Part 1 – Person class Write a Person class that tracks subscribers to a library,
ID: 3590424 • Letter: P
Question
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 • Edit attributes of an existing Person Part 2 - Book Class Write a Book class 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 Homework 3 Page 2 Extend your main program of part 1 with these capabilities: • Create test data for six books • display all books in library, along with name of borrower (if any) • enable people to check books in and out Challenge 1 1) Change the borrower member variable to a pointer to a Person object. 2) The library has multiple copies of each book. 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.
c++ PROGRAM. PLEASE DO NOT USE DATA STRUTURE BECAUSE I USE CPP.SH TO RUN PROGRAMS.THKS
Explanation / Answer
code
Person1.cpp:
#ifndef PERSON_H
#define PERSON_H
#include <iostream>
using namespace std;
class Person
{
string fullName;
int identifier;
string email;
public:
Person()
{
fullName = "";
identifier = 0;
email = "";
}
Person(string name, int id, string mail)
{
fullName = name;
identifier = id;
email = mail;
}
void setFullName(string name) { fullName = name; }
void setIdentifier(int id) { identifier = id; }
void setEmail(string mail) { email = mail; }
string getFullName() { return fullName; }
int getIdentifier() { return identifier; }
string getEmail() { return email; }
};
#endif
Book.cpp :
#ifndef BOOK_H
#define BOOK_H
class Book
{
string title;
string author;
bool status; //To check if book is checked out.
Person borrower; //Person who borrowed the book.
public:
Book(string ttl, string athr, bool stts, Person brwr)
{
title = ttl;
author = athr;
status = stts;
borrower = brwr;
}
/*Person getBorrower()
{
return borrower;
}*/
void setBorrower(Person brwr)
{
borrower = brwr;
}
void checkOut(Person brwr)
{
if(!status)
setBorrower(brwr);
}
void checkIn()
{
status = false;
}
string getTitle() { return title; }
string getAuthor() { return author; }
bool getStatus() { return status; }
string getBorrower()
{
string temp = "Name : " + borrower.getFullName();
temp += " ID : " + to_string(borrower.getIdentifier());
temp += " Email: " + borrower.getEmail();
return temp;
}
};
#endif
Person1BookTest.cpp:
#include <iostream>
#include "Person1.cpp"
#include "Book.cpp"
using namespace std;
int main()
{
Person person1 ("John Girisham", 123, "johngirisham@hotmail.com");
Person person2 ("Donald Trumph", 234, "donaldtrumph@whitehouse.com");
Person person3("Saddam Hussain", 345, "saddamhussain@ggmmail.com");
Person person4("Indira Gandhi", 456, "indiragandhi@yahoo.co.in");
cout << "Name : " << person1.getFullName() << endl;
cout << "ID : " << person1.getIdentifier() << endl;
cout << "Email: " << person1.getEmail() << endl << endl;
cout << "Name : " << person2.getFullName() << endl;
cout << "ID : " << person2.getIdentifier() << endl;
cout << "Email: " << person2.getEmail() << endl << endl;
cout << "Name : " << person3.getFullName() << endl;
cout << "ID : " << person3.getIdentifier() << endl;
cout << "Email: " << person3.getEmail() << endl << endl;
cout << "Name : " << person4.getFullName() << endl;
cout << "ID : " << person4.getIdentifier() << endl;
cout << "Email: " << person4.getEmail() << endl << endl;
person1.setFullName("Barack Obama");
person1.setIdentifier(567);
person1.setEmail("barackobama@publichealth.com");
cout << "Name : " << person1.getFullName() << endl;
cout << "ID : " << person1.getIdentifier() << endl;
cout << "Email: " << person1.getEmail() << endl << endl;
Book book1("Programming in C", "Dennis Ritchie", true, person1);
cout << "Title: " << book1.getTitle() << endl;
cout << "Author: " << book1.getAuthor() << endl;
if(book1.getStatus())
cout << "Borrower Details: "<< endl << book1.getBorrower() << endl << endl;
Book book2("Macbeth", "William Shakespear", false, person1);
cout << "Title: " << book2.getTitle() << endl;
cout << "Author: " << book2.getAuthor() << endl;
if(book2.getStatus())
cout << "Borrower Details: "<< endl << book2.getBorrower() << endl << endl;
Book book3("First Love", "Sachin Garg", true, person2);
cout << endl << "Title: " << book3.getTitle() << endl;
cout << "Author: " << book3.getAuthor() << endl;
if(book3.getStatus())
cout << "Borrower Details: "<< endl << book3.getBorrower() << endl;
}
IF ANY QUERIES REGARDING CODE PLEASE GET BACK TO ME
THANK YOU