WAP to find Largest among 3 numbers using class (Display all the three numbers along with largest value)
#include <iostream>
#include <iomanip>
using namespace std;
class Display{
public:
int n1;
int n2;
int n3;
void display()
{
cout<<"Enter first number: ";
cin>>n1;
cout<<"Enter second number: ";
cin>>n2;
cout<<"Enter third number: ";
cin>>n3;
cout<<"display all numbers\n"<<n1<<setw(20)<<n2<<setw(20)<<n3<<endl;
if ((n1>=n2) && (n1>=n3))
cout<<"Largest value: "<<n1;
else if ((n2>=n1) &&(n2>=n3))
cout<<"Largest value: "<<n2;
else if ((n3>=n1) && (n3>=n2))
cout<<"Largest value: "<<n3;
}
};
int main()
{
Display s;
s.display();
return 0;
}
Comments
Leave a comment