Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Programming C++ Programming C++ Programming C++ Programming Homework 3 Page

ID: 3590412 • Letter: C

Question

C++ Programming

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 Book

Explanation / Answer

//person.h file

#ifndef PERSON_H

#define PERSON_H

#include<iostream.h>

#include<string.h>

using namespace std;

class Person{

string name;

int id;

string email;

public:

Person(void){

}

Person(int p_id,string p_name,string p_email){

name=p_name;

id=p_id;

email=p_email;

}

void setName(string p_name){

name=p_name;

}

void setId(int p_id){

id=p_id;

}

void setEmail(string p_email){

email=p_email;

}

string getName(void){

return name;

}

int getId(void){

return id;

}

string getEmail(void){

return email;

}

};

#endif

//end of person.h file

//book.h file

#ifndef BOOK_H
#define BOOK_H
#include<iostream.h>
#include<string.h>
using namespace std;
class Book{
string title;
string author;
bool status; // checked out : true, checked in: false
public:
Person borrower;
  
Book(void){
  
}
Book(string b_title,string b_author){
title=b_title;
author=b_author;
status=false; //by default, not checked in
}
void setBorrower(Person p){
borrower=p;
  
}
Person getBorrower(){
return borrower;
  
}
void checkIn(){
status=false;
cout<<" "<<borrower.getName()<<" Checked in the book '"<<getTitle()<<"'

successfully ";
}
void checkOut(Person b){
if(status==true){ //already checked out
cout<<"ERROR, already checked out by "<<borrower.getName()<<endl;
}else{
setBorrower(b);
status=true;
cout<<borrower.getName()<<" checked out the book '"<<getTitle()<<"'

successfully"<<endl;
}
}
string getTitle(){
return title;
}
string getAuthor(){
return author;
}
  
  
};

#endif

//end of book.h file

//mainprogram.cpp

#include<iostream.h>
#include<string.h>
#include "person.h"
#include "book.h"
int main(){
//part1 starts
Person person[4];
person[0].setId(1);
person[0].setName("Alice");
person[0].setEmail("Alice@mail.com");

person[1].setId(2);
person[1].setName("Bob");
person[1].setEmail("Bob@mail.com");

person[2].setId(3);
person[2].setName("Cullen");
person[2].setEmail("Cullen@mail.com");

person[3].setId(4);
person[3].setName("Dave");
person[3].setEmail("Dave@mail.com");

for(int i=0;i<4;i++){
cout<<"Person:"<<i+1;
cout<<" ID: "<<person[i].getId();
cout<<" Name: "<<person[i].getName();
cout<<" Email: "<<person[i].getEmail();
cout<<" ";
}
person[3].setId(5); //editing attributes of an existing person
person[3].setName("David"); //editing attributes of an existing person
//part1 ends
//part2 starts
Book books[6]={Book("Dreams","Joseph"),Book("Lost in Love","Amanda"),Book

("Hello","Adele"),Book("Kingdom of heaven","Christopher"),Book("Dead

souls","Nega"),Book("Dawn","Surya")};
books[0].checkOut(person[0]);

books[1].checkOut(person[1]);

books[2].checkOut(person[2]);

books[4].checkOut(person[3]);

for(int i=0;i<6;i++){
cout<<"Bookname: "<<books[i].getTitle()<<endl;
cout<<"Author: "<<books[i].getAuthor()<<endl;
cout<<"Borrower: "<<books[i].getBorrower().getName()<<endl;
cout<<"_______"<<endl;
}
books[0].checkOut(person[1]); //Bob trying to check out book[0] which is already

checked out by Alice; will display error
books[0].checkIn(); //Alice checked in
books[0].checkOut(person[1]); //Now Bob can check out

//end of part2
return 0;
}

//end of mainprogram.cpp

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote