C ++ program test data for 2 book, 2 Mp3, 2 video Homework 4 – Library Applicati
ID: 3596631 • Letter: C
Question
C ++ program
test data for 2 book, 2 Mp3, 2 video
Homework 4 – Library Application with Music and Video
Due Wednesday, October 25, at the beginning of class. Hand in hard copy of your code and be
prepared to run your program. Develop your program as follows:
• Complete part 1 before you begin part 2.
• The main program and each class definition must be in separate files.
• Hard code test data in the program. Do not enter test data when you run the program.
• Use functions to break your main program into components
• Add a comment at the beginning of all classes and functions to describe behavior.
Part 1 – Publication Class
In your solution to homework 3, rename Book to Publication wherever it appears. Test your
program to ensure it works properly.
Part 2 – Book, Music, and Video classes
Add a new Book class, as well as Music and Video classes. All three classes are derived from the
Publication class. Add these member variables:
Book class:
• pages
• format (hardcover, softcover, digital)
Music class:
• duration (seconds)
• format (MP3, AAV, WAV)
Video class:
• resolution (low, high, 4K)
• producer
All three classes should have constructors, get, and set functions.
Extend your main program to edit and display Publication and Person data, using this menu:
1) Display people
2) Display publications
3) Edit people
4) Edit publications
5) Check out publication
6) Check in publication
7) Quit
homework 3 code
/*
* This is the part two of the library Application.
* Homework 3 Part two
* File: main.cpp
* Author: sushil Man Singh Karki
* Date: 10/15/2017
*/
#include<iostream>
#include<string>
#include "person.h"
#include "books.h"
int main() {
//part1 starts
// Class person is created with the object that is structured in array of four test people with the member attribute id, name, and email.
// Creates a test data for four people with name, id and email address.
Person person[4];
person[0].setId(1);
person[0].setName("Pukar Rai");
person[0].setEmail("pukar_01@mail.com");
person[1].setId(2);
person[1].setName("Sarin Maskey");
person[1].setEmail("sain_01@mail.com");
person[2].setId(3);
person[2].setName("Puspa Subedi");
person[2].setEmail("puspa_01@mail.com");
person[3].setId(4);
person[3].setName("Anjan Karki");
person[3].setEmail("Anjan_01@mail.com");
// Here for loop is designed in order to iterate the loop for the 4 times so that the information of four people is displayed.
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("Puspa Subedi"); //editing attributes of an existing person
//part1 ends
//part2 starts
// Initialization of Object of class book which is stored in array of six elements with a book author and title.
// Code below created a test data for six books with their borrower name and validates the book is checkedIN or out.
Book books[6] = { Book("The Notebook","Nicholas Sparks"),Book("Maha Ko Ma","Madan Krishna Shrestha"),Book
("Half girlfriend","Chetan Bhagat"),Book("The last song","Nicholas sparks"),Book("Lean In ","Sheryl Sandberg"),Book("General Theory of Relativity","Albert Einstein")};
books[0].checkOut(person[0]);
books[1].checkOut(person[1]);
books[2].checkOut(person[2]);
books[4].checkOut(person[3]);
// Initialization of for loop which iterate for six times dispalaying bookname, author and status of book.
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]); //sarin trying to check out book[0] which is already
//checked out pukar by ; will display error
books[0].checkIn(); //pukar checked in
books[0].checkOut(person[1]); //Now sarin can check out
//end of part2
system("pause");
return 0;
}
//end of mainprogram.cpp
Explanation / Answer
person.hpp
/*
* the file contains the information about the
* declerations of class Person type
*/
#ifndef __PERSON_HPP__
#define __PERSON_HPP__
class Person
{
private:
int mId;
std::string mName;
std::string mEmail;
public:
Person();
~Person();
void setId(int id);
void setName(std::string name);
void setEmail(std::string email);
int getId();
std::string getName();
std::string getEmail();
};
#endif
person.cpp
/*
* the file contains the information about the
* definations of class Person type
*/
#include "Person.hpp"
Person::Person()
{
mId = 0;
mName = "";
mEmail = "";
}
Person::~Person(){}
void Person::setId(int id)
{
mId = id;
}
void Person::setName(std::string name)
{
mName = name;
}
void Person::setEmail(std::string email)
{
mEmail = email;
}
int Person::getId()
{
return mId;
}
std::string Person::getName()
{
return mName;
}
std::string Person::getEmail()
{
return mEmail;
}
Book.hpp
/*
* the file contains the information about the
* declerations of class Book type
*/
#ifndef __BOOK_HPP__
#define __BOOK_HPP__
class Book:public Publication
{
private:
std::string mName;
std::string mAuthor;
long mPages;
std::string mFormat;
bool mCheck;
Person mPerson;
public:
Book();
Book(std::string name, std::string mAuthor);
~Book();
void setPages(long pages);
void setFormat(std::string format);
long getPages();
std::string getFormat();
void checkIn();
void checkOut(Person person);
};
#endif
Book.cpp
/*
* the file contains the information about the
* definations of class Book type
*/
#include "Book.hpp"
#include "Person.hpp"
#include <iostream>
Book::Book()
{
mName = "";
mAuthor = "";
mPages = 0;
mFormat = "";
mCheck = false;
mPerson = nullptr;
}
Book::Book(std::string name, std::string author)
{
mName = name;
mAuthor = author;
}
Book::~Book(){}
void Book::setPages(long pages)
{
mPages = pages;
}
void Book::setFormat(std::string format)
{
mFormat = format;
}
long Book::getPages()
{
return mPages;
}
std::string Book::getFormat()
{
return mFormat;
}
void Book::checkIn()
{
mPerson = nullptr;
}
void Book::checkOut(Person person)
{
if (mCheck == false)
{
mPerson = person;
mCheck = true;
}
else
{
std::cout << "The Boook " << mName << "is not available. ";
}
}
Music.hpp
/*
* the file contains the information about the
* declerations of class Book type
*/
#ifndef __MUSIC_HPP__
#define __MUSIC_HPP__
class Music:public Publication
{
private:
int mDuration;
std::string mFormat;
public:
Music();
~Music();
void setDuration(long duration);
void setFormat(std::string format);
long getDuration();
std::string getFormat();
};
#endif
Music.cpp
/*
* the file contains the information about the
* definations of class Music type
*/
#include "Music.hpp"
Music::Music()
{
mDuration = 0;
mFormat = "";
}
Music::~Music(){}
void Music::setDuration(long duration)
{
mDuration = duration;
}
void Music::setFormat(std::string format)
{
mFormat = format;
}
long Music::getDuration()
{
return mDuration;
}
std::string Music::getFormat()
{
return mFormat;
}
Video.hpp
/*
* the file contains the information about the
* declerations of class Video type
*/
#ifndef __VIDEO_HPP__
#define __VIDEO_HPP__
class Video:public Publication
{
private:
std::string mResolution;
std::string mProducer;
public:
Video();
~Video();
void setResolution(std::string resolution);
void setProducer(std::string producer);
std::string getResolution();
std::string getProducer();
};
#endif
Video.cpp
/*
* the file contains the information about the
* definations of class Video type
*/
#include "Video.hpp"
Video::Video()
{
mResolution = "";
mProducer = "";
}
Video::~Video(){}
void Video::setResolution(std::string resolution)
{
mResolution = resolution;
}
void Video::setProducer(std::string producer)
{
mProducer = producer;
}
std::string Video::getResolution()
{
return mResolution;
}
std::string Video::getProducer()
{
return mProducer;
}
main.cpp
-----------------------------
#include "Person.hpp"
#include "Publication.hpp"
#include "Book.hpp"
#include "Music.hpp"
#include "Video.hpp"
int main()
{
int choice;
Person person[4];
Publication books[6];
person[0].setId(1);
person[0].setName("Pukar Rai");
person[0].setEmail("pukar_01@mail.com");
person[1].setId(2);
person[1].setName("Sarin Maskey");
person[1].setEmail("sain_01@mail.com");
person[2].setId(3);
person[2].setName("Puspa Subedi");
person[2].setEmail("puspa_01@mail.com");
person[3].setId(4);
person[3].setName("Anjan Karki");
person[3].setEmail("Anjan_01@mail.com");
std :: cout << "Enter yout choice : "
std :: cout << "1.Display People";
std :: cout << "2.Display Publications";
std :: cout << "3.Edit People";
std :: cout << "4.Edit Publications";
std :: cout << "5 Check out Publication";
std :: cout << "6. Check in Publication";
std :: cout << "7.Quit";
std :: cin >> choice;
switch( choice ){
case 1 : 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 << " ";
} break;
case 2 : 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;
}
break;
case 3: person[3].setId(5);
person[3].setName("Puspa Subedi");
break;
case 4: books[6] = { Book("The Notebook","Nicholas Sparks"),Book("Maha Ko Ma","Madan Krishna Shrestha"),Book
("Half girlfriend","Chetan Bhagat"),Book("The last song","Nicholas sparks"),Book("Lean In ","Sheryl Sandberg"),Book("General Theory of Relativity","Albert Einstein")};
break;
case 5: books[0].checkOut(person[0]);
books[1].checkOut(person[1]);
books[2].checkOut(person[2]);
books[4].checkOut(person[3]);
books[0].checkOut(person[1]);
books[0].checkOut(person[1]);
break;
case 6: books[0].checkIn();
break;
case 7: return 0;
break;
}
return 0;
}
/* hope this helps */
/* if any queries please comment */
/* thank you */
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.