//main.cpp #include "Person.h" #include "Seller.h" #include "Powerseller.h" #include #include #include #include using namespace std; void printMenu(); void printSellers(list sellers); void checkSeller(list sellers); void addSeller(list sellers); void deleteSeller(list &sellers); int main() { list sellers; ifstream infile; infile.open("sellers.dat"); if (!infile) { cerr << "File could not be opened." << endl; exit(1); } char type; while (!infile.eof()) { infile >> type; if (type == 'S') { Seller* newseller = new Seller; newseller -> read(infile); sellers.push_back(newseller); } if (type == 'P') { Powerseller* newpowerseller = new Powerseller; newpowerseller -> read(infile); sellers.push_back(newpowerseller); } } infile.close(); bool done = false; int choice; while (!done) { printMenu(); cin >> choice; switch (choice) { case 1: printSellers(sellers); break; case 2: checkSeller(sellers); break; case 3: addSeller(sellers); break; case 4: deleteSeller(sellers); break; case 5: done = true; break; } } return 0; } void printMenu() { cout << endl; cout << "Menu" << endl; cout << "1. Print information of all sellers" << endl; cout << "2. Check information of a particular seller" << endl; cout << "3. Add a seller to the list" << endl; cout << "4. Remove a seller from the list" << endl; cout << "5. Quit" << endl; cout << "Enter your choice: "; } void printSellers(list sellers) { for (list::iterator i = sellers.begin(); i != sellers.end(); i++) { (*i)->print(); } } void checkSeller(list sellers) { string fname, lname; cout << "Enter the seller's first name: " ; cin >> fname; cout << "Enter the seller's last name: " ; cin >> lname; bool found = false; for (list::iterator i = sellers.begin(); i != sellers.end(); i++) { if ((*i)->getFirstName() == fname && (*i)->getLastName() == lname) { found = true; cout << "\n" << endl; (*i)->print(); } } if (!found) { cout << "Seller not found." << endl; } } void addSeller(list sellers) { string fname, lname, info, web, em, id; int sold, item; float rating; cout << "Please enter the following information (enter invalid type to quit): " << "\n"; cout << "Is the seller a (S)eller or (P)ower Seller? "; cin >> info; if (info == "S") { cout << "first name: " << endl; cin >> fname; cout << "last name: " << endl; cin >> lname; cout << "User ID: " << endl; cin >> id; cout << "Email Address: " << endl; cin >> em; //Email Address: cout << "Average Star Rating: " << endl; cin >> rating; cout << "Total Items sold: " << endl; cin >> item; cout << "The new Power Seller has been added. Returning to Seller Management..." << endl; Seller* newseller = new Seller; newseller -> read(cin); sellers.push_back(newseller); } if (info == "P") { cout << "first name: " << endl; cin >> fname; cout << "last name: " << endl; cin >> lname; cout << "User ID: " << endl; cin >> id; cout << "Email Address:" << endl; cin >> em; //Email Address: cout << "Average Star Rating: " << endl; cin >> rating; cout << "Total Items sold: " << endl; cin >> item; cout << "Website Address: " << endl; cin >> web; cout << "Current year products Sold: " << endl; cin >> sold; Powerseller* newpowerseller = new Powerseller; newpowerseller -> read(cin); sellers.push_back(newpowerseller); //for (list::iterator i = sellers.begin(); i != sellers.end(); i++) //{ //Powerseller* newpowerseller = new Powerseller; //newpowerseller -> read(cin); //sellers.push_back(newpowerseller); //break; //} } } void deleteSeller(list &sellers) { string fname, lname; cout << "Enter the seller's first name: "; cin >> fname; cout << "Enter the seller's last name: "; cin >> lname; bool found = false; for (list::iterator i = sellers.begin(); i != sellers.end(); i++) { if ((*i)->getFirstName() == fname && (*i)->getLastName() == lname) { found = true; sellers.erase(i); break; } } if (!found) { cout << "Seller not found." << endl; } } My add function doesn't return to the menu. Can you help me out?
//main.cpp
#include "Person.h"
#include "Seller.h"
#include "Powerseller.h"
#include <iostream>
#include <list>
#include <fstream>
#include <string>
using namespace std;
void printMenu();
void printSellers(list<Seller*> sellers);
void checkSeller(list<Seller*> sellers);
void addSeller(list<Seller*> sellers);
void deleteSeller(list<Seller*> &sellers);
int main() {
list<Seller*> sellers;
ifstream infile;
infile.open("sellers.dat");
if (!infile) {
cerr << "File could not be opened." << endl;
exit(1);
}
char type;
while (!infile.eof())
{
infile >> type;
if (type == 'S')
{
Seller* newseller = new Seller;
newseller -> read(infile);
sellers.push_back(newseller);
}
if (type == 'P')
{
Powerseller* newpowerseller = new Powerseller;
newpowerseller -> read(infile);
sellers.push_back(newpowerseller);
}
}
infile.close();
bool done = false;
int choice;
while (!done) {
printMenu();
cin >> choice;
switch (choice) {
case 1:
printSellers(sellers);
break;
case 2:
checkSeller(sellers);
break;
case 3:
addSeller(sellers);
break;
case 4:
deleteSeller(sellers);
break;
case 5:
done = true;
break;
}
}
return 0;
}
void printMenu() {
cout << endl;
cout << "Menu" << endl;
cout << "1. Print information of all sellers" << endl;
cout << "2. Check information of a particular seller" << endl;
cout << "3. Add a seller to the list" << endl;
cout << "4. Remove a seller from the list" << endl;
cout << "5. Quit" << endl;
cout << "Enter your choice: ";
}
void printSellers(list<Seller*> sellers) {
for (list<Seller*>::iterator i = sellers.begin(); i != sellers.end(); i++)
{
(*i)->print();
}
}
void checkSeller(list<Seller*> sellers) {
string fname, lname;
cout << "Enter the seller's first name: " ;
cin >> fname;
cout << "Enter the seller's last name: " ;
cin >> lname;
bool found = false;
for (list<Seller*>::iterator i = sellers.begin(); i != sellers.end(); i++) {
if ((*i)->getFirstName() == fname && (*i)->getLastName() == lname)
{
found = true;
cout << "\n" << endl;
(*i)->print();
}
}
if (!found)
{
cout << "Seller not found." << endl;
}
}
void addSeller(list<Seller*> sellers)
{
string fname, lname, info, web, em, id;
int sold, item;
float rating;
cout << "Please enter the following information (enter invalid type to quit): " << "\n";
cout << "Is the seller a (S)eller or (P)ower Seller? ";
cin >> info;
if (info == "S")
{
cout << "first name: " << endl;
cin >> fname;
cout << "last name: " << endl;
cin >> lname;
cout << "User ID: " << endl;
cin >> id;
cout << "Email Address: " << endl;
cin >> em;
//Email Address:
cout << "Average Star Rating: " << endl;
cin >> rating;
cout << "Total Items sold: " << endl;
cin >> item;
cout << "The new Power Seller has been added. Returning to Seller Management..." << endl;
Seller* newseller = new Seller;
newseller -> read(cin);
sellers.push_back(newseller);
}
if (info == "P")
{
cout << "first name: " << endl;
cin >> fname;
cout << "last name: " << endl;
cin >> lname;
cout << "User ID: " << endl;
cin >> id;
cout << "Email Address:" << endl;
cin >> em;
//Email Address:
cout << "Average Star Rating: " << endl;
cin >> rating;
cout << "Total Items sold: " << endl;
cin >> item;
cout << "Website Address: " << endl;
cin >> web;
cout << "Current year products Sold: " << endl;
cin >> sold;
Powerseller* newpowerseller = new Powerseller;
newpowerseller -> read(cin);
sellers.push_back(newpowerseller);
//for (list<Seller*>::iterator i = sellers.begin(); i != sellers.end(); i++)
//{
//Powerseller* newpowerseller = new Powerseller;
//newpowerseller -> read(cin);
//sellers.push_back(newpowerseller);
//break;
//}
}
}
void deleteSeller(list<Seller*> &sellers) {
string fname, lname;
cout << "Enter the seller's first name: ";
cin >> fname;
cout << "Enter the seller's last name: ";
cin >> lname;
bool found = false;
for (list<Seller*>::iterator i = sellers.begin(); i != sellers.end(); i++) {
if ((*i)->getFirstName() == fname && (*i)->getLastName() == lname) {
found = true;
sellers.erase(i);
break;
}
}
if (!found)
{
cout << "Seller not found." << endl;
}
}
My add function doesn't return to the menu. Can you help me out?
![Menu
1. Print information of all sellers
2. Check information of a particular seller
3. Add a seller to the list
4. Remove a seller from the list
5. Quit
Enter your choice: 3
Please enter the following information (enter invalid type to qui
t):
Is the seller a (S)eller or (P)ower Seller? S
first name:
Luke
last name:
River
User ID:
LR89
Email Address:
LR89@goggle.com
Average Star Rating:
5
Total Items sold:
455
The new Power Seller has been added. Returning to Seller Managem
ent...
0](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F45088ba1-a1a3-4a96-b462-54f2c0a5a29e%2Fa855f413-48c5-4fc0-99d5-4e84f388ffc3%2F9934z8h_processed.png&w=3840&q=75)
![Please choose from the following menu:
1. Print all seller information
2. Check information of one seller
3. Add a seller
4. Remove a seller
5. Quit
Enter your choice: 3
Please enter the following information (enter invalid type to quit):
Is the seller a (S)eller or (P)ower Seller? S
First name: Angela
Last name: Thomas
User ID: angthomas
Email Address: angela.thomas@bellsouth.com
Average Star Rating: 3.7
Total Items sold: 380
The new Seller has been added. Returning to Seller management...
Please choose from the following menu:
1. Print all seller information
2. Check information of one seller
3. Add a seller
4. Remove a seller
5. Quit](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F45088ba1-a1a3-4a96-b462-54f2c0a5a29e%2Fa855f413-48c5-4fc0-99d5-4e84f388ffc3%2F9z2on9a_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)