[go: up one dir, main page]

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

Oops Function and Constructor Overloading Level 1

The document contains multiple C++ programs demonstrating the use of function overloading in different classes such as Student, Store, Hospital, Olympic, AccBalance, Country, and Welcomemsg. Each class has methods that perform operations based on the parameters passed, showcasing how the same method name can handle different types or numbers of arguments. The main function in each program collects user input and invokes the respective methods to display results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views9 pages

Oops Function and Constructor Overloading Level 1

The document contains multiple C++ programs demonstrating the use of function overloading in different classes such as Student, Store, Hospital, Olympic, AccBalance, Country, and Welcomemsg. Each class has methods that perform operations based on the parameters passed, showcasing how the same method name can handle different types or numbers of arguments. The main function in each program collects user input and invokes the respective methods to display results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as 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