assignment
assignment
BSCS51F24S012
Question 1 Write a program that declared a class with one integer data
member and two member functions for input data and output data. Decide
appropriate access modifiers for these members. Use this class in your
program
#include <iostream>
class my class
#include<iostream>
class REPORT
private:
int adno;
char name[20];
void GETAVG()
int sum = 0;
average = sum/5.0f;
}
public:
void READINFO()
cout<<"Enter id ";
cin>>adno;
cin>>name;
cin>>marks[i];
GETAVG ();
void DISPLAYINFO ()
cout<<"admision Id "<<adno<<endl;
cout<<"Name "<<name<<endl;
cout<<"Average "<<average<<endl;
};
int main()
REPORT R1;
R1.READINFO();
cout<<endl;
R1.DISPLAYINFO();
return 0;
}int data;
public:
void getdata()
void showdata()
};
int main()
obj1.getdata();
obj2.getdata();
obj1.showdata();
obj2.showdata();
return 0;
Question 2 Create a class named Distance that has feets (as int) and inches (as
float). The class has Getdist (int, float) to get the specified value in object,
Showdist () to display distance object in feets’ inches” format. Write main ()
function to create two distance objects. Get the value in two objects and
display all objects.
#include<iostream>
class Distance
private:
int feet;
float inches;
public:
feet=f;
inches=i;
}
void Showdist()
cout<< feet << '\'' << inches << '\"' << endl;
float totalinches()
};
int main()
Distance Dist1,Dist2;
int f1;
float i1;
cin>>f1>>i1;
Dist1.Getdist(f1,i1);
int f2;
float i2;
cin>>f2>>i2;
Dist2.Getdist(f2,i2);
cout<<"\nDistance 1:";
Dist1.Showdist();
}*/
cout<<"\nDistance 1:";
Dist1.Showdist();
else
cout<<"Distance 2:";
Dist2.Showdist();
return 0;
}
Question 3 Create a class named TIME that has hours, minutes and seconds data
members as integer. The class has settime (int, int, int) to set the specified value in
object, showtime () to display time object in hh:mm:ss format. Write main ()
function to create two time objects. Set the value in two objects and display all
time objects.
#include <iostream>
class TIME {
private:
public:
hours = h;
minutes = m;
seconds = s;
void showtime() {
cout << hours << ":" << minutes << ":" << seconds << endl;
};
int main() {
t1.showtime();
t2.showtime();
return 0;
Question 4 Create a class Person that has three data members Pid, Pname,
PSalary with appropriate data type. Person class also contains the member
functions: getdata() function is used to input values, showdata() function is
used to display value, setdata() function is used to set the values of data
members using parameters, getSalary() function is used to return the value of
person salary. The program should create three objects of the person class
and input values for these objects. The program display the details of highest
salary holder person.
Q no 4
#include <iostream>
class Person {
private:
int Pid;
string Pname;
double PSalary;
public:
void getdata() {
void showdata() {
cout << "ID: " << Pid << ", Name: " << Pname << ", Salary: " << PSalary << endl;
Pid = id;
Pname = name;
PSalary = salary;
double getSalary() {
return PSalary;
};
int main() {
Person persons[3];
persons[i].getdata();
int maxIndex = 0;
maxIndex = i;
persons[maxIndex].showdata();
return 0;
}
QUESTION 5 Write a class Employee with three data members Eid type int, Ename type string
and Esalary type double. It also contains the following member function:
• The get() function is used to input values
• The show() function is used to display values
• The set() function is used to set the values of data members using parameteThe
returnSalary() function is used to return the salary of employee.
The program should create two object of the employee class, input the values and display the
record of that employee whose monthly salary is greater.
#include <iostream>
using namespace std;
class Employee {
private:
int Eid;
string Ename;
double Esalary;
public:
void get() {
cout << "Enter Employee ID, Name, and Salary: ";
cin >> Eid >> Ename >> Esalary;
}
void show() {
cout << "Employee ID: " << Eid << ", Name: " << Ename << ", Salary: " << Esalary <<
endl;
}
double returnSalary() {
return Esalary;
}
};
int main() {
Employee emp1, emp2;
emp1.get();
emp2.get();
return 0;
}
Question 6 Write a program that declare a class Student with five data
members to store five subject mark of student. Class also includes three
member function for input marks, Sum() to calculate and return the sum of
five subject and Avg() to calculate and return the average marks of fiv
#include <iostream>
using namespace std;
class Student {
private:
int marks[5];
public:
void getMarks() {
cout << "Enter marks for 5 subjects (out of 100): ";
for (int i = 0; i < 5; i++) {
cin >> marks[i];
}
}
int Sum() {
int sum = 0;
for (int i = 0; i < 5; i++) {
sum += marks[i];
}
return sum;
}
double Avg() {
return Sum() / 5.0;
}
};
int main() {
Student student;
student.getMarks();
return 0;
}e subject. Each subject has a maximum of 100 marks. Use this class in your program.
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
int admno;
string sname;
float total;
public:
void Takedata() {
cin.ignore();
getline(cin, sname);
void Showdata() {
};
int main() {
Student s1, s2; cout << "Enter details for Student 1:" << endl;
s1.Takedata();
s2.Takedata();
s1.Showdata();
cout << "\nStudent 2 Details:" << endl;
s2.Showdata();
return 0;
#include <string>
class Batsman {
private:
int bcode;
string bname;
float batavg;
} else {
batavg = 0.0;
public:
void readdata() {
cin.ignore();
getline(cin, bname);
calcavg();
void displaydata() {
cout << "Batsman Code: " << bcode << endl;
cout << "Number of Times Not Out: " << notout << endl;
};
int main() {
Batsman b;
b.readdata();
b.displaydata();
return 0;
#include <string>
class TEST {
private:
int TestCode;
string Description;
int NoCandidate;
int CenterReqd;
int CALCNTR() {
public:
void SCHEDULE() {
cin.ignore();
getline(cin, Description);
cout << "Enter Number of Candidates: ";
CenterReqd = CALCNTR();
cout << "Number of Centers Required: " << CenterReqd << endl;
void DISPTEST() {
cout << "Number of Centers Required: " << CenterReqd << endl;
};
int main() {
TEST t;
t.SCHEDULE();
t.DISPTEST();
return 0;
class REPORT
private:
int adno;
char name[20];
void GETAVG()
int sum = 0;
average = sum/5.0f;
public:
void READINFO()
cout<<"Enter id ";
cin>>adno;
cin>>name;
cin>>marks[i];
GETAVG ();#include<iostream>
class REPORT
{
private:
int adno;
char name[20];
void GETAVG()
int sum = 0;
void DISPLAYINFO ()
cout<<"admision Id "<<adno<<endl;
cout<<"Name "<<name<<endl;
cout<<"Average "<<average<<endl;
int main()
REPORT R1;
R1.READINFO();
cout<<endl;
R1.DISPLAYINFO();
};
….……………………
….……………………
/// destructor
///
#include<iostream>
class Distance
private:
int feet;
float inches;
public:
void Getdist()
cin>>feet;
cin>>inches;
}
void Showdist()
cout<<"Distance is "<<feet <<"\', " << inches << '\"' << endl;
///d3.Adddist(d1, d2);
Distance temp;
temp.inches -= 12;
temp.feet++;
return temp;
~Distance() {}
};
int main()
d3 = d1.Adddist(d2);
cout<<"Dist1: ";
d1.Showdist();
cout<<"Dist2: ";
d2.Showdist();
cout<<"Dist3: ";
d3.Showdist();
return 0;