beginner of c++

dipanshi

Beta member
Messages
2
can sum1 explain this program ????
#include<conio.h>
#include<iostream.h>

class largest
{
int d;
public :
void getdata(void);
void display_large(largest,largest);
};

void largest :: getdata(void)
{
cout<<"\n\nEnter Value :-";
cin>>d;
}

void largest :: display_large(largest o1,largest o2)
{
if(o1.d > o2.d)
cout<<"\nObject 1 contain Largest Value "<<o1.d;
else if(o2.d > o1.d)
cout<<"\nObject 2 contain Largest Value "<<o2.d;
else
cout<<"\nBOTH ARE EQUAL";
}


void main()
{
largest o1,o2,o3;
clrscr();

o1.getdata();
o2.getdata();

o3.display_large(o1,o2);
getch();
}

m nt able to understand the working of functions in programs and use of three objects...
 
Do you have any specific questions exactly about it? What exactly don't you understand about it?

Basically, it's creating 3 instances of the "largest" class (o1, o2, and o3). It then calls getdata from the o1 instance, which prompts the user for a value. It stores that in the o1.d variable of the o1 instance. It does the same thing for o2.getdata.

After prompting for the values, it calls display_large from the o3 instance of largest, with parameters o1 and o2. display_large takes in 2 arguments of user-defined types "largest" and then compares the 2 values. Depending on which is bigger, it displays the specific output message (Object 1 contain Largest Value, Object 2 contain Largest Value, or Both Are Equal).

It then waits for the user to press a key and then exits.
 
i was juz confused bcuz this program used three objects(instances) ....... which is not required we can do this program using a single object....
neways it is clear to me now...
thnks a lot ....
 
Back
Top Bottom