C++ programming C++ programming C++ programming Homework 3 Page 2 Homework 3-Lib
ID: 3590413 • Letter: C
Question
C++ programming
C++ programming
C++ programming
Homework 3 Page 2 Homework 3-Library Application Extend your main program of part 1 with these capabilities: Due Wednesday, October 11, at the beginning of class. Hand in hard copy of your code and be prepared to run your program. Develop your program as follows - Create test data for six books . display all books in library, along with name of borrower (if any) eenable people to check books in and out * Code and debug part 1 before you begin part 2. * The main program and each class definition must be in separate files . Hard code your test data in the program, so that you do not have to enter data when Challenge (optional-1 bonus point) you run the program. Track the number of copies of each book, and track one borrower for each copy, Do not allow a person to check out a book if all copies are already checked out. Part 1- Person class Write a Person class that tracks subscribers to a library, with these member attributes: . full name identifier (numeric) . email address Person has these member functions * Constructor-initializes new object . get and set function for each attribute Write a main program with these capabilities: * Create test data for four people .Display all people eEdit attributes of an existing Person Part 2 Book Class Write a Book dass that tracks all books in a library, with these member attributes * title author status-indicates if Book is checked out borrower-the Person object that has currently checked out book, if any Book has these member functions: * Constructor-initializes new object * get and set function for borrower member variable checkout-enables person to check out Book . do not allow if book is checked out . checkin enables Person to check in BookExplanation / Answer
public class Person
{
public:
string fullName;
int id;
string email;
Person(string name, int ID, string em) {
this. setFullName(name);
this.setID(ID);
this.setEmail(em);
}
string getFullName(){ return this.fullName; }
void setFullName(string name){ this.fullName = name; }
int getID(){ return this.id; }
void setID(int iden){ this.id = iden; }
string getEmail(){ return this.email; }
void setEmail(string eadd){ this.email = eadd; }
void display(){
cout<<”Name: ”<<this.fullName<<”ID: ”<<this.id<<”Email: ”<<this.email<<endl;
}
}
public class Book
{
public:
string title,author;
bool status=true;
Person p;
Book(string titl, string auth, bool st) {
this.setTitle(titl);
this.setAuthor(auth);
this. setStatus(st);
}
void setTitle(string titl){ this.title = titl; }
string getTitle() { return this.title; }
void setAuthor(string auth){ this.author = auth; }
string getAuthor() { return this.author; }
void setStatus(bool st){ this.status = st; }
bool getStatus(){ return this .status; }
void setPerson(Person per) {
if(this.status == false)
{ this.p = per;
this.setStatus(true); // book is borrowed, change the status to true
cout<<”Book successfully borrowed by ”<<p.fullName<<endl;
}
else{
cout<<”This book is already borrowed in the name of ”<<p.fullName<<endl;
}
}
void returnBook(Person p){
if(this.status == true){
this.p = NULL;
this.setStatus(false);
cout<<”This book is returned successfully”<<endl;
}
else {
cout<<”This book is not borrowed by anybody”<<endl;
}
}
Person getPerson(){ return this.p; }
Void display(){
if(this.status == true)
{
Cout<<”Title: ”<< this.title<<”Author: ”<<this.author<<”Borrowed: Yes”<< “Name : ”<<p.fullName<<”ID: ”<<p.id<<”Email: ”<<p.email<<endl;
}
else
{
Cout<<”Title: ”<< this.title<<”Author: ”<<this.author<<”Borrowed: No<<endl;
}
}
}
void main() {
Person p1(“abc”,1,”abc@xx.com”),p2(“xyz”,2,”xyz@xx.com”),p3(“pqr”,3,”pqr@xx.com”),p4(“aaa”,4,”aaa@xx.com”);
// display all people
p1.display();
p2.display();
p3.display();
p4.display();
// edit attribute of an existing person
p4.fullName = “bbb”; // or p4.setFullName(“bbb”)
Books b1(“aaa”,”John”,false),b2(“bbb”,”Mark”,false),b3(“ccc”,”David”,false),b4(“ddd”,”Marry”,false),b5(“eee”,”Lane”,false),b6(“fff”,”Rio”,false);
//display books
b1.display();
b2.display();
b3.display();
b4.display();
b5.display();
b6.display();
// enable borrowing
b1.setPerson(p1);
// returning borrowed book
b1.returnBook(p1);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.