NEW Programming Assignment C++

#pragma once #include "InventoryItem.h" #ifndef BOOK_H #define BOOK_H class Book : public InventoryItem { private:

std::string title; std::string author; std::string publisher; public:

Book(); Book(std::string, std::string, std::string, std::string, int, double); std::string getTitle(); std::string getAuthor(); std::string getPublisher(); void setTitle(std::string); void setAuthor(std::string); void setPublisher(std::string); void display(); void read(std::ifstream &); }; #endif // !BOOK_H /////////////// #pragma once #include #include #include #ifndef INVENTORYITEM_H #define INVENTORYITEM_H class InventoryItem { private:

std::string description; int quantityOnHand; double price; public:

InventoryItem(); InventoryItem(std::string, int, double); std::string getDescription(); int getQuantityOnHand(); double getPrice(); void read(std::ifstream &); void display(InventoryItem); void setDescription(std::string); void setQuantityOnHand(int); void setPrice(double); }; #endif // !INVENTORYITEM_H ////////////////// #include "InventoryItem.h" InventoryItem::InventoryItem() { description = "none"; quantityOnHand = 0; price = 0; } InventoryItem::InventoryItem(std::string name, int number, double num) { description = name; quantityOnHand = number; price = num; } void InventoryItem::read(std::ifstream &myfile) { char h; if (myfile.is_open()) { getline(myfile, description, ','); setDescription(description); myfile >> quantityOnHand; setQuantityOnHand(quantityOnHand); myfile >> h; myfile >> price; setPrice(price); myfile.ignore(100, '\n'); } } std::string InventoryItem::getDescription() { return description; } int InventoryItem::getQuantityOnHand() { return quantityOnHand; } double InventoryItem::getPrice() { return price; } void InventoryItem::display(InventoryItem item) { std::cout << item.getDescription() << std::endl; std::cout << item.getQuantityOnHand() << std::endl; std::cout << item.getPrice() << std::endl; } void InventoryItem::setDescription(std::string d) { description = d; } void InventoryItem::setQuantityOnHand(int num) { if (num >= 0) quantityOnHand = num; else quantityOnHand = 0; } void InventoryItem::setPrice(double num) { price = num; } /////////////////// #include "Book.h" Book::Book() { title = "none"; author = "none"; publisher = "none"; } Book::Book(std::string t, std::string a, std::string p, std::string name, int number, double num) :InventoryItem(name, number, num) { title = t; author = a; publisher = p; } std::string Book::getTitle() { return title; } std::string Book::getAuthor() { return author; } std::string Book::getPublisher() { return publisher; } void Book::setTitle(std::string ti) { title = ti; } void Book::setAuthor(std::string au) { author = au; } void Book::setPublisher(std::string pu) { publisher = pu; } void Book::display() { std::cout << getDescription() << std::endl; std::cout << getQuantityOnHand() << std::endl; std::cout << getPrice() << std::endl; std::cout << title << " " << author << " " << publisher << std::endl << std::endl; } void Book::read(std::ifstream &inFile) { char h; std::string line; int num; double x; if (inFile.is_open()) { getline(inFile, line, ','); setDescription(line); inFile >> num; setQuantityOnHand(num); inFile >> h; inFile >> x; setPrice(x); getline(inFile, std::string(), ' '); getline(inFile, title, ','); setTitle(title); getline(inFile, author, ','); setAuthor(author); getline(inFile, publisher); setPublisher(publisher); } } //////////////////// #include "InventoryItem.h" #include "Book.h" #include #include #include using namespace std; int main() { ifstream file("data.txt"); //Assume the name of input file is data.cs if (!file) { cerr <<"Can't open file "<< "data.csv"< bookList; Book temp; while (file) { temp.read(file); bookList.push_back(temp); } for (int i = 0; i < bookList.size()-1; ++i) bookList[i].display(); system("pause"); return 0; } ////////////////// Iphone 6, 33, 599.00, The Hunger Games, Suzanne Collins, Scholastic Corporation Samsung Galaxy s6, 21, 439.50, The Maze Runner, James Dashner, Unknown