Assignment 1
Assignment 1
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;
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;
}