Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* aim: to study and implement overloaded functions
- 1. write a c++ program using function overloading to find the maximum of two ints, 3 floats,3 doubles
- 2. write a c++ program to swap 2 ints 2 floats and 2 characters
- 3. to compute the area of various geometrical entries, such as circle triangle, rectangle and square. use classes and array of objects
- */
- #include<iostream.h>
- void max(int a, int b)
- {
- if (a>b)
- cout<<"\nmaximum is "<<a;
- else if(a<b)
- cout<<"\nmaximum is "<<b;
- else
- cout<<"both equal";
- }
- void max(float a, float b, float c)
- {
- if (a>b && a>c)
- cout<<"\nmaximum is "<<a;
- else if(b>a && b>c)
- cout<<"\nmaximum is "<<b;
- else
- cout<<"\nmaximum is "<<c;
- }
- void max(double a, double b, double c)
- {
- if (a>b && a>c)
- cout<<"\nmaximum is "<<a;
- else if(b>a && b>c)
- cout<<"\nmaximum is "<<b;
- else
- cout<<"\nmaximum is "<<c;
- }
- int main()
- {
- int ch;
- do
- {
- cout<<" \n\n1.max of 2 ints\n2.max of 3 floats\n3. max of 3 doubles\n4.exit Enter choice";
- cin>>ch;
- switch(ch)
- {
- case 1:
- cout<<"enter 2 ints";
- int a,b;
- cin>>a>>b;
- max(a,b);
- break;
- case 2:
- cout<<"enter 3 floats";
- float c,d,e;
- cin>>c>>d>>e;
- max(c,d,e);
- break;
- case 3:
- cout<<"enter 3 doubles";
- double f,g,h;
- cin>>f>>g>>h;
- max(f,g,h);
- break;
- case 4:
- break;
- default:
- break;
- }
- }while(ch!=4);
- return 0;
- }
- /*
- 1.max of 2 ints
- 2.max of 3 floats
- 3. max of 3 doubles
- 4.exit Enter choice1
- enter 2 ints2 5
- maximum is 5
- 1.max of 2 ints
- 2.max of 3 floats
- 3. max of 3 doubles
- 4.exit Enter choice3
- enter 3 doubles2.5 4.6 89.6
- maximum is 89.6
- 1.max of 2 ints
- 2.max of 3 floats
- 3. max of 3 doubles
- 4.exit Enter choice4
- Press any key to continue
- */
- /* aim: to study and implement overloaded functions
- 1. write a c++ program using function overloading to find the maximum of two ints, 3 floats,3 doubles
- 2. write a c++ program to swap 2 ints 2 floats and 2 characters
- 3. to compute the area of various geometrical entries, such as circle triangle, rectangle and square. use classes and array of objects
- program 2
- */
- #include<iostream.h>
- void swap(char a, char b)
- {
- char t;
- t=a;
- a=b;
- b=t;
- cout<<"the swapped chars are "<<a<<" and "<<b;
- }
- void swap(float a, float b)
- {
- float t;
- t=a;
- a=b;
- b=t;
- cout<<"the swapped floats are" <<a<<" and "<<b;
- }
- int main()
- {
- int ch;
- do
- {
- cout<<" \n\n1.swap 2 characters\n2.swap 2 floats\n3.exit\n enter choice: ";
- cin>>ch;
- switch(ch)
- {
- case 1:
- cout<<"enter 2 characters";
- char a,b;
- cin>>a>>b;
- swap(a,b);
- break;
- case 2:
- cout<<"enter 2 floats";
- float c,d;
- cin>>c>>d;
- swap(c,d);
- break;
- case 3:
- break;
- default:
- break;
- }
- }while(ch!=3);
- return 0;
- }
- /*
- 1.swap 2 characters
- 2.swap 2 floats
- 3.exit
- enter choice: 1
- enter 2 charactersa b
- the swapped chars are b and a
- 1.swap 2 characters
- 2.swap 2 floats
- 3.exit
- enter choice: 2
- enter 2 floats1.2 2.4
- the swapped floats are2.4 and 1.2
- 1.swap 2 characters
- 2.swap 2 floats
- 3.exit
- enter choice: 3
- Press any key to continue
- */
- /* aim: to study and implement overloaded functions
- 1. write a c++ program using function overloading to find the maximum of two ints, 3 floats,3 doubles
- 2. write a c++ program to swap 2 ints 2 floats and 2 characters
- 3. to compute the area of various geometrical entries, such as circle triangle, rectangle and square. use classes and array of objects
- program 3
- */
- #include<iostream.h>
- class find
- {
- float area;
- public:
- void areaa(int a) //circle
- {
- area= 3.1415*a*a;
- cout<<"the area is" <<area;
- }
- void areaa(float a) //square
- {
- area= a*a;
- cout<<"the area is "<<area;
- }
- void areaa(int a, int b) //triangle
- {
- area= 0.5*a*b;
- cout<<"the area is "<<area;
- }
- void areaa(float a, float b) //rectangle
- {
- area=a*b;
- cout<<"the area is "<<area;
- }
- };
- int main()
- {
- find a[20];
- int ch,n;
- cout<<"enter the number of geometrical figures";
- cin>>n;
- int i;
- for(i=0;i<n;i++)
- {
- cout<<"\n\nobject "<<i+1;
- cout<<" \n\n1.circle \n2.triangle \n3.square\n4. rectangle \nenter choice: ";
- cin>>ch;
- switch(ch)
- {
- case 1:
- cout<<"\nenter radius";
- int x;
- cin>>x;
- a[i].areaa(x);
- break;
- case 2:
- cout<<"\nenter base and height";
- int c,d;
- cin>>c>>d;
- a[i].areaa(c,d);
- break;
- case 3:
- cout<<"\nenter length of side";
- int e;
- cin>>e;
- a[i].areaa(e);
- break;
- case 4:
- cout<<"enter length and breadth";
- float f,g;
- cin>>f>>g;
- a[i].areaa(f,g);
- break;
- default:
- break;
- }
- }
- return 0;
- }
- /*
- enter the number of geometrical figures3
- object 1
- 1.circle
- 2.triangle
- 3.square
- 4. rectangle
- enter choice: 1
- enter radius20
- the area is1256.6
- object 2
- 1.circle
- 2.triangle
- 3.square
- 4. rectangle
- enter choice: 2
- enter base and height2 5
- the area is 5
- object 3
- 1.circle
- 2.triangle
- 3.square
- 4. rectangle
- enter choice: 4
- enter length and breadth5 6
- the area is 30
- Press any key to continue
- */
Advertisement
Add Comment
Please, Sign In to add comment