0% found this document useful (0 votes)
6 views15 pages

OOP Lab 8

The document outlines a lab assignment for CS-211 focusing on Object Oriented Programming. It involves creating a Book class and a Writer class, along with a List class to manage multiple writers and their books. The program includes functionalities to display writer information, find books by title, and identify the writer with the most books.

Uploaded by

maniniazi909
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)
6 views15 pages

OOP Lab 8

The document outlines a lab assignment for CS-211 focusing on Object Oriented Programming. It involves creating a Book class and a Writer class, along with a List class to manage multiple writers and their books. The program includes functionalities to display writer information, find books by title, and identify the writer with the most books.

Uploaded by

maniniazi909
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/ 15

Lab 8

CS-211
Object Oriented Programming

Submitted to : Ma’am Shaista Rashid


Submitted by: Momina Waheed Kiani (003085)
Eman Amir Niazi(02777)
Aman Nazir(004710)

International Islamic University Islamabad


Faculty of Computing
Department of Software Engineering
Write a Book class that contains the attributes Book ID, book title and price. It also

contains member functions to input and show its attributes.

Write another class writer that contains the attributes writer name and NoOfBooks. It

contains an array of book objects as its member. The length of the array should be 3 to

store the data of 3 books. It also contains member functions to input and display its attributes.

List class will store information of 6 writers.

Provide menu options to provide following functionality

- Display information of all the writers

- Find book by title

- Display information of writer who has written maximum number of books

- Exit
CODE:
book.h:

#pragma once

#include <string>

using namespace std;

class book {

int id;

string title;

float price;

public:

void get();

void display();

string telltitle() {

return title;

};
book.cpp:

#include<iostream>

#include<string>

#include"book.h"

using namespace std;

void book::get()

cout<<"Enter id: \n";

cin>>id;

cout<<"Enter title:\n ";

cin>>title;

cout<<"Enter price: \n";

cin>>price;

void book::display()

cout<<"id: "<<id<<endl;

cout<<"title: "<<title<<endl;

cout<<"price: "<<price<<endl;

}
writer.h:

#pragma once

#include<string>

#include"book.h"

class writer

{
string name;

int noofbooks;

book b[3];

public:

void get();

void display();

bool findbook(string s1);

int tellnoofbooks()

return noofbooks;

};
List.h:
#include "writer.h"

class list

writer w[6];

public:

void displayinfo();

void getinfo();

void maxbooks();

void findbooks();

};

writer.cpp:

#include<iostream>

#include<string>
#include"writer.h"

using namespace std;

void writer::get()

cout<<"enter name of writer\n";

cin>>name;

cout<<"enter no of books\n";

cin>>noofbooks;

for(int i=0;i<=2&&i<noofbooks;i++)

cout<<"enter details of the book:"<<i+1<<endl;

b[i].get();

void writer::display()

cout<<"writer name:"<<name<<"no. of books"<<noofbooks<<endl;

for(int i=0;i<=2&&i<noofbooks;i++)

cout<<"book"<<i+1<<"details"<<endl;

b[i].display();

bool writer::findbook(string s1)

for(int i=0;i<=2&&i<noofbooks;i++)
{

if(s1==b[i].telltitle())

b[i].display();

return true;

return false;

}
list.h:
#pragma once

#include "writer.h"

class list

writer w[6];

public:

void displayinfo();

void getinfo();

void maxbooks();

void findbooks();

};
list.cpp:
#include<iostream>

#include<string>

#include "list.h"

#include "writer.h"

using namespace std;

void list::getinfo()
{

for(int i=0; i<=5;i++)

w[i].get();

void list::displayinfo()

for(int i=0; i<=5;i++)

w[i].display();

void list::maxbooks()

int max = w[0].tellnoofbooks();

int index=0;

for ( int i = 1; i <=5; i++)

if(max<w[i].tellnoofbooks())

max = w[i].tellnoofbooks();

index=i;

w[index].display();

}
}

void list::findbooks()

bool found= false;

string s;

cout<<"Enter the title of the book you want to find: ";

cin>>s;

for(int i=0; i<=5&&found==false;i++)

found=true;

w[i].display();

if (found==false)

cout<<"Book not found";

}
main.cpp:

#include<iostream>

#include"book.h"

#include"writer.h"

#include"list.h"

using namespace std;

int main()

list l;
int ch;

cout<<"Enter detail of 6 writers:\n";

l.getinfo();

do

cout<<"1:Display information of all the writers\n";

cout<<"2:Find book by title\n";

cout<<"3:Display information of writer who has written maximum number of books\n";

cout<<"4:Exit\n";

cout<<"Enter choice"<<endl;

cin>>ch;

if(ch==1)

l.displayinfo();

else if(ch==2)

l.findbooks();

else if(ch==3)

l.maxbooks();

else if(ch==4)

{
cout<<"Exiting";

else

cout<<"Invalid choice";

} while (ch!=4);

return 0;

}
OUTPUT:-

You might also like