SlideShare a Scribd company logo
1 of 9
AIR UNIVERSITY
DEPARTMENT OF MECHATRONICS ENGINEERING
EXPERIMENT NO 2
Lab Title Introduction to classes
Student Name: Hammad Iftikhar Hanif
Reg. No: 201080
LAB ASSESSMENT:
Attributes
Excellent
(5)
Good
(4)
Average
(3)
Satisfactory
(2)
Unsatisfactory
(1)
Ability to Conduct
Experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows
the lab safety rules
Total Marks: Obtained Marks:
LAB REPORT ASSESSMENT:
Attributes
Excellent
(5)
Good
(4)
Average
(3)
Satisfactory
(2)
Unsatisfactory
(1)
Data presentation
Experimental results
Conclusion
Total Marks: Obtained Marks:
BEMTS-III Functionsand Structures
2
Date: Signature:
Department of Mechatronics Engineering
Data Structure and Object Oriented Programming Lab
Lab Report: 2
Introdroduction to Classes
Name: Hammad Iftikhar
Roll Number: 201080
Class: BEMTS-3A
Submitted To: Engr. M. Farooq Khan
Date: 30 September, 2021
Air University,Islamabad DS and OOP Lab
3
Lab Tasks
Q1.Create a class Book with three data members BookID, Pages and Price.
It also contains the following member functions:
• The get() function is used to input values (1st object)
• The show() function is used to display values
• The set() function is used to set the values of data members using parameters (2nd object)
• The getPrice() function is used to return the value of Price
The program should create two objects of the class and input values tor these objects. The
program displays the details of the most costly book.
#include <iostream>
using namespace std;
class textbooks
{
private:
int BookID,Paisay,NoOfPages;
public:
void get();
void show();
void set(int a,int b,int c);
int getPaisay();
};
int main()
{
double x,y;
textbooks bookA,bookB;
bookA.get();
bookA.show();
bookB.set(300,900,1500);
x=bookA.getPaisay();
y=bookB.getPaisay();
if(x>y)
{
cout<<"BookA is expensive.";
}
void textbooks::get()
{cout<<"Enter BookID: ";
cin>>BookID;
cout<<"Enter number of Pages : ";
cin>>NoOfPages;
cout<<endl<<"Enter Price of Book : ";
cin>>Paisay;
system("cls");
}
void textbooks::show()
{cout<<"BookID is:"<<BookID<<endl;
cout<<"No of Pages of book are:
"<<NoOfPages<<endl;
cout<<"Price of book
is:"<<Paisay<<endl;
}
void textbooks::set(int a,int b,int c)
{BookID=a;
Paisay=b;
NoOfPages=c;
}
int textbooks::getPaisay()
{
return Paisay;
}
BEMTS-III Functionsand Structures
4
else if(y>x)
{
cout<<"BookB is expensive.";
}
else{
cout<<"Both textbooks are of
same Price.";
}
return 0;
}
Q2) Create a class Student_Result that contains roll number, name, and marks of CP, OOP,
and DS. The class also contains the following member functions:
• The input() function is used to input the values in data members
• The show() function is used to displays the value of data members •
The total() function returns the total marks of a student.
• The avg() function returns the average marks of a student.
Create 2 instances of a class.One for Ali and other for Hassan. Get data for both Ali and Hassan,
display it. Calculate total marks and average for both the students and compare the results.
#include<iostream>
using namespace std;
class result
{
private:
void result::input()
{
cout<<"Name :"<<endl;
cin>>name;
cout<<"Reg ID :"<<endl;
cin>>reg;
cout<<"CP marks :"<<endl;
cin>>cp;
Air University,Islamabad DS and OOP Lab
5
string name;
int reg;
float cp,oop,ds;
public:
void input();
float show();
int total();
int average();
};
int main()
{
int a,b,c,d,e,f;
result studentA,studentB;
studentA.input();
studentB.input();
a=studentA.show();
b=studentA.total();
c=studentA.average();
d=studentB.show();
e=studentB.total();
f=studentB.average();
cout<<endl;
cout<<endl;
if(studentA.average()>studentB.av
erage())
cout<<"Student 1
performed better. "<<endl;
else
cout<<"Student 2 performed
better. "<<endl;
return 0;
}
cout<<"oop marks :"<<endl;
cin>>oop;
cout<<"DS marks :"<<endl;
cin>>ds;
system("cls");
}
float result::show()
{
cout<<"Student :
"<<name<<endl;
cout<<"Reg ID :
"<<reg<<endl<<endl;
cout<<"Marks scored
:"<<endl<<endl;
cout<<"CP : "<<cp<<endl;
cout<<"OOP :
"<<oop<<endl;
cout<<"DS :
"<<ds<<endl<<endl;
}
int result::total()
{
int Total;
Total=cp+oop+ds;
return Total;
}
int result::average()
{
int avg;
avg=(cp+oop+ds)/3;
cout << "Average=
"<<avg<<endl;
return avg;
}
BEMTS-III Functionsand Structures
6
Q3) Create a class called BankAccount that models a checking account at a bank. The program
creates an account with an opening balance, displays the balance, makes a deposit and a
withdrawal, and then displays the new balance.
#include <iostream>
#include <string>
using namespace std;
class bankacc
{
private:
string accname;
double b,d,wd;
void bankacc::show()
{
b=93748;
cout<<"Account Name =
"<<endl<<accname<<endl;
cout<<"Initial balance =
"<<b<<endl;
cout << "Amount deposited=
"<<d<<endl;
cout << "Amount withdrawn=
"<<wd<<endl;
Air University,Islamabad DS and OOP Lab
7
public:
void get();
void show();
};
int main()
{
bankacc b;
b.get();
b.show();
return0;
}
void bankacc::get()
{
cout<<"Enter Account
Name:";
cin>>accname;
cout<<endl<<"Enter the
amount to deposit :";
cin>>d;
cout<<endl<<"Enter the
amount to withdraw : ";
cin>>wd;
}
cout << "Current balance =
"<<b+d-wd<<endl;
}
BEMTS-III Functionsand Structures
8
Q4)
Create a class Rectangle. The class has attributes length and width. Provide methods that
calculate the perimeter and the area of the rectangle. Provide set and get methods for both
length and width. The set methods should verify that length and width are each floating point
number greater than or equal to 0.0 and less than 20.0. Write a program to test class
Rectangle.
#include<iostream>
using namespace std;
class r
{
private:
double a;
double l;
double w;
double p;
public:
void get();
void show();
void r::get()
{
cout<<"Enter lengthof
rectangle :";
cin>>l;
cout<< "Enter Widthof
rectangle :";
cin>> w;
}
void r::show()
{
a=l*w;
cout<<"Areaof rectangle is =
"<<a<<endl;
p=(l+w)*2;
Air University,Islamabad DS and OOP Lab
9
};
int main()
{
r Rect;
Rect.get();
cout << endl << "Your Answers are
: " << endl;
Rect.show();
return0;
}
cout<<"Perimeter of rectangle
is = "<<p<<endl;
}

More Related Content

Similar to Report-Template.docx

Lokesh 's Ip project Pokemon information
Lokesh 's Ip project Pokemon informationLokesh 's Ip project Pokemon information
Lokesh 's Ip project Pokemon informationbholu803201
 
Virtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.pptVirtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.pptishan743441
 
c++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfc++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfayush616992
 
Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2Kaela Johnson
 
Plsql task
Plsql taskPlsql task
Plsql taskNawaz Sk
 
web technology practicals.pdf
web technology practicals.pdfweb technology practicals.pdf
web technology practicals.pdfNaveenK242465
 
web technology practicals.pdf
web technology practicals.pdfweb technology practicals.pdf
web technology practicals.pdfNaveenK242465
 
Online examination
Online examinationOnline examination
Online examinationAstha Patel
 
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptxCONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptxDeepasCSE
 
Salesforce, APEX Concepts
Salesforce, APEX ConceptsSalesforce, APEX Concepts
Salesforce, APEX ConceptsGaurish Goel
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALPrabhu D
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiMuhammed Thanveer M
 
ASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code firstASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code firstMd. Aftab Uddin Kajal
 
Term 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdfTerm 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdfKiranKumari204016
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201rohassanie
 

Similar to Report-Template.docx (20)

Ch03
Ch03Ch03
Ch03
 
Lokesh 's Ip project Pokemon information
Lokesh 's Ip project Pokemon informationLokesh 's Ip project Pokemon information
Lokesh 's Ip project Pokemon information
 
Virtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.pptVirtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.ppt
 
c++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfc++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdf
 
Ex
ExEx
Ex
 
Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2
 
Plsql task
Plsql taskPlsql task
Plsql task
 
web technology practicals.pdf
web technology practicals.pdfweb technology practicals.pdf
web technology practicals.pdf
 
web technology practicals.pdf
web technology practicals.pdfweb technology practicals.pdf
web technology practicals.pdf
 
Online examination
Online examinationOnline examination
Online examination
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
C++ practical
C++ practicalC++ practical
C++ practical
 
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptxCONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
 
Salesforce, APEX Concepts
Salesforce, APEX ConceptsSalesforce, APEX Concepts
Salesforce, APEX Concepts
 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
ASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code firstASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code first
 
Term 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdfTerm 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdf
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201
 

Recently uploaded

S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksMagic Marks
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersMairaAshraf6
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...HenryBriggs2
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 

Recently uploaded (20)

S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 

Report-Template.docx

  • 1. AIR UNIVERSITY DEPARTMENT OF MECHATRONICS ENGINEERING EXPERIMENT NO 2 Lab Title Introduction to classes Student Name: Hammad Iftikhar Hanif Reg. No: 201080 LAB ASSESSMENT: Attributes Excellent (5) Good (4) Average (3) Satisfactory (2) Unsatisfactory (1) Ability to Conduct Experiment Ability to assimilate the results Effective use of lab equipment and follows the lab safety rules Total Marks: Obtained Marks: LAB REPORT ASSESSMENT: Attributes Excellent (5) Good (4) Average (3) Satisfactory (2) Unsatisfactory (1) Data presentation Experimental results Conclusion Total Marks: Obtained Marks:
  • 2. BEMTS-III Functionsand Structures 2 Date: Signature: Department of Mechatronics Engineering Data Structure and Object Oriented Programming Lab Lab Report: 2 Introdroduction to Classes Name: Hammad Iftikhar Roll Number: 201080 Class: BEMTS-3A Submitted To: Engr. M. Farooq Khan Date: 30 September, 2021
  • 3. Air University,Islamabad DS and OOP Lab 3 Lab Tasks Q1.Create a class Book with three data members BookID, Pages and Price. It also contains the following member functions: • The get() function is used to input values (1st object) • The show() function is used to display values • The set() function is used to set the values of data members using parameters (2nd object) • The getPrice() function is used to return the value of Price The program should create two objects of the class and input values tor these objects. The program displays the details of the most costly book. #include <iostream> using namespace std; class textbooks { private: int BookID,Paisay,NoOfPages; public: void get(); void show(); void set(int a,int b,int c); int getPaisay(); }; int main() { double x,y; textbooks bookA,bookB; bookA.get(); bookA.show(); bookB.set(300,900,1500); x=bookA.getPaisay(); y=bookB.getPaisay(); if(x>y) { cout<<"BookA is expensive."; } void textbooks::get() {cout<<"Enter BookID: "; cin>>BookID; cout<<"Enter number of Pages : "; cin>>NoOfPages; cout<<endl<<"Enter Price of Book : "; cin>>Paisay; system("cls"); } void textbooks::show() {cout<<"BookID is:"<<BookID<<endl; cout<<"No of Pages of book are: "<<NoOfPages<<endl; cout<<"Price of book is:"<<Paisay<<endl; } void textbooks::set(int a,int b,int c) {BookID=a; Paisay=b; NoOfPages=c; } int textbooks::getPaisay() { return Paisay; }
  • 4. BEMTS-III Functionsand Structures 4 else if(y>x) { cout<<"BookB is expensive."; } else{ cout<<"Both textbooks are of same Price."; } return 0; } Q2) Create a class Student_Result that contains roll number, name, and marks of CP, OOP, and DS. The class also contains the following member functions: • The input() function is used to input the values in data members • The show() function is used to displays the value of data members • The total() function returns the total marks of a student. • The avg() function returns the average marks of a student. Create 2 instances of a class.One for Ali and other for Hassan. Get data for both Ali and Hassan, display it. Calculate total marks and average for both the students and compare the results. #include<iostream> using namespace std; class result { private: void result::input() { cout<<"Name :"<<endl; cin>>name; cout<<"Reg ID :"<<endl; cin>>reg; cout<<"CP marks :"<<endl; cin>>cp;
  • 5. Air University,Islamabad DS and OOP Lab 5 string name; int reg; float cp,oop,ds; public: void input(); float show(); int total(); int average(); }; int main() { int a,b,c,d,e,f; result studentA,studentB; studentA.input(); studentB.input(); a=studentA.show(); b=studentA.total(); c=studentA.average(); d=studentB.show(); e=studentB.total(); f=studentB.average(); cout<<endl; cout<<endl; if(studentA.average()>studentB.av erage()) cout<<"Student 1 performed better. "<<endl; else cout<<"Student 2 performed better. "<<endl; return 0; } cout<<"oop marks :"<<endl; cin>>oop; cout<<"DS marks :"<<endl; cin>>ds; system("cls"); } float result::show() { cout<<"Student : "<<name<<endl; cout<<"Reg ID : "<<reg<<endl<<endl; cout<<"Marks scored :"<<endl<<endl; cout<<"CP : "<<cp<<endl; cout<<"OOP : "<<oop<<endl; cout<<"DS : "<<ds<<endl<<endl; } int result::total() { int Total; Total=cp+oop+ds; return Total; } int result::average() { int avg; avg=(cp+oop+ds)/3; cout << "Average= "<<avg<<endl; return avg; }
  • 6. BEMTS-III Functionsand Structures 6 Q3) Create a class called BankAccount that models a checking account at a bank. The program creates an account with an opening balance, displays the balance, makes a deposit and a withdrawal, and then displays the new balance. #include <iostream> #include <string> using namespace std; class bankacc { private: string accname; double b,d,wd; void bankacc::show() { b=93748; cout<<"Account Name = "<<endl<<accname<<endl; cout<<"Initial balance = "<<b<<endl; cout << "Amount deposited= "<<d<<endl; cout << "Amount withdrawn= "<<wd<<endl;
  • 7. Air University,Islamabad DS and OOP Lab 7 public: void get(); void show(); }; int main() { bankacc b; b.get(); b.show(); return0; } void bankacc::get() { cout<<"Enter Account Name:"; cin>>accname; cout<<endl<<"Enter the amount to deposit :"; cin>>d; cout<<endl<<"Enter the amount to withdraw : "; cin>>wd; } cout << "Current balance = "<<b+d-wd<<endl; }
  • 8. BEMTS-III Functionsand Structures 8 Q4) Create a class Rectangle. The class has attributes length and width. Provide methods that calculate the perimeter and the area of the rectangle. Provide set and get methods for both length and width. The set methods should verify that length and width are each floating point number greater than or equal to 0.0 and less than 20.0. Write a program to test class Rectangle. #include<iostream> using namespace std; class r { private: double a; double l; double w; double p; public: void get(); void show(); void r::get() { cout<<"Enter lengthof rectangle :"; cin>>l; cout<< "Enter Widthof rectangle :"; cin>> w; } void r::show() { a=l*w; cout<<"Areaof rectangle is = "<<a<<endl; p=(l+w)*2;
  • 9. Air University,Islamabad DS and OOP Lab 9 }; int main() { r Rect; Rect.get(); cout << endl << "Your Answers are : " << endl; Rect.show(); return0; } cout<<"Perimeter of rectangle is = "<<p<<endl; }