//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?


Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images









