aytdev

C++ MID TERM CODE

Mar 5th, 2021 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.10 KB | None | 0 0
  1. NAME: AYAT ULLAH
  2. ID: C201050
  3. SEC: 2BM
  4.  
  5.  
  6. /* Answer 1(a) */
  7. .... code .....
  8.  
  9. #include <iostream>
  10. using namespace std;
  11. class Volume{
  12.  double length,breadth,height;
  13.  public:
  14.     Volume(double x=0,double y=0,double z=0):length(x),breadth(y),height(x){}
  15.  
  16. };
  17. int main()
  18. {
  19.  
  20. return 0;
  21. }
  22.  
  23. /* Answer 1(b) */
  24. .... code .....
  25.  
  26. #include <iostream>
  27. using namespace std;
  28. class Volume{
  29.  double length,breadth,height;
  30.  public:
  31.     Volume(double x=0,double y=0,double z=0):length(x),breadth(y),height(x){}
  32.  
  33. };
  34. int main()
  35. {
  36.  
  37. return 0;
  38. }
  39.  
  40. /* Answer 1(c) */
  41. .... code .....
  42.  
  43. #include <iostream>
  44. using namespace std;
  45. class Rectangle{
  46.  double length,breadth;
  47.  public:
  48.     Rectangle(double x=0,double y=0):length(x),breadth(y){}
  49.     double Area(){
  50.        double area;
  51.        area = length*breadth;
  52.        return area;
  53.     }
  54.  
  55. };
  56. int main()
  57. {
  58.     Rectangle obj1(4,5),obj2(5,8);
  59.     cout<<obj1.Area()<<endl;
  60.     cout<<obj2.Area();
  61.  
  62. return 0;
  63. }
  64.  
  65. /* Answer 1(d) */
  66. .... code .....
  67.  
  68. #include <iostream>
  69. using namespace std;
  70. class Student{
  71.  string name ,semester,adress;
  72.  public:
  73.      void getdate(){
  74.          cout<<"Enter name: ";
  75.          cin>>name;
  76.  
  77.          cout<<"Enter Semester :";
  78.          cin>>semester;
  79.  
  80.          cout<<"Enter adress :";
  81.          cin.ignore();
  82.          cin>>adress;
  83.      }
  84.      void showdate(){
  85.        cout<<name<<"\t\t\t"<<semester<<"\t\t\t"<<adress<<endl;
  86.  
  87.      }
  88.  
  89. };
  90. int main()
  91. {
  92.     Student obj[3];
  93.     for(int i=0;i<3;i++){
  94.         system("cls");
  95.         cout<<"Student"<<i+1<<endl;
  96.        obj[i].getdate();
  97.     }
  98.     cout<<"Name\t\t\tSemester\t\t\tAdress\n";
  99.     for(int i=0;i<3;i++){
  100.  
  101.        obj[i].showdate();
  102.     }
  103.  
  104. return 0;
  105. }
  106.  
  107.  
  108. /* Answer 2(a) */
  109. .... code .....
  110.  
  111. #include <iostream>
  112. using namespace std;
  113. class Student{
  114.  double height;
  115.  
  116.  public:
  117.      static double theight;
  118.      void getdate(){
  119.          cout<<"Enter student height :";
  120.          cin>>height;
  121.          theight+=height;
  122.      }
  123.  
  124. };
  125. double Student::theight=0;
  126. int main()
  127. {
  128.     int n;
  129.     cout<<"Enter total student number :";
  130.     cin>>n;
  131.     Student obj[n];
  132.     for(int i=0;i<n;i++){
  133.         system("cls");
  134.         cout<<"Student "<<i+1<<endl;
  135.        obj[i].getdate();
  136.     }
  137.    cout<<"Median of height is "<<Student::theight/n<<endl;
  138.  
  139. return 0;
  140. }
  141.  
  142. /* Answer 2(b) */
  143. .... code .....
  144.  
  145. #include <iostream>
  146. using namespace std;
  147. class Dict{
  148.  string name="NOT SET",adress="NOT SET",mn="NOT SET",gender="NOT SET",nid="NOT SET";
  149.  
  150.  public:
  151.      Dict(string x,string y,string z,string i,string j):name(x),adress(y),mn(z),gender(i),nid(j){}
  152.      Dict(string x,string y,string i,string j):name(x),adress(y),gender(i),nid(j){}
  153.      void pdata(){
  154.          cout<<name<<" "<<adress<<" ";
  155.          if(mn!="NOT SET"){
  156.             cout<<mn<<" ";
  157.           }
  158.          cout<<gender<<" "<<nid<<endl;
  159.  
  160.      }
  161.  
  162. };
  163.  
  164. int main()
  165. {
  166.    Dict obj1("ayat ullah","kumira,shitakunda","01926668875","male","3687554"),obj2("ayat ullah","kumira,shitakunda","male","3687554");
  167.   obj1.pdata();
  168.   obj2.pdata();
  169. return 0;
  170. }
  171.  
  172. /* Answer 2(c) */
  173. .... code .....
  174.  
  175. #include<bits/stdc++.h>
  176. using namespace std;
  177. int main(){
  178.  string fname,mname,lname;
  179.  cin>>fname>>mname>>lname;
  180.  cout<<fname<<" "<<mname[0]<<"."<<lname[0]<<"."<<endl;
  181.  return 0;
  182.  
  183.  
  184. }
  185.  
  186. /* Answer 3(a) */
  187. .... code .....
  188. #include<bits/stdc++.h>
  189. using namespace std;
  190. class AddAmount{
  191.   float ammount=0,tammount=50;
  192.   public:
  193.  
  194.       AddAmount (float x=50):ammount(x){tammount+=ammount;}
  195.       AddAmount(){
  196.           tammount+=0;
  197.       }
  198.  
  199.       void getdata(){
  200.       cout<<tammount<<endl;
  201.     }
  202.  
  203. };
  204. int main(){
  205.     AddAmount obj1(),obj2(500);
  206.     //obj1.getdata();
  207.     obj2.getdata();
  208.  return 0;
  209.  
  210.  
  211. }
  212.  
  213. /* Answer 3(b) */
  214. .... code .....
  215.  
  216. #include<bits/stdc++.h>
  217. using namespace std;
  218. class PrintNumber{
  219.   int num;
  220.   public:
  221.       int printn(int x){
  222.         cout<<x;
  223.       }
  224.       long long printn(long long x){
  225.         cout<<x;
  226.       }
  227.       float printn(float x){
  228.         cout<<x;
  229.       }
  230.       double printn(double x){
  231.         cout<<x;
  232.       }
  233.  
  234. };
  235. int main(){
  236.  
  237.  return 0;
  238.  
  239.  
  240. }
  241.  
  242.  
  243.  
Advertisement
Add Comment
Please, Sign In to add comment