0% found this document useful (0 votes)
22 views

Assignment 1

The document contains 4 programming questions involving C++ classes. The first question involves defining a Book class with methods to get, set, and display book details. The second defines classes for buildings to calculate area per person. The third defines a Result class to input, display and calculate marks and averages of students. The fourth defines a Rectangle class to get dimensions, calculate and display the area and perimeter.

Uploaded by

Faryal Fatima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Assignment 1

The document contains 4 programming questions involving C++ classes. The first question involves defining a Book class with methods to get, set, and display book details. The second defines classes for buildings to calculate area per person. The third defines a Result class to input, display and calculate marks and averages of students. The fourth defines a Rectangle class to get dimensions, calculate and display the area and perimeter.

Uploaded by

Faryal Fatima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

NAME FARYAL FATIMA

ROLL NO F2020387063
CLASS ADP(CS)
SECTION QCA
RESOURCE PERSON SIR MOHSIN ASHRAF
ASSIGNMENT NO 1:
Question no 1:
#include<iostream>
using namespace std;

class Book
{
public:
int BookID,Pages,Price;
void get()
{
cout<<"Enter your Book ID: ";
cin>>BookID;
cout<<"Enter your number of Pages: ";
cin>>Pages;
};
void show()
{
cout<<"Book ID is: "<<BookID<<endl;
cout<<"Number of Page(s) are: "<<Pages<<endl;
};
void set(int id, int pg)
{
BookID=id;
Pages=pg;
};

int getprice()
{
cout<<"Enter the Book Price: ";
cin>>Price;
return Price;
}
};
int main()
{
int id,pg,pr;
Book d2;
d2.get();
pr=d2.getprice();
d2.show();
d2.set(id,pg);
cout<<"Book price is: "<<pr;
return 0;
}
Question no 2:
#include<iostream>
using namespace std;
class Building
{
public:
float Floors,Area,Occupants;
float app;
float AreaPerPerson()
{
app=Area/Occupants;
return app;
};
};

int main()
{
float hArea,oArea;
Building house;
Building office;

cout<<"Enter the value of house Floors: ";


cin>>house.Floors;
cout<<"Enter the value of house Area: ";
cin>>house.Area;
cout<<"Enter the value of house Occupants: ";
cin>>house.Occupants;
hArea=house.AreaPerPerson();
cout<<"Area per person of House: "<<hArea<<endl;
cout<<"Enter the value of office Floors: ";
cin>>office.Floors;
cout<<"Enter the value of office Area: ";
cin>>office.Area;
cout<<"Enter the value of office Occupants: ";
cin>>office.Occupants;
oArea=office.AreaPerPerson();
cout<<"Area per person of Office: "<<oArea<<endl;
return 0;
}
QUESTION NO 3:
#include<iostream>
using namespace std;

class Result
{
public:
float rollno,marks[3],totl;
float average;
string name;
void input()
{
cout<<"Student Name: ";
cin>>name;
cout<<"Student Roll no: ";
cin>>rollno;
cout<<"Marks of subject 1: ";
cin>>marks[0];
cout<<"Marks of subject 2: ";
cin>>marks[1];
cout<<"Marks of subject 3: ";
cin>>marks[2];
};
void show()
{
cout<<"Student Name: "<<name<<endl;
cout<<"Student Roll no:"<<rollno<<endl;
cout<<"Marks of Subject 1 is: "<<marks[0]<<endl;
cout<<"Marks of Subject 2 is: "<<marks[1]<<endl;
cout<<"Marks of Subject 3 is: "<<marks[2]<<endl;
};
float total()
{
totl=marks[0]+marks[1]+marks[2];
return totl;
};
float avg()
{
average=(marks[0]+marks[1]+marks[2])/3;
return average;
};
};
int main()
{
int T,a;
Result rst;
rst.input();
rst.show();
T=rst.total();
a=rst.avg();
cout<<"Total Marks are: "<<T<<endl;
cout<<"Average is: "<<a<<endl;
return 0;
}
Question no 4:
#include<iostream>
using namespace std;

class RECTANGLE
{
public:
float Length=1,Width=1,Area,Perimeter;
void AreaPerimeter()
{
Area=Length*Width;
cout<<"Area: "<<Area;
Perimeter=2*(Length+Width);
cout<<"Perimeter: "<<Perimeter<<" meters"<<endl;
};
void set()
{
if(Length>0&&Length<=20 && Width>0&&Width<=20)
{
AreaPerimeter();
}
else
{
cout<<endl<<"Invalid Input";
}
};
void get()
{
cout<<"Enter Length: ";
cin>>Length;
cout<<"Enter Width: ";
cin>>Width;
set();
};
};
int main()
{
RECTANGLE rect1;
rect1.get();
return 0;
}

You might also like