0% found this document useful (0 votes)
53 views

1 Simple Message Display Coding

The document contains code for 8 programs demonstrating various C++ concepts like message display, arithmetic operators, converting case, checking number types, converting numbers to words, employee payroll, object oriented arithmetic operations, and string overloading. Each program section includes the code, inputs, and outputs for that program. The programs cover basic C++ concepts like data types, user input, conditional statements, functions, classes and objects.

Uploaded by

Prabu Prabhu
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)
53 views

1 Simple Message Display Coding

The document contains code for 8 programs demonstrating various C++ concepts like message display, arithmetic operators, converting case, checking number types, converting numbers to words, employee payroll, object oriented arithmetic operations, and string overloading. Each program section includes the code, inputs, and outputs for that program. The programs cover basic C++ concepts like data types, user input, conditional statements, functions, classes and objects.

Uploaded by

Prabu Prabhu
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/ 46

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:

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:

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:

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:

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:

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:

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:

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";
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

if(n==9)
cout<<"Nine";
getch();
}
OUTPUT:

5. NUMBER INTO WORDS


***********************
NUMBER INTO WORDS
*********************
INPUT
*****
Enter the n value: 1
OUTPUT
*******
One

SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

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;
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

cout<<"\nOUTPUT\n";
cout<<"******\n";
if(g=='m'&&yos>10&&qual==1)
sal=15000;
else
if(g=='m'&&yos>10&&qual==0)
sal=10000;
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:

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
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

Enter qualification : 0
OUTPUT:
********
SALARY OF EMPLOYEE= 10000

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:
********
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

SALARY OF EMPLOYEE= 9500

6. EMPLOYEE PAYROLL STATEMENT


************************************
INPUT:
******
Enter name: Shilpa
Enter gender: F
Enter year of service: 12
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
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

Enter gender: F
Enter year of service: 5
Enter qualification : 0
OUTPUT:
********
SALARY OF EMPLOYEE= 5000

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:

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=";
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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;
}
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();
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

O.div();
O.mod();
O.display();
getch();
}

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:

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";
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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;
}
void string::cmpr()
{
cout<<"\n\nCOMPARISON\n";
cout<<"----------";
if(strcmp(st1,st2)==0)
cout<<"\n\nComparison of two strings are equal"<<endl;
else
cout<<"\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;
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

clrscr();
x.read();
x.concat();
x.cmpr();
x.strleng();
getch();
}

OUTPUT:

8. STRING OVERLOADING
**************************
STRING OVERLOADING
*********************
INPUT
*****
Enter the first string : Guptha
Enter the second string :Arun
OUTPUT
*******
CONCATENATION
--------------------------Concatenation of the string : GupthaArun
COMPARISON
--------------------Comparison of two strings are not equal
LENGTH
-----------SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

Length of the string entered : 10

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!";
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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;
}
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;
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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";
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:

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
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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

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
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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

OUTPUT
*******
Account details
Name of the depositer : Alex
Account number: 45450
Account type: SAMG
Balance: Rs.97,000

SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

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;
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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";
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;
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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;
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;
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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();}

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
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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
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
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

*****
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

11.IMPLEMENTING OF FRIENDLY FUNCTION


******************************************
CODING:
#include<iostream.h>
#include<conio.h>
class SECOND;
class FIRST
{
private:
int f1;
float f2;
public:
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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****";
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)
{
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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;
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;
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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();
}
}
}

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 !!
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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

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)
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

{
}
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:
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";
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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)
{
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)
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

{
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;
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()
{
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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();
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:

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
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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

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);
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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();
}
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';
SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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();
}}

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

SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

OBJECT ORIENTED PROGRAMMING USING C++-LAB

BATCH : 2014-2017

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

SCHOOL OF BUSINESS MANAGEMENT

PAGE NO:

You might also like