54
OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017 1. SIMPLE MESSAGE DISPLAY ******************************* CODING: #include<iostream.h> #include<conio.h> void main() { int age; char name[30]; clrscr(); cout<<"\nSimple message display"; cout<<"\n********************"; cout<<"\nEnter name:"; cin>>name; cout<<"\nEnter age:"; cin>>age; cout<<"\nFather name:"; cin>>name; cout<<"\nMother name:"; cin>>name; getch(); } OUTPUT: SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Final c + + program

  • Upload
    prabhu

  • View
    234

  • Download
    3

Embed Size (px)

DESCRIPTION

Final c + + program

Citation preview

Page 1: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

1. SIMPLE MESSAGE DISPLAY

*******************************

CODING:

#include<iostream.h>

#include<conio.h>

void main()

{

int age;

char name[30];

clrscr();

cout<<"\nSimple message display";

cout<<"\n********************";

cout<<"\nEnter name:";

cin>>name;

cout<<"\nEnter age:";

cin>>age;

cout<<"\nFather name:";

cin>>name;

cout<<"\nMother name:";

cin>>name;

getch();

}

OUTPUT:

1. SIMPLE MESSAGE DISPLAY

****************************Enter name: Boopathi

Enter age: 19

Father name: Nagaraj

Mother name: Eswari

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 2: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

2. ARITHMATIC OPERATORS

******************************CODING:

#include<iostream.h>

#include<conio.h>

void main()

{

int A,B,C;

clrscr();

cout<<"ARITHMATIC OPERATORS\n";

cout<<"********************\n";

cout<<"INPUT\n";

cout<<"******\n";

cout<<"Enter the value for A\n";

cin>>A;

cout<<"Enter the value for B\n";

cin>>B;

cout<<"OUTPUT\n";

cout<<"******\n";

C=A+B;

cout<<"\n Addition is:"<<C;

C=A-B;

cout<<"\n Subtraction is:"<<C;

C=A*B;

cout<<"\n Multiplication is:"<<C;

C=A/B;

cout<<"\n Division is:"<<C;

getch();

}

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 3: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

OUTPUT:

2. ARITHMATIC OPERATORS

*****************************INPUT

******

Enter the value of A:2

Enter the value of B:2

OUTPUT

********

ADDITION IS: 4

SUBTRACTION IS: 0

MULTIPLICATION IS: 4

DIVISION IS: 1

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 4: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

3.CONVERTING UPPERCASE TO LOWERCASE

*******************************************

CODING:

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

char ch;

cout<<"Converting uppercase to lowercase\n";

cout<<"*********************************\n";

cout<<"INPUT\n";

cout<<"*****\n";

cout<<"Enter uppercase character:\n";

cin>>ch;

{

if((ch>=65)&&(ch<=90))

ch=ch+32;

cout<<"OUTPUT\n";

cout<<"******\n";

cout<<"\n The lowercase charcter is:"<<ch;

}

getch();

}

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 5: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

OUTPUT:

3. CONVERTING UPPERCASE TO LOWERCASE

********************************************INPUT:

******

Enter uppercase character: A

OUTPUT:

********

The lowercase character is : a

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 6: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

4. CHECKING THE TYPES OF NUMBERS*************************************

CODING:

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

float num;

cout<<"CHECKING THE TYPES OF NUMBERS\n";

cout<<"**********************\n";

cout<<"INPUT\n";

cout<<"******\n";

cout<<"Enter the number=\n";

cin>>num;

cout<<"OUTPUT\n";

cout<<"******\n";

if(num<=0)

{

if(num==0)

cout<<"You are entered zero\n";

else

cout<<num <<”is NEGATIVE number\n";

}

else

cout<<num <<"is POSTIVE number\n";

getch();

}

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 7: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

OUTPUT:4.CHECKING THE TYPES OF NUMBERS

**************************************INPUT

******

Enter the number=2

OUTPUT

********

2 is POSTIVE number

4. CHECKING THE TYPES OF NUMBERS **************************************

INPUT

******

Enter the number=0

OUTPUT

********

You are entered zero

4. CHECKING THE TYPES OF NUMBERS**************************************

INPUT

******

Enter the number=-2

OUTPUT

********

-2 is NEGATIVE number

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 8: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

5. NUMBER INTO WORDS*************************

CODING:

#include<iostream.h>#include<conio.h>void main(){int n;clrscr();cout<<"NUMBER IN TO WORDS\n";cout<<"*******************\n";cout<<"INPUT\n";cout<<"*****\n";cout<<"Enter the n value=";cin>>n;cout<<"OUTPUT\n";cout<<"******\n";if(n==0)cout<<"Zero";if(n==1)cout<<"One";if(n==2)cout<<"Two";if(n==3)cout<<"Three";if(n==4)cout<<"Four";if(n==5)cout<<"Five";if(n==6)cout<<"Six";if(n==7)cout<<"Seven";if(n==8)cout<<"Eight";if(n==9)cout<<"Nine";getch();}

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 9: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

OUTPUT:5. NUMBER INTO WORDS***********************

NUMBER INTO WORDS

*********************

INPUT

*****

Enter the n value: 1

OUTPUT

*******

One

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 10: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

6. EMPLOYEE PAYROLL STATEMENT**********************************

CODING:

#include<iostream.h>

#include<conio.h>

int main()

{

char name[30],g;

int yos,qual,sal=0;

clrscr ();

cout<<"EMPLOYEE PAYROLL STATEMENT\n";

cout<<"**************************\n";

cout<<"INPUT\n";

cout<<"*****\n";

cout<<"\nEnter name:";

cin>>name;

cout<<"\nEnter gender:";

cin>>g;

cout<<"\nEnter year of service:";

cin>>yos;

cout<<"\nEnter qualification:";

cin>>qual;

cout<<"\nOUTPUT\n";

cout<<"******\n";

if(g=='m'&&yos>10&&qual==1)

sal=15000;

else

if(g=='m'&&yos>10&&qual==0)

sal=10000;

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 11: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

else

if(g=='m'&&yos<=10&&qual==0)

sal=8000;

else

if(g=='m'&&yos<=10&&qual==1)

sal=9500;

if(g=='f'&&yos>10&&qual==1)

sal=13000;

else

if(g=='f'&&yos>10&&qual==0)

sal=8000;

else

if(g=='f'&&yos<=10&&qual==0)

sal=5000;

else

if(g=='f'&&yos<=10&&qual==1)

sal=7000;

cout<<"SALARY OF EMPLOYEE="<<sal;

getch();

return 0;

}

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 12: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

OUTPUT:

6. EMPLOYEE PAYROLL STATEMENT************************************

INPUT:

******

Enter name: Alex

Enter gender: M

Enter year of service: 13

Enter qualification : 1

OUTPUT:

********

SALARY OF EMPLOYEE= 15000

6. EMPLOYEE PAYROLL STATEMENT

************************************INPUT:

******

Enter name: Gupta

Enter gender: M

Enter year of service: 14

Enter qualification : 0

OUTPUT:

********

SALARY OF EMPLOYEE= 10000

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 13: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

6. EMPLOYEE PAYROLL STATEMENT

************************************INPUT:

******

Enter name: Arun

Enter gender: M

Enter year of service: 7

Enter qualification : 0

OUTPUT:

********

SALARY OF EMPLOYEE= 8000

6. EMPLOYEE PAYROLL STATEMENT

************************************INPUT:

******

Enter name: Vignesh

Enter gender: M

Enter year of service: 0

Enter qualification : 1

OUTPUT:

********

SALARY OF EMPLOYEE= 9500

6. EMPLOYEE PAYROLL STATEMENT

************************************INPUT:

******

Enter name: Shilpa

Enter gender: F

Enter year of service: 12

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 14: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

Enter qualification : 1

OUTPUT:

********

SALARY OF EMPLOYEE= 13000

6. EMPLOYEE PAYROLL STATEMENT

************************************INPUT:

******

Enter name: Sadhana

Enter gender: F

Enter year of service: 15

Enter qualification : 0

OUTPUT:

********

SALARY OF EMPLOYEE= 8000

6. EMPLOYEE PAYROLL STATEMENT

************************************

INPUT:

******

Enter name: Aarthi

Enter gender: F

Enter year of service: 5

Enter qualification : 0

OUTPUT:

********

SALARY OF EMPLOYEE= 5000

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 15: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

6. EMPLOYEE PAYROLL STATEMENT

************************************INPUT:

******

Enter name: Ramasree

Enter gender: F

Enter year of service: 0

Enter qualification : 1

OUTPUT:

********

SALARY OF EMPLOYEE= 7000

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 16: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

7.ARITHMETIC OPERATION****************************

CODING:

#include<iostream.h>#include<conio.h>class arithmetic{float X,Y,a,s,m,d,M;public:void getdata();void add();void sub();void mul();void div();void mod();void display();};void arithmetic::getdata(){cout<<"ARITHMETIC OPERATION\n";cout<<"*********************\n";cout<<"INPUT\n";cout<<"*****\n";cout<<"\nEnter the value of X=";cin>>X;cout<<"\nEnter the value of Y=";cin>>Y;}void arithmetic::add(){a=X+Y;}void arithmetic::sub(){s=X-Y;}void arithmetic::mul(){m=X*Y;

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 17: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

}void arithmetic::div(){d=X/Y;}void arithmetic::mod(){M=(int)X%(int)Y;}void arithmetic::display(){cout<<"\nOUTPUT";cout<<"\n*******\n";cout<<"\nADDITION is :"<<a;cout<<"\nSUBTRACTION is :"<<s;cout<<"\nMULTIPLICATION is :"<<m;cout<<"\nDIVISION is :"<<d;cout<<"\nMODULATION is :"<<M;}void main(){clrscr();arithmetic O;O.getdata();O.add();O.sub();O.mul();O.div();O.mod();O.display();getch();}

.

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 18: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

OUTPUT:

7.ARITHMETIC OPERATION*************************

ARITHMETIC OPERATION

***********************

INPUT

******

Enter the value of X : 5

Enter the value of Y : 2

OUTPUT

*******

ADDITION is : 7

SUBTRACTION is : 3

MULTIPLICATION is : 10

DIVISION is : 2.5

MODULATION is : 1

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 19: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

8. STRING OVERLOADING**************************

CODING:

#include<iostream.h>#include<conio.h>#include<string.h>class string{private:char st4[30];char st1[15];char st2[15];char st3[30];public:void read();void concat();void cmpr();void strleng();};void string::read(){cout<<"STRING OVERLODING\n";cout<<"******************\n";cout<<"\nINPUT\n";cout<<"*****\n";cout<<"\nEnter the first string:"<<endl;cin>>st1;cout<<"\nEnter the second string:"<<endl;cin>>st2;}void string::concat(){strcpy(st3,st1);strcat(st3,"");strcat(st3,st2);cout<<"\nOUTPUT\n";cout<<"******\n";cout<<"\nCONCATENATION\n";cout<<"-------------\n";cout<<"\nConcatenation of the String:"<<st3;

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 20: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

}void string::cmpr(){cout<<"\n\nCOMPARISON\n";cout<<"----------";if(strcmp(st1,st2)==0)

cout<<"\n\nComparison of two strings are equal"<<endl;elsecout<<"\n\nComparison of two strings are not equal"<<endl;}

void string::strleng(){int length;

length=strlen(st3);cout<<"\nLENGTH\n";cout<<"------\n";cout<<"\nLength of string entered:"<<length<<endl;}void main(){string x;clrscr();x.read();x.concat();x.cmpr();x.strleng();getch();}

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 21: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

OUTPUT:

8. STRING OVERLOADING**************************

STRING OVERLOADING*********************INPUT*****Enter the first string : GupthaEnter the second string :ArunOUTPUT*******CONCATENATION---------------------------Concatenation of the string : GupthaArunCOMPARISON---------------------Comparison of two strings are not equalLENGTH------------Length of the string entered : 10

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 22: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

9. BANK TRANSACTION**********************

CODING:

#include<iostream.h>#include<conio.h>#include<iomanip.h>class bank{char name[20];int acno;char actype[4];float balance;public:

bank(){cout<<"\nBANK TRANSACTION";cout<<"\n****************\n";cout<<"\nINPUT";cout<<"\n*****"; cout<<"\n\n Constructor invoked!"; acno=0000; balance=0.0; }

void init();void deposit();void withdraw();void disp_det();};void bank::init(){cout<<"\n\n New account:";cout<<"\n\n Enter the name of the depositer:";cin>>name;cout<<"\n\n Enter the account number:";cin>>acno;cout<<"\n\n Enter the account type:(CCUR/SAMG/FD/RD/DMAT)";cin>>actype;cout<<"\n\n Enter the amount to deposit:";cin>>balance;

}

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 23: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

void bank::deposit(){float more;cout<<"\n\n depositing";cout<<"\n\n Enter the ammount of deposit";cin>>more;balance+=more;}void bank::withdraw(){float amt;cout<<"\n\n withdraw!";cout<<"\n\n Enter the amount to withdraw:";cin>>amt;balance-=amt;}void bank::disp_det(){cout<<"\n\n Account details";cout<<"\n\n Name of the depositer:"<<name<<endl;cout<<"\n\n Account number:"<<acno<<endl;cout<<"\n\n Account type:"<<actype<<endl;cout<<"\n\n Balance:Rs."<<balance<<endl;}void main(void){clrscr();bank obj;int choice=1;while(choice!=0){cout<<"\n\nEnter 0 to exit";cout<<"\n\n1.Initialize a New Account \n\n2.Deposite \n\n3.Withdraw \n\n4.Account Status \n\n Choose your opton:";

cin>>choice;cout<<"\n OUTPUT";cout<<"\n ******";switch(choice){case 0:obj.disp_det();cout<<"\n Exiting program";

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 24: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

break;case 1:obj.init();break;case 2:obj.deposit();break;case 3:obj.withdraw();break;case 4:obj.disp_det();break;default:cout<<"\n Illegal option"<<endl;}}getch();}

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 25: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

OUTPUT:

9. BANK TRANSACTION**********************

BANK TRANSACTION

********************

INPUT

*****

Constructor invoked!

Enter 0 to exit

1.Initialize a New Account

2.Deposite

3.Withdraw

4.Account Status

Choose your option:1

OUTPUT

*******

Enter the name of the depositer: Alex

Enter the account number: 45450

Enter the account type: (CCUF/SAMG/FD/RD/DMAT)SAMG

Enter the amount to deposit: 1,00,000

INPUT

*****

Enter 0 to exit

1.Initialize a New Account

2.Deposite

3.Withdraw

4.Account Status

Choose your option:2

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 26: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

OUTPUT

*******

Depositing

Enter the amount of deposit: 2,000

INPUT

*****

Enter 0 to exit

1.Initialize a New Account

2.Deposite

3.Withdraw

4.Account Status

Choose your option:3

OUTPUT

*******

Withdraw!

Enter the amount to withdraw: 5,000

INPUT

*****

Enter 0 to exit

1.Initialize a New Account

2.Deposite

3.Withdraw

4.Account Status

Choose your option:4

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 27: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

OUTPUT

*******

Account details

Name of the depositer : Alex

Account number: 45450

Account type: SAMG

Balance: Rs.97,000

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 28: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

10. EMPLOYEE DETAILS

**********************CODING:

#include<iostream.h>

#include<conio.h>

class emp

{

public:

int empno;

double salary;

double netamt;

int pf,hra,da;

char name[10],add[15];

char dept[15],grade;

void input();

void disp();

};

class pay:public emp

{

public:

void calc();

};

void emp::input()

{

clrscr();

read:

cout<<"\nEMPLOYEE DETAILS";

cout<<"\n****************\n";

cout<<"\nINPUT";

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 29: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

cout<<"\n*****";

cout<<"\n\nEnter the employee number:";

cin>>empno;

cout<<"\nEnter the employee name:";

cin>>name;

cout<<"\nEnter the employee address:";

cin>>add;

cout<<"\nEnter the employee department:";

cin>>dept;

cout<<"\nEnter the employee salary:";

cin>>salary;

cout<<"\nEnter the employee grade[a,b,c]:";

cin>>grade;

cout<<"\n";

}

void pay::calc()

{

if(grade=='a')

{

pf=200;

hra=300;

da=50;

}

else if(grade=='b')

{

pf=150;

hra=300;

da=50;

}

else if(grade=='c')

{

pf=300;

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 30: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

hra=100;

da=300;

}

netamt=salary+pf+hra+da;

}

void emp::disp()

{

cout<<"\nPAY SLIP";

cout<<"\n********\n";

cout<<"\nOUTPUT";

cout<<"\n*****";

cout<<"\n\nEmployee number:"<<empno;

cout<<"\n\nEmployee name:"<<name;

cout<<"\n\nEmployee address:"<<add;

cout<<"\n\nEmployee department:"<<dept;

cout<<"\n\nEmployee salary:"<<salary;

cout<<"\n\nNet Salary:"<<netamt;

}

void main() {

clrscr();

pay a;

char d;

read:

a.input();

a.calc();

a.disp();

cout<<"\n\n\t\t\t Do you want to continue [y/n]:";

cin>>d;

if(d=='y')

goto read;

else

getch();}

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 31: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

OUTPUT:

10. EMPLOYEE DETAILS************************

EMPLOYEE DETAILS

*******************

INPUT

*****

Enter the employee number: 44

Enter the employee name: ARUN

Enter the employee address: COIMBATORE

Enter the employee department: HR

Enter the employee salary: 30,000

Enter the employee grade[a,b,c] : A

PAY SLIP

********

OUTPUT

*******

Employee number : 44

Employee name: ARUN

Employee address: COIMBATORE

Employee department: HR

Employee salary:30,000

Net salary:30,550

Do you want to continue [y/n]:y

INPUT

*****

Enter the employee number: 45

Enter the employee name: ALEX

Enter the employee address: DHARAPURAM

Enter the employee department: MARKETING

Enter the employee salary: 50,000

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 32: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

Enter the employee grade[a,b,c] : b

PAY SLIP

********

OUTPUT

*******

Employee number : 45

Employee name: ALEX

Employee address: DHARAPURAM

Employee department: MARKETING

Employee salary:50,000

Net salary:50,500

Do you want to continue [y/n]:y

INPUT

*****

Enter the employee number: 46

Enter the employee name: GUPTHA

Enter the employee address: CHENNAI

Enter the employee department: MANAGER

Enter the employee salary: 65,000

Enter the employee grade[a,b,c] : c

PAY SLIP

********

OUTPUT

*******

Employee number : 46

Employee name: GUPTHA

Employee address: CHENNAI

Employee department: MANAGER

Employee salary:65,000

Net salary:65,700

Do you want to continue [y/n]:n

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 33: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

11.IMPLEMENTING OF FRIENDLY FUNCTION******************************************

CODING:

#include<iostream.h>

#include<conio.h>

class SECOND;

class FIRST

{

private:

int f1;

float f2;

public:

void input(void);

void output(void);

friend void dis (FIRST,SECOND);

};

class SECOND

{

private:

int s1;

float s2;

public:

void input(void);

void output(void);

friend void dis(FIRST,SECOND);

};

void FIRST::input(void)

{

cout<<"\n\nINPUT";

cout<<"\n****";

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 34: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

cout<<"\n\nENTER THE INTEGER VALUE:";

cin>>f1;

cout<<"\nENTER THE FLOAT VALUE:";

cout.precision(2);

cin>>f2;

}

void FIRST::output(void)

{

cout<<"\n\n!!first input set!!"<<"\n";

cout<<"\n\n->"<<f1;

cout<<"\n\n->"<<f2;

}

void SECOND::input(void)

{

cout<<"\n\nINPUT";

cout<<"\n*****";

cout<<"\n\nENTER THE INTEGTER VALUE:";

cin>>s1;

cout<<"\nENTER THE FLOAT VALUE:";

cout.precision(2);

cin>>s2;

}

void SECOND::output(void)

{

cout<<"\n\n!! second input set !!"<<"\n";

cout<<"\n\n->"<<s1;

cout<<"\n\n->"<<s2;

}

void dis(FIRST F,SECOND S)

{

int i;

float f;

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 35: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

i=F.f1+S.s1;

f=F.f2+S.s2;

cout<<"\n\n\nTHE RESULT OF THE OPERATION";

cout<<"\n***************************";

cout<<"\n\n"<<F.f1<<"+"<<S.s1<<"="<<i;

cout<<"\n\n"<<F.f2<<"+"<<S.s2<<"="<<f<<"\n";

}

void main()

{

clrscr();

{

cout<<"\nIMPLEMENTING OF FRIENDLY FUNCTION"<<"\n";

cout<<"\n*********************************"<<"\n";

FIRST fir;

SECOND sec;

char a='y';

while(a=='y')

{

fir.input();

sec.input();

fir.output();

sec.output();

dis(fir,sec);

cout<<"\n\n\n\t\t\t DO YOU WANT TO CONTINUE [Y/N] :";

cin>>a;

getch();

}

}

}

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 36: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

OUTPUT:11.IMPLEMENTING OF FRIENDLY FUNCTION*******************************************

IMPLEMENTING OF FRIENDLY FUNCTION

**************************************

INPUT

*****

ENTER THE INTEGER VALUE :2

ENTER THE FLOAT VALUE :2.2

INPUT

*****

ENTER THE INTEGER VALUE :2

ENTER THE FLOAT VALUE :2.2

!! First input set !!

->2

->2.2

!! Second input set !!

->2

->2.2

THE RESULT OF OPERATION

**************************

2+2=4

2.2+2.2=4.4

DO YOU WANT TO CONTINUE [Y/N] :N

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 37: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

12. THE VIRTUAL FUNCTION***************************

CODING:

#include<iostream.h>

#include<conio.h>

#include<math.h>

class shape

{

public:

virtual void area(void);

virtual void peri(void);

};

void shape::area(void)

{

}

void shape::peri(void)

{

}

class square:public shape

{

double side;

public:

void input(void);

void area(void);

void peri(void);

};

class rectangle:public shape

{

double side;

public:

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 38: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

void input(void);

void area(void);

void peri(void);

};

class triangle:public shape

{

double h,a,b,c,ba;

public:

void input(void);

void area(void);

void peri(void);

};

void square::input(void)

{

cout<<"\n\nSQUARE";

cout<<"\n******";

cout<<"\n\n Enter the value of side:";

cin>>side;

}

void square::area(void)

{

double area;

area=pow(side,2);

cout<<"\n\n Area of the square is:"<<area;

}

void square::peri(void)

{

double peri=4*side;

cout<<"\n\nPerimeter of the square is:"<<peri;

}

void rectangle::input(void)

{

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 39: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

double length,base;

cout<<"\n\nRECTANGLE";

cout<<"\n*********";

cout<<"\n\nEnter the length:";

cin>>length;

cout<<"\n\nEnter the breadth:";

cin>>base;

}

void rectangle::area(void)

{

double length,base;

double area=length*base;

cout<<"\n\nArea of the rectangle is:"<<area;

}

void rectangle::peri(void)

{

double length,base;

double peri=2*(length+base);

cout<<"\n\nPerimeter of the rectangle is:"<<peri;

}

void triangle::input(void)

{

cout<<"\n\nTRIANGLE";

cout<<"\n********";

cout<<"\n\nEnter the value of first side:";

cin>>a;

cout<<"\n\nEnter the value of second side:";

cin>>b;

cout<<"\n\nEnter the value of third side:";

cin>>c;

cout<<"\nEnter the base:";

cin>>ba;

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 40: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

cout<<"\nEnter the height:";

cin>>h;

}

void triangle::area(void)

{

double area=0.5*ba*h;

cout<<"\n\nArea of the triangle is:"<<area;

}

void triangle::peri(void)

{

double p=(a+b+c);

cout<<"\n\nPerimeter of the triangle:"<<p;

}

void main()

{

clrscr();

char d;

read:

cout<<"THE VIRTUAL FUNTION";

cout<<"\n*******************";

shape*s,sh;

square sq;

rectangle r;

triangle t;

s=&sh;

s=&sq;

sq.input();

s->area();

s->peri();

s=&r;

r.input();

s->area();

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 41: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

s->peri();

s=&t;

t.input();

s->area();

s->peri();

cout<<"\n\n\n\t\t\tDo You Want To Continue[y/n]:";

cin>>d;

if(d=='y')

goto read;

else

getch();

}

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 42: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

OUTPUT:12. THE VIRTUAL FUNCTION***************************

OUTPUT OF THE VIRTUAL FUNCTION

**********************************

SQUARE

*******

Enter the value of side:4

Area of the square is: 16

Perimeter of the square is : 16

RECTANGLE

***********

Enter the length: 4

Enter the breadth: 5

Area of the rectangle is: 20

Perimeter of the rectangle is : 18

TRIANGLE

*********

Enter the value of first side: 6

Enter the value of second side: 4

Enter the value of third side: 5

Enter the base: 5

Enter the height: 5

Area of the triangle is: 5

Perimeter of the triangle: 15

Do You Want To Continue[Y/N]:N

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 43: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

13. MULTIPLICATION TABLE USING CONSOLE********************************************

CODING:

#include<iostream.h>

#include<conio.h>

#include<iomanip.h>

class TAB

{

private:

float res;

int i,n;

public:

float num;

void input(void);

void ini(void);

void output(void);

void disp();

};

void TAB::input(void)

{

cout<<"\n\n Enter which table:";

cin>>num;

cout<<"\n\n Enter number of times:";

cin>>n;

}

void TAB::ini(void)

{

int i;

disp();

}

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 44: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

void TAB::disp(void)

{

cout.precision(3);

cout<<setiosflags(ios::showpoint);

cout<<setiosflags(ios::showpos);

for(i=1;i<=n;i++)

{

res=num*i;

cout<<"\n\t"<<setw(4)<<num<<setw(4)<<"*"<<setw(4);

cout<<i<<setw(5)<<"="<<setw(5)<<res;

}

}

void main()

{

clrscr();

char a='y';

while(a=='y')

{

cout<<"MULTIPLICATION TABLE USING CONSOLE I/O";

cout<<"\n**********************************";

cout<<"\n\nINPUT";

cout<<"\n*****";

TAB t;

t.input();

cout<<"\nOUTPUT";

cout<<"\n******";

cout<<"\n\n Multiplication table";

t.ini();

cout<<"\n\n\n\t\t\t Do You Continue(Y/N)";

cin>>a;

getch();

}}

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 45: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

OUTPUT:13. MULTIPLICATION TABLE USING CONSOLE********************************************

Enter which table: 5

Enter number of times: 10

Multiplication table

+5.000 * +1 =+5.000

+5.000 * +2 =+10.000

+5.000 * +3 =+15.000

+5.000 * +4 =+20.000

+5.000 * +5 =+25.000

+5.000 * +6 =+30.000

+5.000 * +7 =+35.000

+5.000 * +8 =+40.000

+5.000 * +9 =+45.000

+5.000 * +10 =+50.000

Do You Want Continue[Y/N]:N\

SCHOOL OF BUSINESS MANAGEMENT PAGE NO:

Page 46: Final c + + program

OBJECT ORIENTED PROGRAMMING USING C++-LAB BATCH : 2014-2017

SCHOOL OF BUSINESS MANAGEMENT PAGE NO: