upsidedown

oops expt 3 a,b,c :D

Feb 10th, 2012
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.23 KB | None | 0 0
  1. /* aim: to study and implement overloaded functions
  2. 1. write a c++ program using function overloading to find the maximum of two ints, 3 floats,3 doubles
  3. 2. write a c++ program to swap 2 ints 2 floats and 2 characters
  4. 3. to compute the area of various geometrical entries, such as circle triangle, rectangle and square. use classes and array of objects
  5.  
  6.  
  7. */
  8.  
  9. #include<iostream.h>
  10.  
  11. void max(int a, int b)
  12. {
  13.     if (a>b)
  14.         cout<<"\nmaximum is "<<a;
  15.     else if(a<b)
  16.         cout<<"\nmaximum is "<<b;
  17.     else
  18.         cout<<"both equal";
  19. }
  20.  
  21.  
  22.  
  23. void max(float a, float b, float c)
  24. {
  25.     if (a>b && a>c)
  26.         cout<<"\nmaximum is "<<a;
  27.     else if(b>a && b>c)
  28.         cout<<"\nmaximum is "<<b;
  29.     else
  30.         cout<<"\nmaximum is "<<c;
  31. }
  32.  
  33.  
  34.  
  35. void max(double a, double b, double c)
  36. {
  37.     if (a>b && a>c)
  38.         cout<<"\nmaximum is "<<a;
  39.     else if(b>a && b>c)
  40.         cout<<"\nmaximum is "<<b;
  41.     else
  42.         cout<<"\nmaximum is "<<c;
  43. }
  44.  
  45.  
  46.  
  47. int main()
  48. {
  49.     int ch;
  50.     do
  51.     {
  52.  
  53.         cout<<" \n\n1.max of 2 ints\n2.max of 3 floats\n3. max of 3 doubles\n4.exit  Enter choice";
  54.         cin>>ch;
  55.         switch(ch)
  56.         {
  57.         case 1:
  58.             cout<<"enter 2 ints";
  59.             int a,b;
  60.             cin>>a>>b;
  61.             max(a,b);
  62.             break;
  63.         case 2:
  64.             cout<<"enter 3 floats";
  65.             float c,d,e;
  66.             cin>>c>>d>>e;
  67.             max(c,d,e);
  68.             break;
  69.         case 3:
  70.             cout<<"enter 3 doubles";
  71.             double f,g,h;
  72.             cin>>f>>g>>h;
  73.             max(f,g,h);
  74.             break;
  75.         case 4:
  76.             break;
  77.         default:
  78.             break;
  79.         }
  80.     }while(ch!=4);
  81.         return 0;
  82. }
  83.  
  84.  
  85. /*
  86.  
  87. 1.max of 2 ints
  88. 2.max of 3 floats
  89. 3. max of 3 doubles
  90. 4.exit  Enter choice1
  91. enter 2 ints2 5
  92.  
  93. maximum is 5
  94.  
  95. 1.max of 2 ints
  96. 2.max of 3 floats
  97. 3. max of 3 doubles
  98. 4.exit  Enter choice3
  99. enter 3 doubles2.5 4.6 89.6
  100.  
  101. maximum is 89.6
  102.  
  103. 1.max of 2 ints
  104. 2.max of 3 floats
  105. 3. max of 3 doubles
  106. 4.exit  Enter choice4
  107. Press any key to continue
  108. */
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. /* aim: to study and implement overloaded functions
  121. 1. write a c++ program using function overloading to find the maximum of two ints, 3 floats,3 doubles
  122. 2. write a c++ program to swap 2 ints 2 floats and 2 characters
  123. 3. to compute the area of various geometrical entries, such as circle triangle, rectangle and square. use classes and array of objects
  124.  
  125.  
  126.   program 2
  127. */
  128.  
  129.  
  130.  
  131. #include<iostream.h>
  132.  
  133. void swap(char a, char b)
  134. {
  135.     char t;
  136.     t=a;
  137.     a=b;
  138.     b=t;
  139.     cout<<"the swapped chars are "<<a<<" and "<<b;
  140.  
  141. }
  142.  
  143.  
  144.  
  145. void swap(float a, float b)
  146. {
  147.     float t;
  148.     t=a;
  149.     a=b;
  150.     b=t;
  151.     cout<<"the swapped floats are" <<a<<" and "<<b;
  152.  
  153. }
  154.  
  155.  
  156. int main()
  157. {
  158.     int ch;
  159.     do
  160.     {
  161.  
  162.         cout<<" \n\n1.swap 2 characters\n2.swap 2 floats\n3.exit\n enter choice: ";
  163.         cin>>ch;
  164.         switch(ch)
  165.         {
  166.         case 1:
  167.             cout<<"enter 2 characters";
  168.             char a,b;
  169.             cin>>a>>b;
  170.             swap(a,b);
  171.             break;
  172.         case 2:
  173.             cout<<"enter 2 floats";
  174.             float c,d;
  175.             cin>>c>>d;
  176.             swap(c,d);
  177.             break;
  178.         case 3:
  179.             break;
  180.         default:
  181.             break;
  182.         }
  183.     }while(ch!=3);
  184.         return 0;
  185. }
  186.  
  187.  
  188. /*
  189.  
  190.  
  191. 1.swap 2 characters
  192. 2.swap 2 floats
  193. 3.exit
  194.  enter choice: 1
  195. enter 2 charactersa b
  196. the swapped chars are b and a
  197.  
  198. 1.swap 2 characters
  199. 2.swap 2 floats
  200. 3.exit
  201.  enter choice: 2
  202. enter 2 floats1.2 2.4
  203. the swapped floats are2.4 and 1.2
  204.  
  205. 1.swap 2 characters
  206. 2.swap 2 floats
  207. 3.exit
  208.  enter choice: 3
  209. Press any key to continue
  210. */
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218. /* aim: to study and implement overloaded functions
  219. 1. write a c++ program using function overloading to find the maximum of two ints, 3 floats,3 doubles
  220. 2. write a c++ program to swap 2 ints 2 floats and 2 characters
  221. 3. to compute the area of various geometrical entries, such as circle triangle, rectangle and square. use classes and array of objects
  222.  
  223.  
  224.   program 3
  225. */
  226.  
  227.  
  228.  
  229. #include<iostream.h>
  230.  
  231.  
  232. class find
  233. {
  234.     float area;
  235.    
  236. public:
  237.     void areaa(int a)  //circle
  238.     {
  239.         area= 3.1415*a*a;
  240.         cout<<"the area is" <<area;
  241.     }
  242.  
  243.     void areaa(float a) //square
  244.     {
  245.         area= a*a;
  246.         cout<<"the area is "<<area;
  247.     }
  248.  
  249.     void areaa(int a, int b) //triangle
  250.     {
  251.         area= 0.5*a*b;
  252.         cout<<"the area is "<<area;
  253.     }
  254.  
  255.     void areaa(float a, float b) //rectangle
  256.     {
  257.         area=a*b;
  258.         cout<<"the area is "<<area;
  259.     }
  260. };
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267. int main()
  268. {
  269.     find a[20];
  270.     int ch,n;
  271.  
  272.     cout<<"enter  the number of geometrical figures";
  273.     cin>>n;
  274.  
  275.     int i;
  276.  
  277.     for(i=0;i<n;i++)
  278.     {
  279.         cout<<"\n\nobject "<<i+1;
  280.  
  281.  
  282.         cout<<" \n\n1.circle \n2.triangle \n3.square\n4. rectangle \nenter choice: ";
  283.         cin>>ch;
  284.         switch(ch)
  285.         {
  286.         case 1:
  287.             cout<<"\nenter radius";
  288.             int x;
  289.             cin>>x;
  290.             a[i].areaa(x);
  291.             break;
  292.         case 2:
  293.             cout<<"\nenter base and height";
  294.             int c,d;
  295.             cin>>c>>d;
  296.             a[i].areaa(c,d);
  297.             break;
  298.  
  299.         case 3:
  300.             cout<<"\nenter length of side";
  301.             int e;
  302.             cin>>e;
  303.             a[i].areaa(e);
  304.             break;
  305.         case 4:
  306.             cout<<"enter length and breadth";
  307.             float f,g;
  308.             cin>>f>>g;
  309.             a[i].areaa(f,g);
  310.             break;
  311.        
  312.         default:
  313.             break;
  314.         }
  315.     }
  316.         return 0;
  317. }
  318.  
  319.  
  320. /*
  321.  
  322. enter  the number of geometrical figures3
  323.  
  324.  
  325. object 1
  326.  
  327. 1.circle
  328. 2.triangle
  329. 3.square
  330. 4. rectangle
  331. enter choice: 1
  332.  
  333. enter radius20
  334. the area is1256.6
  335.  
  336. object 2
  337.  
  338. 1.circle
  339. 2.triangle
  340. 3.square
  341. 4. rectangle
  342. enter choice: 2
  343.  
  344. enter base and height2 5
  345. the area is 5
  346.  
  347. object 3
  348.  
  349. 1.circle
  350. 2.triangle
  351. 3.square
  352. 4. rectangle
  353. enter choice: 4
  354. enter length and breadth5 6
  355. the area is 30
  356.  
  357.  Press any key to continue
  358. */
Advertisement
Add Comment
Please, Sign In to add comment