Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Pseudocode for the following C++ program #include //input & output #include // string library #include #include #include using namespace std; //structure to save

Create a Pseudocode for the following C++ program

#include//input & output

#include // string library

#include

#include

#include

using namespace std;

//structure to save products available on store

struct Product

{

int id;

string name;

int price;

string description;

int quantity;

};

int findProductId(Product products[], int count, int id)

{

for (int i = 0;i

{

if (products[i].id == id)

return id;

}

return -1;

}

string findProductName(Product products[], int count, int id)

{

for (int i = 0;i

{

if (products[i].id == id)

return products[i].name;

}

}

string findProductDescription(Product products[], int count, int id)

{

for (int i = 0;i

{

if (products[i].id == id)

return products[i].description;

}

}

int findProductPrice(Product products[], int count, int id)

{

for (int i = 0;i

{

if (products[i].id == id)

return products[i].price;

}

}

int findProductQuantity(Product products[], int count, int id)

{

for (int i = 0;i

{

if (products[i].id == id)

return products[i].quantity;

}

}

int main()

{

Product products[20];

Product myCart[20];

int id, quantity, found;

double saving, totalPrice, finalCost;

char reward, creditCard;

int productCount = 0, cartCount = 0;

int option;

ifstream ifile;

ifile.open("Inventory.txt"); //file containing the inventory

if (!ifile.is_open())

{

cout << " Product not Available !";

system("pause");

return 0;

}

string line, data;

while (getline(ifile, line)) // read in file the inventory separated by comma in line

{

istringstream read(line);

getline(read, data, ',');

products[productCount].id = atoi(data.c_str());

getline(read, data, ',');

products[productCount].name = data;

getline(read, data, ',');

products[productCount].description = data;

getline(read, data, ',');

products[productCount].price = atoi(data.c_str());

getline(read, data, ',');

products[productCount].quantity = atoi(data.c_str());

productCount++;

}

cout<<"Product in Inventory: " <

cout << " ************************************************** ";

cout << "* * ";

cout << "* Turabo Engineering Tennis Center * ";

cout << "* * ";

cout << "*************************************************** ";

while (1)

{

//Menu

cout << " 1.Inventory;";

cout << " 2.Select Merchandise";

cout << " 3.Shopping Cart 0:";

cout << "Exit";

cout << " Select a option : ";

cin >> option;

switch (option)

{

case 1:

cout << " ID\tItem Name \t Description \tprice\tQuantity ";

for (int i = 0;i

{

cout << products[i].id << "\t" << products[i].name << "\t " << products[i].description << "\t$" << products[i].price;

cout << "\t" << products[i].quantity << "\t" << endl;

}

break;

case 2: //look for product id

cout << " Enter product id : ";

cin >> id;

found = findProductId(products, productCount, id);

if (found>0) //product id has to be gratter than 0

{

cout << " Enter Quantity : ";

cin >> quantity;

int quantt = findProductQuantity(products, productCount, id);

while (quantity>quantt)

{

cout << " Quanity available : " << quantt << " Please Enter valid Quantity : "; //if quantity asked is greatter than the inventory diplay a error message

cin >> quantity;

} //adding product the shopping cart

myCart[cartCount].id = id;

myCart[cartCount].name = findProductName(products, productCount, id);

myCart[cartCount].description = findProductDescription(products, productCount, id);

myCart[cartCount].price = findProductPrice(products, productCount, id);

myCart[cartCount].quantity = quantity;

cartCount++;

cout << " Item has been added to card successfully !" << endl;

}

else

{

cout << " Product not found with id : " << id << endl; // if id is not in the inventory list

}

break;

case 3: //Shopping Cart

cout << " Items in Cart " << endl;

cout << " ID\tItem Name \t Description\tprice\tQuantity\tTotal Price " << endl;

for (int i = 0;i

{

cout << myCart[i].id << "\t" << myCart[i].name << "\t" << myCart[i].description << "\t$" << myCart[i].price;

cout << "\t" << myCart[i].quantity << "\t\t$" << myCart[i].price*myCart[i].quantity << endl;

}

cout << " 1.Checkout " << endl;

cout << "2.Continue Shopping" << endl;

cin >> option;

switch (option)

{

case 1: //Reward Card & Discount

cout << " (Get $5.00 off)Do you Have Reward card (y/n) :" << endl;

cin >> reward;

cout << " (Get extra 20% off )Would like to payment through store's Credit Card (y/n)" << endl;

cin >> creditCard;

cout << " ***********Customer Receipt********* ";

totalPrice = 0; //total price reset to 0

for (int i = 0;i

{

cout << myCart[i].id << "\t" << myCart[i].name << "\t" << myCart[i].description << "\t$" << myCart[i].price;

cout << "\t" << myCart[i].quantity << "\t$" << myCart[i].price*myCart[i].quantity << endl;

totalPrice = totalPrice + myCart[i].price*myCart[i].quantity;

}

cout << " Total Cost : $" << totalPrice;

//discount Menu

saving = 0;// reset saving to 0

if (reward == 'y' || reward == 'Y')

saving = 5;

if (creditCard == 'y' || creditCard == 'Y')

saving = saving + totalPrice*.2;

cout << " You Saved : $" << saving;

totalPrice -= saving;

//Tax Calculator

cout << " stat Tax (10.5%) : $" << totalPrice*.105;

cout << " Muncipal Tax(1%) : $" << totalPrice*.01;

finalCost = totalPrice + totalPrice*.105 + totalPrice*.01; //Total Cost

cout << " Final Cost : $" << finalCost;

cout << " *****Thank you for Shopping******** ";

cout << " ******** Come Back Soon! ********** ";

break;

system("pause");

case 2:

break;

}

case 0:

system("pause"); //Pause system for no automatic close

return 0;

default: cout << " Invalid option"; // if any option selected is invalid

break;

}

}

system("pause");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is a media or data search?

Answered: 1 week ago

Question

What are four primary sources of law in the United States?

Answered: 1 week ago

Question

What is an interface? What keyword is used to define one?

Answered: 1 week ago