Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Practical No: 7

Program to Implement Array of Objects


Practical Related Questions:
1) State the output the following program:
Exercise:
1) Write a C++ program to define class
“Employee” having data members emp_id,
emp_name and emp_salary. Accept and display
data for employees having salary greater than
25,000/-.
2) Write a C++ program to define a class “City”
having data member’s name, population. Accept
and display data for 10 cities.
3) Complete the given table:
#include<iostream>
using namespace std;
class student
{
char name[20];int marks;public:
void getName()
{
cin>>name;
}
void getMarks()
{
cin>>marks;
}
void displayInfo()
{
cout<<"Name:"<<name<<endl;
cout<<"marks: "<<marks<<endl;
};
int main()
{
student st[5];
for(int i=0;i<5;i++)
{
cout<<"student"<<i+1<<endl;
cout<<"Enter name"<<endl;
st[i].getName();
cout<<"Enter marks"<<endl;
st[i].getMarks();
}
for(int i=0;i<5;i++)
{
cout<<"student"<<i+1<<endl;
st[i].displayInfo()
}
#include<iostream>
using namespace std;
class Employee
{
int Id;
char Name[25];
int Age;
long Salary;
public:

void GetData()
{
cout<<"\n\t Enter Employee Id: ";
cin>>Id;
cout<<"\n\t Enter Employee Name: ";
cin>>Name;
cout<<"\n\t Enter Employee Age: ";
cin>>Age;
cout<<"\n\t Enter employee Salary: ";
cin>>Salary;
}
void PutData()
{
cout<<"\n"<<Id<<"\t"<<Name<<"\t"<
<Age<<"\t"<<Salary;
}
};
int main()
{
int i;
Employee E[3];
for(i=0;i<3;i++)
{
cout<<"\n Enter details of
"<<i+1<<"Employee";
E[i].GetData();
}
cout<<"\n Details of Employees";
for(i=0;i<3;i++)
E[i].PutData();
return 0;
}

You might also like