0% found this document useful (0 votes)
6 views15 pages

Untitled Document

The document contains multiple C++ programs demonstrating the use of classes and objects for various applications, including number input, distance measurement, time representation, and student information management. Each program defines a class with methods for input and output, showcasing basic object-oriented programming principles. The examples illustrate how to encapsulate data and functionality within classes, along with user interaction through the console.

Uploaded by

muhammad uzair
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)
6 views15 pages

Untitled Document

The document contains multiple C++ programs demonstrating the use of classes and objects for various applications, including number input, distance measurement, time representation, and student information management. Each program defines a class with methods for input and output, showcasing basic object-oriented programming principles. The examples illustrate how to encapsulate data and functionality within classes, along with user interaction through the console.

Uploaded by

muhammad uzair
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/ 15

Exercise Solution

Written By : Ms.Sana Mumtaz


//Q1
#include<iostream>

using namespace std;

class Number

private:

int n;

public:

void get()

cout<<"Enter the no: ";

cin>>n;

void show()

cout<<"no is: "<<n<<endl;

};

int main()

{
Number n1;

n1.get();

n1.show();

return 0;

//Q2

#include<iostream>

using namespace std;

class Distance

private:

int feet;

float inch;

public:

void get()

cout<<"Enter the feet: ";

cin>>feet;

cout<<"Enter the inches: ";

cin>>inch;

void show()

{
cout<<"Distance is: "<<feet<<"\'"<<inch<<"\"";

};

int main()

Distance d1;

d1.get();

d1.show();

return 0;

//Q3

#include<iostream>

using namespace std;

class Time

private:

int h,m,s;

public:

void get()

cout<<"Enter the hours: ";

cin>>h;

cout<<"Enter the mints: ";


cin>>m;

cout<<"Enter the second: ";

cin>>s;

void show()

cout<<"Time is: "<<endl;

cout<<h<<":"<<m<<":"<<s;

};

int main()

Time t1;

t1.get();

t1.show();

return 0;

//Q4

#include<iostream>

#include<string.h>

using namespace std;

class Person

{
private:

int id;

string name;

float salry;

public:

void get()

cout<<"Enter id no: ";

cin>>id;

cin.ignore();

cout<<"Enter name: ";

getline(cin,name);

cout<<"Enter salry: ";

cin>>salry;

void set(int id2,string name1,float salry2)

id=id2;

name=name1;

salry=salry2;

float returnsalry()

{
return salry;

void show()

cout<<"Id is: "<<id<<endl;

cout<<"name is: "<<name<<endl;

cout<<"salry is: "<<salry<<endl;

};

int main()

Person p1,p2;

p2.set(6,"Ali",1200.8);

p1.get();

if(p1.returnsalry()>p2.returnsalry())

p1.show();

else

p2.show();

return 0;

//Q6

#include<iostream>
#include<string.h>

using namespace std;

class Student

private:

int arr[5];

public:

void GET_INFO()

for(int i=0;i<5;i++){

cout<<"Enter the marks of "<<i+1<<" subject:";

cin>>arr[i];

int SUM(){

int sum=0;

for(int i=0;i<5;i++){

sum+=arr[i];

return sum;

float AVG(int sum){

return sum/5;
}

};

int main(){

Student s1;

s1.GET_INFO();

int summ=s1.SUM();

float avg=s1.AVG(summ);

cout<<"Totel Average is: "<<avg;

return 0;

//Q7

#include<iostream>

#include<string.h>

using namespace std;

class Student{

private:

int admno;

char str[20];

float sb1,sb2,sb3,totel;

public:

void get();

float ctotel(){

return sb1+sb2+sb3;
}

void show();

};

void Student::get(){

cout<<"Enter the admno: ";

cin>>admno;

cin.ignore();

cout<<"Enter the name: ";

cin.getline(str,20);

cout<<"Enter the mark of English: ";

cin>>sb1;

cout<<"Enter the mark of Science: ";

cin>>sb2;

cout<<"Enter the mark of Math: ";

cin>>sb3;

totel=ctotel();

void Student::show(){

cout<<"admno is: "<<admno<<endl;

cout<<"name is: "<<str<<endl;

cout<<"Totel no is: "<<totel;

int main(){
Student s1;

s1.get();

s1.show();

return 0;

//Q8

#include<iostream>

#include<string.h>

using namespace std;

class Batman{

private:

int dcode,innng,notout,run;

char str[20];

float batavg;

void calavg(){

batavg=(innng-notout)/run;

public:

void get();

void show();

};

void Batman::get(){

cout<<"Enter the digit code: ";


cin>>dcode;

cin.ignore();

cout<<"Enter the name: ";

cin.getline(str,20);

cout<<"Enter the mark of inngs: ";

cin>>innng;

cout<<"Enter the mark of notout: ";

cin>>notout;

cout<<"Enter the mark of runs: ";

cin>>run;

calavg();

void Batman::show(){

cout<<"digit code is: "<<dcode<<endl;

cout<<"name is: "<<str<<endl;

cout<<"Totel average is: "<<batavg;

int main(){

Batman s1;

s1.get();

s1.show();

return 0;

}
//Q9

#include<iostream>

#include<string.h>

using namespace std;

class Test

private:

int tcode,nocand,centreq;

string str;

int CALCNTR(){

return (nocand/100.0f+1);

public:

void SCHUDLE()

cout<<"Enter the test code: ";

cin>>tcode;

cin.ignore();

cout<<"Enter the description: ";

getline(cin,str);

cout<<"Enter the no of candidate: ";

cin>>nocand;

centreq=CALCNTR();
}

void DISPTEST();

};

void Test::DISPTEST(){

cout<<"test code is: "<<tcode<<endl;

cout<<"description is: "<<str<<endl;

cout<<"Required centre is: "<<centreq;

int main(){

Test s1;

s1.SCHUDLE();

s1.DISPTEST();

return 0;

//Q10

#include<iostream>

#include<string.h>

using namespace std;

class Flight

private:

int fligtno;

float dist,fuel;
string str;

void CALFUEL(){

if(dist<=1000)

fuel=500;

else if(dist>1000 && dist<=2000)

fuel=1100;

else

fuel=2200;

public:

void FEEDINFO()

cout<<"Enter the no of Flight: ";

cin>>fligtno;

cin.ignore();

cout<<"Enter the Destination: ";

getline(cin,str);

cout<<"Enter the distance: ";

cin>>dist;

CALFUEL();

void SHOWINFO();

};
void Flight::SHOWINFO(){

cout<<"No of flight is: "<<fligtno<<endl;

cout<<"destination is: "<<str<<endl;

cout<<"Totel Fuel is: "<<fuel;

int main(){

Flight f1;

f1.FEEDINFO();

f1.SHOWINFO();

return 0;

You might also like