Question
Create a Flowshart for the Following c++ Program. #include #include #include #include #include #include using namespace std; //structure to save products available on store struct
Create a Flowshart for the Following c++ Program.
#include
#include
#include
#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("product.txt"); if(!ifile.is_open()) { cout<<" Product not Available !"; return 0; } string line,data; while(getline(ifile,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< cout<<" ************************************************** "; cout<<"* * "; cout<<"* Welcome to online shopping * "; cout<<"* * "; cout<<"*************************************************** "; while(1) { cout<<" 1.View Products 2.Buy Product 3.View Cart 0.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< cout<<"\t"< } break; case 2: cout<<" Enter product id : "; cin>>id; found=findProductId(products,productCount,id); if(found>0) { cout<<" Enter Quantity : "; cin>>quantity; int quantt=findProductQuantity(products,productCount,id); while(quantity>quantt) { cout<<" Quanity available : "< cin>>quantity; } 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 !"; } else { cout<<" Product not found with id : "< } break; case 3: cout<<" Items in Cart "; cout<<" ID\tItem Name \t Description\tprice\tQuantity\tTotal Price "; for(int i=0;i { cout< cout<<"\t"< } cout<<" 1.CheckOut 2.Continue Sopping"; cin>>option; switch(option) { case 1: cout<<" (Get $5.00 off)Do you Have Reward card (y/n) :"; cin>>reward; cout<<" (Get extra 20% off )Would like to payment through store's Credit Card (y/n)"; cin>>creditCard; cout<<" ***********Payament Slip********* "; totalPrice=0; for(int i=0;i { cout< cout<<"\t"< totalPrice=totalPrice+myCart[i].price*myCart[i].quantity; } cout<<" Total Cost : "< saving=0; if(reward=='y'|| reward=='Y') saving=5; if(creditCard=='y'|| creditCard=='Y') saving=saving+totalPrice*.2; cout<<" You Saved : "< totalPrice-=saving; cout<<" stat Tax (10.5%) : "< cout<<" Muncipal Tax(1%) : "< finalCost=totalPrice+totalPrice*.105+totalPrice*.01; cout<<" Final Cost : "< cout<<" *****Happy Shopping******** "; break; case 2: break; } case 0: return 0; default : cout<<" Invalid option"; break; } } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started