Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Smallest Among two Numbers Using Class*/
- /* Language: C++ */
- #include <iostream.h>
- #include <conio.h>
- class float_num
- {
- float a,b;
- public:
- float_num(float x,float y)
- {
- a=x;
- b=y;
- }
- friend float compare(float_num &num);
- };
- class int_num
- {
- int a,b;
- public:
- int_num(int x,int y)
- {
- a=x;
- b=y;
- }
- friend int compare(int_num &num);
- };
- int compare(int_num &num)
- {
- if(num.a<num.b)
- return num.a;
- else
- return num.b;
- }
- float compare(float_num &num)
- {
- if(num.a<num.b)
- return num.a;
- else
- return num.b;
- }
- int main()
- {
- system("cls");
- int a,b;
- float c,d;
- cout<<"\nEnter two Integer Numbers: \n";
- cin>>a>>b;
- int_num int_1(a,b);
- cout<<"\nThe Smallest Among the given two number is: "<<compare(int_1);
- cout<<"\n\nEnter two Floating Point Numbers: \n";
- cin>>c>>d;
- float_num float_1(c,d);
- cout<<"\nThe Smallest Among the given two number is: "<<compare(float_1);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement