I should be able to read the current totals and add additional inventory to text file for case 1.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

C++ I'm having problems with this code. I need to read the text file and add the total inventory for case 2 and to list inventory total by make/model for case 3. It runs but doesnt provide results. I should be able to read the current totals and add additional inventory to text file for case 1.

book.txt

make

pearsons

model

galaxies

price

200.00

inventory

20

make

pearsons

model

islands

price

299.99

inventory

10

*************************************************************

 

#include

#include

 

using namespace std;

class Book

{

private:

string make, model;

float price;

int inventory;

public:

Book();

Book(string mk, string md, float p, int i);

void setMake(string mk)

{

make = mk;

}

string getMake()

{

return make;

}

void setModel(string md)

{

model = md;

}

string getModel()

{

return model;

}

void setPrice(float p)

{

price = p;

}

float getPrice()

{

return price;

}

void setInventory(int i)

{

inventory = i;

}

int getInventory()

{

return inventory;

}

};

Book::Book()

{

make = "Generic";

model = "Basic";

price = 500.00;

inventory= 0;

}

Book::Book(string mc, string md, float p, int i)

{

make = mc;

model = md;

price = p;

inventory = i;

}

int main()

{

int menu;

Book b[10];//declaring book array

int index=0;//to keep track total number of books

string make, model;

float price;

int inventory;

 

while(true){

cout << "\n Menu:\n";

cout << " 1. Add Inventory\n";

cout << " 2. Inventory total\n";

cout << " 3. Inventory by make/model \n";

cout << " 0. Exit\n";

cout << "\n > ";

cin >> menu;

switch (menu)

{

case 1:

//taking book information from user

cin.ignore();

cout<<"\nenter make : ";

getline(cin,make);

cout<<"\nenter model : ";

getline(cin,model);

cout<<"\nenter price : ";

cin>>price;

b[index]=Book(make,model,price,index+1);

index++;

cout<

break;

case 2:

//display all the content of book array

cout<<"\nTotal Inventory: "<

cout<

cout<

for(int i=0;i<=index-1;i++)

cout<

 

cout<

break;

case 3:

cin.ignore();

cout<<"\nenter make to search : ";

getline(cin,make);//taking make from user

for(int i=0;i<=index-1;i++){//looping over book array

if(b[i].getMake()==make){//if make found

cout<

cout<

cout<

}

 

}

cout<

break;

case 0:

exit(0);

default:

cout << "\n Select a valid number [Between 0 and 3]\n";

}

}

}

 

When selecting 2, I need it to add the values (inventory) 20+10 =30 and return results. When selecting 3, show availble inventory by make and model.
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY