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

VIPUL.H #Include #Include #Include #Include #Include #Include #Include #Include #Include #Include

The document contains C++ code for several programs that use classes and objects. The code defines classes like worker, bank, teacher, and stu. It includes functions to input data into object attributes, calculate values, and output object information. The main function creates objects and calls member functions and friend functions to demonstrate working with classes and objects.

Uploaded by

Vipul Aggarwal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

VIPUL.H #Include #Include #Include #Include #Include #Include #Include #Include #Include #Include

The document contains C++ code for several programs that use classes and objects. The code defines classes like worker, bank, teacher, and stu. It includes functions to input data into object attributes, calculate values, and output object information. The main function creates objects and calls member functions and friend functions to demonstrate working with classes and objects.

Uploaded by

Vipul Aggarwal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 12

//VIPUL.

#include<iostream.h>

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#include<process.h>

#include<ctype.h>

#include<math.h>

#include<iomanip.h>

#include<string.h>

#include<fstream.h>
//VIPUL AGGARWAL XII – ‘A’
//PROGRAM NO. 9
/*TO CALCULATE SALARIES OF WORKER'S */
#include”vipul.h”
class worker
{
char wname[20] ;
float hrwrk,wgrate;
float totwage;
float calcwg()
{
totwage=hrwrk*wgrate;
return totwage;
}
public:
long wno;
void in_data()
{
cout<<"\n\t\t\tENTER WORKER'S NUMBER : ";
cin>>wno;
cout<<"\n\t\t\tENTER WORKER'S NAME : ";
cin>>wname;
cout<<"\n\t\t\tENTER NUMBER OF HOURS
WORKED : ";
cin>>hrwrk;
cout<<"\n\t\t\tENTER THE WEDGE RATE : ";
cin>>wgrate;
calcwg();
}
void out_data()
{
cout<<"\n\t\t\tWORKER'S NUMBER IS : "<<wno;
cout<<"\n\t\t\tWorker's Name Is : "<<wname;
cout<<"\n\t\t\tHOURS WORKED : "<<hrwrk;
cout<<"\n\t\t\tWEDGE RATE IS : "<<wgrate;
cout<<"\n\t\t\tTOTAL WAGE IS : "<<totwage;
cout<<"\n";
}
};
worker w;
void main()
{
clrscr();
w.in_data();
w.out_data();
getch();
}

//OUTPUT:
ENTER WORKER'S NUMBER : 3123
ENTER WORKER'S NAME : PIYUSH
ENTER NUMBER OF HOURS WORKED : 13
ENTER THE WEDGE RATE: 1
WORKER'S NUMBER IS: 3123
WORKER'S NAME IS: PIYUSH
HOURS WORKED: 13
WEDGE RATE IS: 1
TOTAL WAGE IS: 13
//VIPUL AGGARWAL XII – ‘A’
//PROGRAM NO. 10
//PROGRAM USING FRIEND FUNCTION
#include”vipul.h”
class bank
{
int acno;
char name[20];
int t;
float s;
public:
void assign()
{
cout<<"\n\t\t\tENTER ACCOUNT NO.: ";
cin>>acno;
cout<<"\n\t\t\tENTER NAME. : ";
gets(name);
cout<<"\n\t\t\tENTER TIME : ";
cin>>t;
cout<<"\n\t\t\tENTER AMOUNT : ";
cin>>s;
}
friend void display();
}b;
void display()
{
clrscr();
cout<<"\n\t\t\tACCOUNT NO. : "<<b.acno;
cout<<"\n\t\t\tNAME. : "<<b.name;
cout<<"\n\t\t\tTIME : "<<b.t;
cout<<"\n\t\t\tAMOUNT : "<<b.s;
}
void main()
{
clrscr();
b.assign();
display();
getch();
}

//OUTPUT

ENTER ACCOUNT NO.: 450

ENTER NAME. : PIYUSH

ENTER TIME : 1

ENTER AMOUNT : 1200

ACCOUNT NO. : 450


NAME. : PIYUSH
TIME : 1
AMOUNT : 1200
//VIPUL AGGARWAL XII – ‘A’
//PROGRAM NO. 11
//PROGRAM USING NESTED CLASS
#include”vipul.h”
class outer
{
public:
int a;
class inner
{
int b;
int c;
public:
void prn(void)
{
cout<<endl<<"inner::prn()"<<endl;
cout<<b<<c<<endl;
}
inner()
{
b=5;
c=10;
}
};
inner ob1;
void second(void)
{
cout<<endl<<"outer::second()"<<endl;
cout<<ob1.c<<endl;
cout<<"a="<<a<<endl;
ob1.prn();
}
outer()
{a=25;}
};
void main()
{
outer ab;
ab.second();
ab.ob1.prn();
}

//OUTPUT

outer::second()
10
a=25

inner::prn()
510

inner::prn()
510
//VIPUL AGGARWAL XII – ‘A’
//PROGRAM NO. 12
//Calculate Salary of a teacher using class & objects with
functions//
#include”vipul.h”
class teacher{
private:
char name[20];
char subject[10];
float basic,DA,HRA;
float salary;
float calculate()
{
salary=basic+DA+HRA;
return salary;
}
public:
void readdata()
{
cout<<"ENTER TEACHER'S NAME:";
cin>>name;
cout<<"ENTER THE SUBJECT:";
cin>>subject;
cout<<"ENTER BASIC:";
cin>>basic;

cout<<"ENTER DA:";
cin>>DA;
cout<<"ENTER HRA:";
cin>>HRA;
}
void showdata()
{
cout<<"NAME:"<<name<<" "<<"SUBJECT:"<<" "<<subject<<"
";
cout<<"BASIC:"<<basic<<" "<<"DA:"<<DA<<"
"<<"HRA:"<<HRA<<" ";
cout<<"CALCULATED SALARY IS RS."<<salary;
}
};
void main()
{
clrscr();
teacher t;
t.readdata();
t.showdata();
getch();
return;
}

//OUTPUT

ENTER TEACHER'S NAME:ABC


ENTER THE SUBJECT:SALARY
ENTER BASIC:3000
ENTER DA:3000
ENTER HRA:6000
NAME:ABC SUBJECT: SALARY BASIC:3000 DA:3000 HRA:6000
CALCULATED SALARY IS RS.12000
//VIPUL AGGARWAL XII-‘A’
//PROGRAM NO. 13
/*TO USE FRIEND FUNCTION*/
#include”vipul.h”
class stu
{
int roll;
char name[20];
float marks;
public:
void input()
{
cout<<"\n\t\t\t ENTER NAME : ";
gets(name);
cout<<"\n\t\t\t ENTER ROLL NUMBER : ";
cin>>roll;
cout<<"\n\t\t\tENTER MARKS : ";
cin>>marks;
}
void output()
{
cout<<"\n\t\t\t NAME : "<<name;
cout<<"\n\t\t\t ROLL NUMBER : "<<roll;
cout<<"\n\t\t\tMARKS : "<<marks;
}
friend void abc();
}s;
void abc()
{
if(s.marks>400)
cout<<"\n\t\t\t*****EXCELLENT*****";
else
cout<<"\n\t\t\t*****WORK HARD*****";
}
void main()
{
clrscr();
s.input();
s.output();
abc();
getch();
}

//OUTPUT

ENTER NAME : PIYUSH

ENTER ROLL NUMBER : 12

ENTER MARKS : 85

NAME : PIYUSH
ROLL NUMBER : 12
MARKS : 85
*****WORK HARD*****

You might also like