Question: I need help to separate this code by classes, article class and user class #include I need help separating this code by classes, item class

I need help to separate this code by classes, article class and user class
#include
I need help separating this code by classes, item class and user class.
#include
#include
#include
#include "user.h"
#include "article.h"
using the standard namespace;
int main(){
fstream file;
string user, pass;
string fuser, fpass;
vectorcart;
inner band =0;
file.open("user.txt");
if (!file.is_open()){
cout << "Error opening file" << endl;
return 1;
}
cout << "User: ";
cin >> user;
cout << "Password: ";
cin >> pass;
while (!file.eof()){
file >> fuser >> fpass;
if (fuser == user && fpass == pass){
band =1;
break;
}
}
file.close();
if (band ==1){
item obj1("Paper",50);
item obj2("Feather",20);
item obj3("Laptop",100);
item obj4("Pencil",10);
item obj5("Draft",5);
vector items ={obj1, obj2, obj3, obj4, obj5};
internal choice;
do{
cout <<"--- Welcome to my online store ---"<> election;
change (choice){
Case 1:{
int subselection;
cout << "How would you like to consult the articles?
";
cout <<"1. Prices below a certain quantity.
";
cout <<"2. Prices above a certain quantity
";
cout <<"3. Name
";
cout << "Enter your choice: ";
cin >> subselection;
int pricelimit;
string itemName;
change(suboption){
Case 1:
case 2:
cout << "Enter price limit: ";
cin >> price limit;
break;
case 3:
cout << "Enter the element name: ";
cin >> itemname;
break;
}
cout << "Available elements:
";
for (int i =0; i < items.size(); i++){
bool display = false;
if (subchoice ==1 && items[i].getPrice() priceLimit) display = true;
if (subchoice ==3 && items[i].getName()== item name) display = true;
if (show){
cout << i +1<<"."<< items[i].getName()<<"- Price: $"<< items[i].getPrice()<< endl;
}
}
charad;
cout <<"Do you want to add an item to your cart? (Y/N): ";
cin >> add;
if (add =='Y'){
int itemNumber, quantity;
cout << "Enter item number: ";
cin >> item number;
cout << "How many pieces?";
cin >> quantity;
items[itemNum -1].setQuantity(quantity);
cart.push_back(items[itemNum -1]);
cout << "Item added to cart.
";
}
continuous chain;
cout <<"Do you want to exit to the main menu or continue adding items? (Menu/Add): ";
cin >> cont;
while (cont == "Add"){
int itemNumber, quantity;
cout << "Enter item number: ";
cin >> item number;
cout << "How many pieces?";
cin >> quantity;
items[itemNum -1].setQuantity(quantity);
cart.push_back(items[itemNum -1]);
cout << "Item added to cart.
";
cout <<"Do you want to exit to the main menu or continue adding items? (Menu/Add): ";
cin >> cont;
}
break;
}
case 2:{
cout << "Your cart:
";
total integer =0;
for (int i =0; i < cart.size(); i++){
cout << i +1<<"."<< cart[i].getName()<<"- Price: $"<< cart[i].getPrice()<<"- Quantity: "<< cart[ i].getQuantity()<< endl;
total += cart[i].getPrice()* cart[i].getQuantity();
}
cout << "Total to pay: $"<< total << endl;
string buyOrCont;
cout <<"Do you want to finish or continue shopping? (Finish/Buy): ";
cin >> buyOrCont;
if (buyOrCont == "Finish"){
cout << "Press Ok to close the sale..
";
string Ok;
cin >> Ok;
if (Okay == "Okay"){
cout << "Sale successfully closed. Thank you for shopping with us!
";
cart.clear();
}
}
break;
}
case 3:
cout << "Leaving...
";
break;
default:
cout << "Invalid choice. Please enter again.
";
break;
}
}
while (choice !=3);}
the rest{
cout << "Invalid username or password. Please try again.
";
}
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!