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

Oop Lab 7 Fa19-Bee-170

The document contains code for multiple C++ classes and programs related to object-oriented programming concepts. It defines classes like Publication, Book, Tape, Person, Student, Computer, Laptop, and others. The main() function in each code snippet creates objects of these classes and calls their member functions to get and display data. The document appears to be a student's lab report or homework assignments on OOP concepts in C++.

Uploaded by

Atyia Javed
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)
21 views

Oop Lab 7 Fa19-Bee-170

The document contains code for multiple C++ classes and programs related to object-oriented programming concepts. It defines classes like Publication, Book, Tape, Person, Student, Computer, Laptop, and others. The main() function in each code snippet creates objects of these classes and calls their member functions to get and display data. The document appears to be a student's lab report or homework assignments on OOP concepts in C++.

Uploaded by

Atyia Javed
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/ 35

OSAMA AFZAL

FA19-BEE-170
BEE-3D
OOP
LAB REPORT 7
TASK 1:
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
class publication {
string title;
int price;
public:
void getdata(){
cout << "\nEnter the title of the book: " << endl;
cin >> title;
cout << "\nEnter the price of the book:" <<
endl;
cin >> price;
}
void putdata(){
cout << "\nThe title of the book: " << title
<<endl;
cout << "The price of the book: " << price <<
endl;
}
};
class book : public publication {
int pages;
public:
void getdata(){
cout << "\nEnter the page count: " << endl;
cin >> pages;
}
void putdata(){
cout << "Number of pages: " << pages << endl;
}
};
class tape : public publication {
int time;
public:
void getdata(){
cout << "\nEnter the playing time in minutes: "
<< endl;
cin >> time;
}
void putdata(){
cout << "The playing time in minutes: " << time
<< endl;
}
};
int main ()
{
publication p1;
book b2;
tape t3;

p1.getdata();
b2.getdata();
t3.getdata();

p1.putdata();
b2.putdata();
t3.putdata();

return 0;
}
TASK 2:
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
class Person {
string ID;
string Name ,Address;
public:
void getdata(){
cout << "\nEnter The ID: " << endl;
cin >> ID;
cout << "\nEnter The Name: " << endl;
cin >> Name;
cout << "\nEnter The Address: " << endl;
cin >> Address;
}
void putdata(){
cout << "\nID: " << ID <<endl;
cout << "Name: " << Name << endl;
cout << "Address: " << Address << endl;
}
};
class Student : public Person {
int RollNumber,Marks;
public:
void getdata(){
cout << "\nEnter the Roll Number: " << endl;
cin >> RollNumber;
cout << "\nEnter the marks: " << endl;
cin >> Marks;
}
void putdata(){
cout << "Roll Number: " << RollNumber <<
"\nMarks: "<< Marks << endl;
}
};
int main ()
{
Person P1;
Student S1;
P1.getdata();
S1.getdata();
P1.putdata();
S1.putdata();
return 0;
}
TASK 3:
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
class Computer
{
int wordsize,memorysize,storagesize;
float speed;
public:
Computer() :
wordsize(0),memorysize(0),storagesize(0),spee
d(0){}
void getdata(){
cout << "\nEnter the Word Size in Bits: " <<
endl;
cin >> wordsize;
cout << "Enter the Memory Size in
MegaBytes(MB): " << endl;
cin >> memorysize;
cout << "Enter the Storage Size in
MegaBytes(MB): " << endl;
cin >> storagesize;
cout << "Enter the Speed in MegaHertz(MHz): "
<< endl;
cin >> speed;
}
void showdata(){
cout<<"Word Size: "<<wordsize <<" Bits"<<endl
<<"Memory Size: "<<memorysize<<"
MB"<<endl<<"Storage Size: "<<storagesize<<"
MB"<<endl<<"Speed: "<<speed<<"
MHz"<<endl;
}
};
class Laptop : public Computer
{
float length,width,height,weight;
public:
Laptop():length(0), width(0), height(0)
,weight(0){
}
void getdata(){
cout<<"\nEnter The Length: "<< endl;
cin>>length;
cout<<"Enter The Width: "<< endl;
cin>>width;
cout<<"Enter The Height: "<< endl;
cin>>height;
cout <<"Enter The Weight: "<< endl;
cin >> weight;
}
void showdata(){
cout<<"Length: "<<length<<endl<<"Width:
"<<width<<endl<<"Height:
"<<height<<endl<<"Weight: "<<weight<<endl;
}
};
int main ()
{
Computer C1;
Laptop L1;
C1.getdata();
L1.getdata();
cout<<endl;
C1.showdata();
L1.showdata();

return 0;
}
HOME TASKS 1:
#include<iostream>
#include<string>
using namespace std;
class Student{
protected:
int rollno;
string name;
public:
void getdata(){
cout <<"\nEnter your Roll No: ";
cin >> rollno;

cout <<"\nEnter your name: ";


cin >> name;
}
void putdata(){
cout <<"Roll No: " <<rollno <<endl <<
"Name: " <<name <<endl;
}
};
class Test : public Student{
protected:
float T1marks, T2marks, T3marks,
Sessional1, Sessional2, Assignment ,Final;
float
Tmarks,sum,percentage1,percentage2,result;
public:
void getmarks(){
cout <<"\nEnter your marks:";
cout<<"\nT1 marks: ";
cin >> T1marks;
cout<<"\nT2 marks: ";
cin >> T2marks;
cout<<"\nT3 marks: ";
cin >> T3marks;
cout<<"\nSessional 1: ";
cin >> Sessional1;
cout<<"\nSessional 2: ";
cin >> Sessional2;
cout<<"\nAssignment: ";
cin >> Assignment;
cout<<"\nFinal: ";
cin >> Final;
}
void putmarks(){

cout<<"T1 marks: "<<T1marks <<endl


<<"T2 marks: "<<T2marks <<endl<<"T3 marks:
"<<T3marks <<endl<<"Sessional 1:
"<<Sessional1<<endl<<"Sessional 2:
"<<Sessional2<<"Assignment:
"<<Assignment<<endl<<"Final: "<<Final<<endl;
}
void Finalresult(){

Tmarks=((T1marks+T2marks+T3marks)/30)*15;
sum=Tmarks+Assignment+Sessional1+Sessional
2;
percentage1=(sum/50)*100;
percentage2=(Final/50)*100;
result=(percentage1+percentage2)/2;
cout <<"Final result: "<<result<<"%";
}
};
int main(){
Student S1; Test T1; S1.getdata();
T1.getmarks();
cout<<endl<<endl;
S1.putdata(); T1.putmarks();
T1.Finalresult();
}
HOME TASK 2:
#include<iostream>
#include<string>
using namespace std;
class Simple
{
protected:
float num1,num2;
float
addition,subtraction,multiplication,division;
public:
float getdata(){
cout <<"\nEnter Numumber 1: ";
cin >> num1;

cout <<"\nEnter Number 2: ";


cin >> num2;
}
float add()
{
addition=num1+num2;
return addition;
}
float sub()
{
subtraction=num1-num2;
return subtraction;
}
float mul()
{
multiplication=num1*num2;
return multiplication;
}
float div()
{
division=num1/num2;
return division;
}
};
int main()
{
Simple S;
S.getdata();
cout<<"\nAddition = "<<S.add();
cout<<"\nSubtraction = "<<S.sub();
cout<<"\nMultiplication = "<<S.mul();
cout<<"\nDivision = "<<S.div();
}
HOMETASK 3:
#include<iostream>
#include<conio.h>
using namespace std;
class electricity
{
char name[20];
int unit;
float Rs;
public:
void get(){
cout<<"\nEnter the Name & Units of Electricity
user: \n";
cin>>name>>unit;
}
void check(){
if(unit<=100)
{
Rs=unit*0.50;
}
else if(unit >100)
{
Rs=unit*0.60;
}
}
void disp(){
if(Rs>=250)
{
Rs=Rs+0.15;
}
cout<<name<<" \t"<<Rs<<endl;
}
};
int main(){
int n,i;
electricity e[10];
cout<<"\nHow many electricity User: \n";
cin>>n;
for(i=0;i<n;i++){
e[i].get();
e[i].check();
}
cout<<"\nElectricity Users: \n";
cout<<"\nName\t\t Total cost(Rs)\n";
cout<<"================================
=\n";
for(i=0;i<n;i++){
e[i].disp();
}
getch();
}

You might also like