SlideShare a Scribd company logo
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

LAB 2 Report.docx
LAB 2 Report.docxLAB 2 Report.docx
LAB 2 Report.docx
AhamedMusharaf1
 
Ch03
Ch03Ch03
Ch03
ojac wdaj
 
Ch03
Ch03Ch03
Lokesh 's Ip project Pokemon information
Lokesh 's Ip project Pokemon informationLokesh 's Ip project Pokemon information
Lokesh 's Ip project Pokemon information
bholu803201
 
Virtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.pptVirtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.ppt
ishan743441
 
c++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfc++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdf
ayush616992
 
Ex
ExEx
Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2
Kaela Johnson
 
Plsql task
Plsql taskPlsql task
Plsql task
Nawaz Sk
 
web technology practicals.pdf
web technology practicals.pdfweb technology practicals.pdf
web technology practicals.pdf
NaveenK242465
 
web technology practicals.pdf
web technology practicals.pdfweb technology practicals.pdf
web technology practicals.pdf
NaveenK242465
 
Online examination
Online examinationOnline examination
Online examination
Astha Patel
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Kamal Acharya
 
C++ practical
C++ practicalC++ practical
C++ practical
Rahul juneja
 
Object Oriented Programming using C++: Ch06 Objects and Classes.pptx
Object Oriented Programming using C++: Ch06 Objects and Classes.pptxObject Oriented Programming using C++: Ch06 Objects and Classes.pptx
Object Oriented Programming using C++: Ch06 Objects and Classes.pptx
RashidFaridChishti
 
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptxCONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
DeepasCSE
 
Salesforce, APEX Concepts
Salesforce, APEX ConceptsSalesforce, APEX Concepts
Salesforce, APEX Concepts
Gaurish Goel
 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
Naveen Sagayaselvaraj
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
Prabhu 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 Melayi
Muhammed Thanveer M
 

Similar to Report-Template.docx (20)

LAB 2 Report.docx
LAB 2 Report.docxLAB 2 Report.docx
LAB 2 Report.docx
 
Ch03
Ch03Ch03
Ch03
 
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
 
Object Oriented Programming using C++: Ch06 Objects and Classes.pptx
Object Oriented Programming using C++: Ch06 Objects and Classes.pptxObject Oriented Programming using C++: Ch06 Objects and Classes.pptx
Object Oriented Programming using C++: Ch06 Objects and Classes.pptx
 
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
 

Recently uploaded

Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfSri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Balvir Singh
 
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
DharmaBanothu
 
Assistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdfAssistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdf
Seetal Daas
 
This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...
DharmaBanothu
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
uqyfuc
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
Paris Salesforce Developer Group
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
nedcocy
 
Ericsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.pptEricsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.ppt
wafawafa52
 
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls ChennaiCall Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
paraasingh12 #V08
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
Kamal Acharya
 
Presentation on Food Delivery Systems
Presentation on Food Delivery SystemsPresentation on Food Delivery Systems
Presentation on Food Delivery Systems
Abdullah Al Noman
 
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptxEV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
nikshimanasa
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
ijseajournal
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
VANDANAMOHANGOUDA
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
Kamal Acharya
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
vmspraneeth
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
b0754201
 
FULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back EndFULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back End
PreethaV16
 

Recently uploaded (20)

Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfSri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
 
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
 
Assistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdfAssistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdf
 
This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
 
Ericsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.pptEricsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.ppt
 
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls ChennaiCall Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
 
Presentation on Food Delivery Systems
Presentation on Food Delivery SystemsPresentation on Food Delivery Systems
Presentation on Food Delivery Systems
 
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptxEV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
 
FULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back EndFULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back End
 

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