Opp All Program File
Opp All Program File
Question no 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 Myclass
private:
int data;
public:
void getdata()
cout<<"enter data";
cin>>data;
void showdata()
cout<<"data is"<<data<<endl;
}
};
int main()
Myclass obj1,obj2;
obj1.getdata();
obj2.getdata();
obj1.showdata();
obj2.showdata();
return 0;
Question no 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:
inches = i;
void showDist() {
cout << "Distance: " << feet << " feet " << inches << " inches" << endl;
};
int main() {
Distance d1, d2
d1.getDist(5, 8.5);
d2.getDist(3, 6.2);
d1.showDist();
d2.showDist();
return 0;
Question no 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 << "Time: " << hours << ":" << minutes << ":" << seconds << endl;
};
int main() {
t1.showTime();
t2.showTime();
return 0;
Question no 07
#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;
}
Question no 04
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.
#include <iostream>
class Person {
private:
int Pid;
char Pname[50];
float PSalary;
public:
void getdata() {
cin.ignore();
cin.getline(Pname, 50);
void showdata() {
}
void setdata(int id, const char name[], float salary) {
Pid = id;
strcpy(Pname, name);
PSalary = salary;
float getSalary() {
return PSalary;
};
int main() {
p1.getdata();
p2.getdata()
p3.getdata();
highest = p2;
highest.showdata();
return 0;