0% found this document useful (0 votes)
86 views9 pages

OOPS FUNCTION AND CONSTRUCTOR OVERLOADING Level 1

The document contains C++ code defining multiple classes - Student, Store, Hospital, Olympic, AccBalance, Country, Welcomemsg - with overloaded member functions. The main() function in each code snippet calls the overloaded member functions by passing different parameters and demonstrates function overloading.

Uploaded by

grtwthwtw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views9 pages

OOPS FUNCTION AND CONSTRUCTOR OVERLOADING Level 1

The document contains C++ code defining multiple classes - Student, Store, Hospital, Olympic, AccBalance, Country, Welcomemsg - with overloaded member functions. The main() function in each code snippet calls the overloaded member functions by passing different parameters and demonstrates function overloading.

Uploaded by

grtwthwtw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

#include <iostream>

using namespace std;

class Student

public:

void Identity(string name,int id){

cout<<name<<" "<<id<<endl;

void Identity(int id,string name){

cout<<name<<" "<<id<<endl;

};

int main()

Student Details;

string name;

int id;

cin>>name>>id;
Details.Identity(name,id);

cin>>id>>name;

Details.Identity(id,name);

return 0;

#include <iostream>

using namespace std;

class Store{

public:

void itemcount(int id){

cout<<id<<endl;

void itemcount(int totalavl,int consumed){

cout<<totalavl - consumed<<endl;

};
int main()

Store purchase;

int id,totalavl,consumed;

cin>>id>>totalavl>>consumed;

purchase.itemcount(id);

purchase.itemcount(totalavl,consumed);

return 0;

#include <iostream>

using namespace std;

class Hospital{

public:

void bill(long int mdeicinebill,int days){

cout<<mdeicinebill*days<<endl;
}

void bill(int roomrent,int days){

cout<<roomrent*days;

};

int main()

Hospital ob;

long int mdeicinebill,days;

int roomrent;

cin>>mdeicinebill>>days;

ob.bill(mdeicinebill,days);

cin>>roomrent>>days;

ob.bill(roomrent,days);

return 0;

}
#include <iostream>

using namespace std;

class Olympic{

public:

void distance(int D1,int D2){

cout<<D1+D2<<" meters"<<endl;

void distance(int D3, int D4, int D5){

cout<<D3+D4+D5<<" meters"<<endl;

};

int main()

Olympic Medal;

int D1,D2,D3,D4,D5;

cin>>D1>>D2>>D3>>D4>>D5;

Medal.distance(D1,D2);

Medal.distance(D3,D4,D5);

return 0;

}
#include <iostream>

using namespace std;

class AccBalance{

public:

AccBalance(){cout<<"Zero Balance"<<endl;}

AccBalance(int balance){

if(balance<0)

cout<<"Has a Negative Balance";

else if(balance==0)

cout<<"Has a Zero Balance";

else

cout<<"Has a Positive Balance";

};

int main()

AccBalance defltBal;

int balance;
cin>>balance;

AccBalance currBal(balance);

return 0;

#include <iostream>

using namespace std;

class Country{

public:

Country(){cout<<"Country:INDIA"<<endl;}

Country(char statename[100],int area,int density)

cout<<"State:"<<statename<<endl<<"Area:"<<area<<endl<<"Density:"<<density<<endl;

};

int main()

{
Country country;

char statename[100];

int area,density;

cin>>statename>>area>>density;

Country statesofindia(statename,area,density);

return 0;

#include <iostream>

using namespace std;

class Welcomemsg{

public:

void msg(string fname){

cout<<"Hi "<<fname<<endl;

void msg(string fname,string lname){

cout<<"Welcome "<<fname<<" "<<lname;


}

};

int main()

Welcomemsg ob;

string fname,lname;

cin>>fname;

ob.msg(fname);

cin>>fname>>lname;

ob.msg(fname,lname);

return 0;

You might also like