C++ General Description: You will write a program in C++ that uses a class bookT
ID: 3839624 • Letter: C
Question
C++
General Description: You will write a program in C++ that uses a class bookType, which will hold specific information about a book, and various functions to be performed on a book. You will define an array to hold 5 books and read in the information about the books from a data file called bookInfo.txt. The program will then ask the user to search for a book based on some of the info (Tile or Author or …) and display the information about the book if it is in the list.
Details:
A bookType will store the following information about a book:
Title
Author
ISBN
Price
Number of copies in stock
The operations that should be performed on a bookType are:
Show the different pieces of information (i.e. Title, author, etc.)
Set the different pieces of information
Check if a title is an actual title of a book, author is an actual author, etc.
The class must have a default constructor that sets the member variables to a default value
The class definition MUST be in a file called bookType.h, and the class function definitions must be in a file called bookTypeimp.cpp.
You must have internal documentation.
You must email me your code (all three files)
Explanation / Answer
Hi,
I could write below code that covers all the functionalities that is mentioned here in the given time. It does not cover all the functionalies you need but it can be used as a base.
#include <iostream>
using namespace std;
class bookType{
string title;
string author;
string ISBN;
double price;
int no_of_copies;
public :
void settitle(string);
void setauthor(string);
void setISBN(string);
void setprice(double);
void setno_of_copies(int);
string gettitle();
string getauthor();
string setISBN();
double setprice();
int setno_of_copies();
void showdata();
string titlesearch(string);
};
void bookType::settitle(string a){
title=a;
}
void bookType::setauthor(string b){
author=b;
}
void bookType::setISBN(string c){
ISBN=b;
}
void bookType::setprice(double d){
price=c;
}
void bookType::setno_of_copies(int d){
no_of_copies=d;
}
string bookType::gettitle(){
return title;
}
long bookType::getauthor(){
return author;
}
int bookType::getISBN(){
return ISBN;
}
int bookType::getprice(){
return price;
}
int bookType::getno_of_copies(){
return no_of_copies;
}
void bookType::showdata(){
cout<<"Title : "<<title;
cout<<"Authot:"<<author;
cout<<"ISBN:"<<ISBN;
cout<<"Price"<<price;
cout<<"Number of copies"<<no_of_copies;
}
string bookType::titlesearch(string s){
if(title==s){
cout<<" Book has been found";
cout<<" Below are the details";
cout<<showdata();
else {
cout<<"Invalid book title";
}
}
}
int main()
{
bookType s1[5];
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.