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