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

Oop Lab 3

The document is a lab journal from a computer science course that contains 3 tasks completed by a student. Task 1 involves creating a Book class with data members and functions, and a menu-driven program to input data for 5 books. Task 2 creates a Student class with data members and functions to input data for an array of 10 students, calculate percentages, and display the lowest scoring student. Task 3 creates a PersonAge class to input a name and date of birth, calculate age using constants, and display the results.

Uploaded by

qfq
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)
146 views

Oop Lab 3

The document is a lab journal from a computer science course that contains 3 tasks completed by a student. Task 1 involves creating a Book class with data members and functions, and a menu-driven program to input data for 5 books. Task 2 creates a Student class with data members and functions to input data for an array of 10 students, calculate percentages, and display the lowest scoring student. Task 3 creates a PersonAge class to input a name and date of birth, calculate age using constants, and display the results.

Uploaded by

qfq
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/ 6

Bahria University, Lahore Campus

Department of Computer Science


Lab Journal 04
(Spring 2020)

Course: Object Oriented Programming - Lab Date: _5-03-2020__


Course Code: CSL-210 Max Marks: 10
Faculty’s Name: Ms. Zupash Awais

Name: _USAMA ADNAN__ Enroll No: 03-134192-057_____ Class: _2B__

Objective(s):
Upon completion of this lab session, learners will be able to:
 Array of Objects
 Const Members

Lab Tasks:
Task 1:
Define a Class BOOK with the following specifications:
Data Members:
bookNo
bookTitle
price
Member Functions:
total_cost( ) A function to calculate the total cost for N no of copies where N is
passed to function as argument.
take_data( ) A function to input bookNo, bookTitle, price.
purchase_info( ) A function to ask the user to input the number of copies to be
purchased of a book. It invokes total_cost( ) and prints the total
cost paid by the user.
Write a menu driven program. Get data for five book from user.

Task 1:
#include<iostream>
#include<string>
using namespace std;

class book{
public:
int n,price;
string tittle;

void showdata()
{cout << "Book Tittle : " << tittle << endl;
cout << "Book Price : " << price << endl;
cout << "Book Id : " << n << endl;
}
void getdata()
{ cout << "Enter Book Tittle : "; cin >> tittle;
cout << "Enter Book Price : "; cin >> price;
cout << "Enter Book # : "; cin >> n;
%
Enrollment Number: ____________________________

};

int main(){
book a[5];
int ch, op, op2;
do
{cout << "1)-Admin" << endl;
cout << "2)-User" << endl;
cout << "3)-Exit" << endl;
cin >> ch;
if (ch == 1){
cout << "1)-Enter books Data" << endl;
cout << "2)-Display books Data" << endl;
cin >> op;
if (op == 1){
for (int i = 0; i <5; i++)
{ a[i].getdata();}
}
if (op == 2){
for (int i = 0; i < 5; i++)
{ a[i].showdata();}}}
else if (ch == 2){
cout << "1:-Purchase Book" << endl;
cout << "1:-Display Book Data" << endl;
cin >> op2;
if (op2 == 1){
int b, y, total;
int p = 1;
cout << "Enter the book id" << endl;
cin >> b;
for (int i = 0; i < 5; i++)
if (b == a[i].n){
cout << "Book Price is :" << a[i].price;
cout << "Mentioned copies you want to buy ?"; cin
>> y; cout << endl;
p = (a[i].price)*y;
}
cout << "Total price is " << p << endl;
}
else if (op2 == 2){
for (int i = 0; i < 5; i++)
{
a[i].showdata();
}
}
}

} while (ch>0 && ch<3);

system("pause");

return 0;

Page 2 of 6
%
Enrollment Number: ____________________________

Task 2:
Write a program with a class that contains following data members
 Id
 name
 marks
Create and array of objects of size 10. Create a function read() to take input from user. Create
a function to calculate percentage of each student. Then create a function that displays the
student id and name of the student with the lowest percentage.

Task 2:

#include<iostream>
#include<string>
using namespace std;

class student{

int id, marks;


string name;
double per;
public:

student()
{
id = 0;
marks = 0;

name = "no-name";

void read()
{

cout << "Enter id :";


cin >> id; cout << endl;
cout << "Enter Name :";
cin >> name; cout << endl;
cout << "Enter marks out of 500 :" ;
cin >> marks;

void percentage()
{
double total = 500;
Page 3 of 6
%
Enrollment Number: ____________________________

per = (marks * 100) / total;

double percheck()
{
return per;
}

};

int main()
{

student a[3];
for (int i = 0; i < 3; i++)
{
a[i].read();
a[i].percentage();

double lp = a[0].percheck();
for (int i = 0; i < 3; i++)
{
if (lp>a[i].percheck())
{
lp = a[i].percheck();
}
}

cout << lp;

system("pause");

return 0;
}

Task3:
Create a class personAge with following data members: name, dob, age. Calculate age by
taking name and dob as input from user. Make appropriate constant functions and variables.

Page 4 of 6
%
Enrollment Number: ____________________________

Task 3:

#include<iostream>
#include<string>
using namespace std;

class personAge
{
string age;
string name;
int yr,mn,dy,ageyr,agemn,agedy;

public:

personAge()
{

void takeage()
{
cout << "Enter Name :";
getline(cin, name);
cout << "Enter Date of Birth .....Enter year of birth :";
cin >> yr;
cout << "Enter month of birth in integer:";
cin >> mn;
cout << "Enter day of birth :";
cin >> dy;
ageyr = 2020 - yr;
agemn = 12 - mn;
agedy = 31 - dy;

void agee()const
{
cout << name;

cout << "age is :" << agedy << "-" << agemn << "-" << ageyr << endl;

};

int main()
{

personAge a;
a.takeage();
a.agee();

return 0;
Page 5 of 6
%
Enrollment Number: ____________________________

Lab Grading Sheet :


Max
Obtained
Task Mark Comments(if any)
Marks
s
1. 05
2. 2.5
3. 2.5
Total 10 Signature

Note : Attempt all tasks and get them checked by your Lab Instructor.

Page 6 of 6

You might also like