0% found this document useful (0 votes)
63 views8 pages

Agnel Institute of Technology & Design: OOPC++

The document contains 6 programming problems related to object-oriented programming in C++. The problems cover concepts like defining classes with data members and methods, passing objects and data to methods, returning values from methods, and creating arrays of class objects. Sample programs with inputs/outputs are provided for each problem to demonstrate the concepts.

Uploaded by

Mathew
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)
63 views8 pages

Agnel Institute of Technology & Design: OOPC++

The document contains 6 programming problems related to object-oriented programming in C++. The problems cover concepts like defining classes with data members and methods, passing objects and data to methods, returning values from methods, and creating arrays of class objects. Sample programs with inputs/outputs are provided for each problem to demonstrate the concepts.

Uploaded by

Mathew
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/ 8

AGNEL INSTITUTE OF TECHNOLOGY & DESIGN

1.Create a class called EMPLOYEE that has basic_salary and bonus as data

members and method to calculate pay.Create an object of this class and calculate

the total pay of the object by calling appropriate method.

Program:

#include<iostream>

using namespace std;

class employee

public:

float basic_salary,bonus;

void pay()

cout<<"Enter the basic salary and bonus amount\n";

cin>>basic_salary>>bonus;

cout<<"\nToal amount:Rs."<<basic_salary+bonus;

}};

int main()

employee e;

e.pay();

return 0;

OUTPUT:

Enter the basic salary and bonus amount

50000

5000

Toal amount:Rs.55000

OOPC++ RollNo.18CO05
AGNEL INSTITUTE OF TECHNOLOGY & DESIGN

2.Use the same class in problrm1, use concept of methods returning value to calculate individual
object.

Program:

#include<iostream>

using namespace std;

class employee

public:

float basic_salary,bonus;

float pay()

{ float total;

cout<<"Enter the basic salary and bonus amount\n";

cin>>basic_salary>>bonus;

total=basic_salary+bonus;

return total;

}};

int main()

employee e;

cout<<"Total amount:Rs."<<e.pay();

return 0;

OUTPUT:

Enter the basic salary and bonus amount

20000

5000

Total amount:Rs.25000

OOPC++ RollNo.18CO05
AGNEL INSTITUTE OF TECHNOLOGY & DESIGN

3.Use same class in problem 1,with returning concept,Pass following data HRA,DA and
calculate total pay for employee object.

Program:

#include<iostream>

using namespace std;

class employee

public:

float basic_salary,bonus,HRA,DA;

int pay()

{ float total;

cout<<"Enter the basic salary and bonus amount\n";

cin>>basic_salary>>bonus;

total=basic_salary+bonus+HRA+DA;

return total;

void calc(float h,float d)

HRA=h;

DA=d;

}};

int main()

employee e;

e.calc(1000,2500);

cout<<"Total amount(Basic Salary+Bonus+HRA+DA):Rs."<<e.pay();

return 0;

OUTPUT:

OOPC++ RollNo.18CO05
AGNEL INSTITUTE OF TECHNOLOGY & DESIGN

Enter the basic salary and bonus amount

20000

3000

Total amount(Basic Salary+Bonus+HRA+DA):Rs.26500

4.Create a class box having data members length and width,pass length and width as
parameters and calculate area.

Program:

#include<iostream>

using namespace std;

class box

public:

float length,width;

void area(float l,float w)

length=l;

width=w;

cout<<"\nArea:"<<length*width;

}};

int main()

box b;

float le,wi;

cout<<"Enter length and width\n";

cin>>le>>wi;

b.area(le,wi);

return 0;

OOPC++ RollNo.18CO05
AGNEL INSTITUTE OF TECHNOLOGY & DESIGN

OUTPUT:

Enter length and width

10

20

Area:200

5.To write a program in C++ to prepare student record using class and object where data
members are name, rollno, marks for 6 subjects and percentage of each student having member
functions getdata,calculate_ percentageand display.

Program:

#include<iostream>

using namespace std;

class student

public:

int roll;

char name[20];

float marks[5];

void getdata()

cout<<"\nEnter name of student:";

cin>>name;

cout<<"\nEnter roll no of student:";

cin>>roll;

cout<<endl;

for(int j=0;j<6;j++)

cout<<"Enter marks of subject"<<j+1<<":";

cin>>marks[j];

OOPC++ RollNo.18CO05
AGNEL INSTITUTE OF TECHNOLOGY & DESIGN

}}

void calculate_percentage()

float total,per;

for(int j=0;j<6;j++)

total+=marks[j];

per=(total/600.0)*100;

display(per);

void display(float p)

cout<<"\nStudent name:"<<name<<"\nStudent Roll no:"<<roll<<"\nStudent


percentage:"<<p;

};

int main()

student s;

s.getdata();

s.calculate_percentage();

return 0;

OUTPUT:

Enter name of student:jason

Enter roll no of student:5698

Enter marks of subject1:50

Enter marks of subject2:50

OOPC++ RollNo.18CO05
AGNEL INSTITUTE OF TECHNOLOGY & DESIGN

Enter marks of subject3:50

Enter marks of subject4:50

Enter marks of subject5:50

Enter marks of subject6:50

Student name:jason

Student Roll no:5698

Student percentage:50

6.Create a class EMPLOYEE that has empcode and empname as data members.Write a
member function getdata( )to input data and a member function display( )to output data.Write
a main function to create an array of EMPLOYEE objects.Accept and display details of atleast
3 employees

Program:

#include<iostream>

using namespace std;

class employee

public:

int empcode;

char empname[10];

void getdata()

cout<<"\nEnter employee code and employee name\n";

cin>>empcode>>empname;

void display()

cout<<"\nEmloyee name:"<<empname<<"\t"<<"Employee code:"<<empcode;

};

OOPC++ RollNo.18CO05
AGNEL INSTITUTE OF TECHNOLOGY & DESIGN

int main()

employee e[2];

for(int i=0;i<3;i++)

e[i].getdata();

for(int i=0;i<3;i++)

e[i].display();

return 0;

OUTPUT:

Enter employee code and employee name

56

Jason

Enter employee code and employee name

89

Rahul

Enter employee code and employee name

54

Mehul

Emloyee name:Jason Employee code:56

Emloyee name:Rahul Employee code:89

Emloyee name:Mehul Employee code:54

OOPC++ RollNo.18CO05

You might also like