beginner of c++ - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Programming
Click Here to Login
Reply
 
Thread Tools Display Modes
 
Old 07-28-2012, 03:33 AM   #1 (permalink)
Newb Techie
 
Join Date: Jul 2012
Posts: 2
Default beginner of c++

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...
__________________

dipanshi is offline   Reply With Quote
Old 07-28-2012, 03:27 PM   #2 (permalink)
Private Joker
 
carnageX's Avatar
 
Join Date: Feb 2007
Location: South Dakota
Posts: 24,446
Default Re: beginner of c++

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.
__________________

__________________
Laptop: MSI GT70 2OC-059us | i7-4700MQ | 16GB | GTX 770m | 500GB SSD / 750GB HDD | 17.3" | Win10 Pro
Desktop: 4690k | 12GB g.Skill RipJaws | GTX 970 | 520hx | Z87X-UD4H | Corsair Vengeance C70 | Corsair H110 | Acer 25" | Acer 22" | Win10
Mobile: Samsung Galaxy Note 5


If I help you, or you just like what I said, rep me by clicking the under my post
carnageX is offline   Reply With Quote
Old 07-29-2012, 03:15 AM   #3 (permalink)
Newb Techie
 
Join Date: Jul 2012
Posts: 2
Default Re: beginner of c++

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 ....
dipanshi is offline   Reply With Quote
Old 07-29-2012, 03:40 AM   #4 (permalink)
Private Joker
 
carnageX's Avatar
 
Join Date: Feb 2007
Location: South Dakota
Posts: 24,446
Default Re: beginner of c++

No problem, glad to help.
__________________
Laptop: MSI GT70 2OC-059us | i7-4700MQ | 16GB | GTX 770m | 500GB SSD / 750GB HDD | 17.3" | Win10 Pro
Desktop: 4690k | 12GB g.Skill RipJaws | GTX 970 | 520hx | Z87X-UD4H | Corsair Vengeance C70 | Corsair H110 | Acer 25" | Acer 22" | Win10
Mobile: Samsung Galaxy Note 5


If I help you, or you just like what I said, rep me by clicking the under my post
carnageX is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner Programming XI_xtasy_ix Programming 13 03-07-2012 02:11 PM
C++ Beginner Matthew131213 Programming 7 08-04-2009 03:20 AM
Ubuntu Beginner... help OnlyCurious Linux and Open Source 2 12-25-2007 05:55 AM
Beginner linux Vybuni Linux and Open Source 14 02-11-2006 08:34 PM
A few Q's from a beginner kizzeith Overclocking and Modding 1 12-04-2003 03:21 PM



Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -5. The time now is 06:06 PM.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.