Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment Definition This assignment requires the development of Csoftware that

ID: 667038 • Letter: A

Question

Assignment Definition This assignment requires the development of Csoftware that supports the back-end activities of an imaginary ++ , software that simulates the processing recquests and inventory) of customer service management of . Customers will use a app that specially formatted text files see separate Web-based stores request details in definitions below)Your food service application must read these text files . , manage active order activity virtual shopping update inventory produce receipts (as output fileswhen are complete and then Also, your application must manage customer payment accounts and provide system support functions for inventory control and reporting. The following list represents the minimum set of functional requirement: Addition of food items to shopping carts. (Inventory is temporarily updated.) • Removal of food items from shopping carts. (Temporary changes to inventory are cancelled.) • Creation of shopping cart reports. (Output text file with list of cart items for a specific customer.) • Processing of payment upon checkout. (Includes processing of coupons.) • Processing of order information in customer carts upon checkout. (Commit changes to inventory.) Management of debit accounts for customers. (All payments must be made from these accounts.) Addition of food item quantity to the inventory of the food service (ie, re-stocking) Creation of inventory control reports. (Report for entire inventory or for specific food items.) SSum ions, P re Ons Minimum Data R rements General Customer account info (name, account#, etc.) must be pre-loaded in a customer file. Customer ests may be stored in rate or combined text files. (See below. Sample request files used for testing must be pre-generated. A simple console user interface must be provided for invento control and r rtin Payment and Customers are given an initial balance on their service debit account. Debit Accounts You need to keep track of account balances and reject payments over that amount Customers may submit requests to add money to their food service debit accounts. If total cost of cart items exceeds account balance, then cancel checkout. Food Items: You must define a minimum of twenty (20) types of food items. Initial inventory (food, quantity, prices) must be pre-loaded into an inventory file. Customers must spect ify a quantity for each food item request. Price changes may occur during re-stocking but do not affect price of items in carts. Adding or removing food to carts causes only temporary changes to inventory data. Shopping Carts: Each customer may use only one cart at a time. The food service can handle a maximum of twenty (20) active carts at one time Customers may save cart contents and continue later but only on the same day Checkout request files will also contain any coupon information. Max. 10 coupons.) O Customer cart reports must show all cart items with prices, quantities, and a total . Each cart is deleted immediately after payment and checkout. Customers may only remove cart items for one food item at a time. Entire quantity specified for addition to a cart must be available (no partial orders Inventory Service s ort staff ma form re-stocking actions at any time. Control and Food re-stocking inputs Sy ify food item names, ices, and quantities. Reporting: Restocking quantity values must be added to current quantity levels. Inventory reports are only displayed screen - saved a control on a console not to file.

Explanation / Answer

Customers.txt

MainInventory.txt

REQUEST01.txt

REQUEST02.txt

account.cpp

#include <string>
#include "account.h"
using namespace std;

account::account() : accountName(""), accountBalance(0.00), accountNumber(0)
{
    cart userCart;
    cart * const cartPtr = &userCart;

}

account::account(int accountNumber, const string & accountName, double accountBalance) {
  
    setAccountBalance(accountBalance);
    setAccountName(accountName);
    setAccountNumber(accountNumber);
    cart userCart;
    //cart * const cartPtr = &userCart;

}

account::~account(){ }

void account::setAccountBalance(double balance) {
    accountBalance = balance;
}

double account::getAccountBalance() const {
    return accountBalance;
}

void account::setAccountNumber(int accountNum) {
    accountNumber = accountNum;
}

int account::getAccountNumber() const {
    return accountNumber;
}

void account::setAccountName(const std::string& accName){
    int len = (int)accName.size();
    len = ( len < 15 ? len : 14 );
    accName.copy( accountName, len);
    accountName[len] = '';
    //accountName = accName;
}

std::string account::getAccountName() const {
    return accountName;
}

void account::addToCart(food::food food){
    userCart.addToCart(food);
}


account.h

#ifndef __account__
#define __account__

#include <iostream>
#include <string>
#include "cart.h"

class account : public cart

{
  
public:
    account();
    account(int accountNumber, const std::string& accountName, double accountBalance);
    //account(account const &);
    ~account();
    void setAccountNumber(int accountNumber);
    int getAccountNumber() const;
  
    void setAccountBalance(double accountBalance);
    double getAccountBalance() const;
  
    void setAccountName(const std::string& accountName);
    std::string getAccountName() const;
  
    void addToCart(food);
    void removeFromCart(food);
    double getTotal() const;
    void toString();
  
private:
    double accountBalance;
    int accountNumber;
// std::string accountName;
    char accountName[15];
    cart userCart;
    cart * const cartPtr = &userCart;
};

#endif


cart.cpp

#include <iostream>
#include <string>
#include <vector>
#include "food.h"
#include "cart.h"

using namespace std;

cart::cart(){
    std::vector<food> cartContents;
}

cart::~cart(){
    cartContents.clear();
    //delete cartPointer;
}

void cart::addToCart(food::food food, int qty) {
    food.setFoodQuantity(qty);
    //cartTotal = cartTotal + (food.getFoodCost() * food.getFoodQuantity());
    cartContents.push_back(food);
}

void cart::addToCart(food::food food) {
    //cartTotal = cartTotal + (food.getFoodCost() * food.getFoodQuantity());
    cartContents.push_back(food);
}

double cart::getCartTotal() const {
    double cartTotal = 0.00;
    for (int i=0; i < cartContents.size(); i++){
        cartTotal = cartTotal + (cartContents[i].getFoodQuantity() * cartContents[i].getFoodCost());
    }
    return cartTotal;
}

void cart::clearCart() {
    cartContents.clear();
}

cart.h

#ifndef __cart__
#define __cart__

#include <iostream>
#include <string>
#include <vector>

#include "food.h"


class cart {
public:
    cart();
    ~cart();

    cart * returnCartPointer();
    void addToCart(food::food, int quantity);
    void addToCart(food::food);
  
    double getCartTotal() const;
  
    void clearCart();
    void toString();
  
private:
  
    food foodItem();
    //account currentAccount();
    cart * cartPointer;
    std::vector<food> cartContents;
    std::vector<food> * const cartPtr = &cartContents;
    int foodQty;
    double cartTotal;

  
};

#endif


food.cpp

#include <fstream>
#include <iomanip>
#include <string>
#include "food.h"

using namespace std;

food::food() : foodName(""), foodQuantity(0), foodCost(0.00)
{
  
}

food::food(const string &foodName) : foodQuantity(0), foodCost(0.00)
{
    setFoodName(foodName);
}

food::food( const string &foodName, int quantity) : foodCost(0.00)
{
    setFoodName(foodName);
    setFoodQuantity(quantity);
}

food::food ( const string &foodName, int quantity, double foodPrice)
{
    setFoodName(foodName);
    setFoodCost(foodPrice);
    setFoodQuantity(quantity);
}

food::~food(){
  
}


void food::setFoodName(const string &foodN){
    int len = foodN.size();
    len = ( len < 10 ? len : 9 );
    foodN.copy( foodName, len);
    foodName[len] = '';
// foodName = name;
}

string food::getFoodName() const {
    return foodName;
}

void food::setFoodQuantity(int quantity) {
    foodQuantity = quantity;
}

int food::getFoodQuantity() const {
    return foodQuantity;
}

void food::setFoodCost(double cost) {
    foodCost = cost;
}

void food::toString() {

    std::cout << "food name: " << this->getFoodName() << std::endl
    << "quantity: " << this->getFoodQuantity() << std::endl
    << "cost per: " << this->getFoodCost() << std::endl;
}

double food::getFoodCost() const {
    if (foodCost <= 0.00){
    }
    return foodCost;
}

double food::getTotalFoodCost() const {
    return (foodCost * foodQuantity);
}

food.h

#ifndef __food__
#define __food__

#include <iostream>
#include <string>

class food {

public:
    food();
    food (const std::string & );// int = 0, double = 0.0
    food (const std::string & , int);
    food( const std::string &, int, double);
    ~food();
    void setFoodQuantity(int quantity);
    void setFoodName(const std::string &);
    void setFoodCost(double cost);
    double getFoodCost() const;
    double getTotalFoodCost() const;
    std::string getFoodName() const;
    int getFoodQuantity() const;
    void toString();
  
private:
    //std::string foodName;
    char foodName[10];
    int foodQuantity;
    double foodCost;
};

#endif


inventory.cpp

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <vector>

#include "inventory.h"
#include "food.h"

inventory::inventory(){
    //upon construction load the inventory file
  
    std::ifstream inOut("/Users/tj/Documents/cis2252/cis2252_final_project/cis2252_final_project/backend/MAININVENTORY.TXT",
                        std::ios::in | std::ios::binary);
    if (!inOut) {
        std::cerr << "INVENTORY FILE MISSING SHOULD BE LOCATED IN ./backend/ SUBDIRECTORY FROM WHICH PROGRAM WAS EXECUTED"
        << std::endl;
        exit (EXIT_FAILURE);
    }
    std::string buffer;
    while (std::getline(inOut, buffer)) {
      
        //finding locations split by different delimiters
        size_t foodLocation = buffer.find_first_of(",");
        size_t quantityLocation = buffer.find_last_of(",");
      
        food currentFood( buffer.substr(0,foodLocation),
                         stoi(buffer.substr(foodLocation +1, quantityLocation - foodLocation -1)),
                         stod(buffer.substr(quantityLocation+1)));
      
        currentInventory.push_back(currentFood);
        //std::cout << currentFood.getFoodName();

    }
    currentInventory.shrink_to_fit();
      
    inOut.close();
    inventorySize = (int)currentInventory.size();
}

inventory::~inventory(){
  
    //code to save the inventory here
    saveInventory();
}

int inventory::getInventorySize() const {
    return inventorySize;
}

void inventory::addItem(){
    std::string name;
    int quantity;
    double cost;
    std::cout <<"please enter the name for the new item" << std::endl << "> ";
    std::cin >> name;
    std::cout <<"please enter the quantity" << std::endl << "> ";
    std::cin >> quantity;
    std::cout <<"please enter the cost of the new item" << std::endl << "> ";
    std::cin >> cost;
    food newItem(name,quantity,cost);
    currentInventory.push_back(newItem);
  
}

void inventory::report() {
    std::cout << " contents in inventory" << std::endl;
    std::cout << std::left << std::setw(10)
    << "Item:" << std::setw(16)
    << "Quantity:" << std::setw(11) << std::setprecision(3)
    << "Price:" <<std::endl;

    for ( int i = 0; i < currentInventory.size(); ++i){
        std::cout << std::left << std::setw(10) << currentInventory[i].getFoodName()
            << std::setw(16) << currentInventory[i].getFoodQuantity()
            << std::setw(11) << std::setprecision(2) << std::fixed << std::showpoint
            << currentInventory[i].getFoodCost() << std::endl;
    }
  
}

void inventory::indvReport() {
    bool success = 1;
    std::cout << "please enter an item you wish to search for " << std::endl << "> ";
    std::string input ("");
    std::cin >> input;
    for (int i = 0; i < currentInventory.size(); ++i) {
        if (currentInventory[i].getFoodName().compare(input) == 0) {
            success = 1;
            std::cout << " " << std::left << std::setw(10)
            << "Item:" << std::setw(16)
            << "Quantity:" << std::setw(11) << std::setprecision(2) << std::right
            << "Price:" <<std::endl;
            std::cout << std::left << std::setw(10) << currentInventory[i].getFoodName()
            << std::setw(16) << currentInventory[i].getFoodQuantity()
            << std::setw(11) << std::setprecision(2) << std::right << std::fixed << std::showpoint
            << currentInventory[i].getFoodCost() << " " << std::endl;
        }
    }

}

void inventory::toString() {
    //std::cout << "contents in inventory" << std::endl;
    for ( int i = 0; i < currentInventory.size(); ++i){

        std::cout << "food name: " << currentInventory[i].getFoodName()
            << std::endl
            << "quantity: " << currentInventory[i].getFoodQuantity() << std::endl
            << "cost per: " << currentInventory[i].getFoodCost() << std::endl;
      
    }
}

std::string inventory::getFoodName() const{
    return foodName;
}

double inventory::searchForPrice(const std::string &foodName) {
    double stupid = 0.00;

        for (int j = 0; j < currentInventory.size(); j++) {
            std::cout <<std::endl<<"comparing:::" << currentInventory[j].getFoodName()<< std::endl<< " with "<< foodName;
            if (currentInventory[j].getFoodName() == foodName) {
                std::cout<<" we have a match: " <<currentInventory[j].getFoodCost()<<std::endl;
                stupid = currentInventory[j].getFoodCost();
            }
        }
  
    return stupid;
}

void inventory::saveInventory() {
      
    std::ofstream outPutFile("/Users/tj/Documents/cis2252/cis2252_final_project/cis2252_final_project/backend/MAININVENTORY.TXT",
                        std::ios::in | std::ios::binary);
    if (!outPutFile) {
        std::cerr << "INVENTORY FILE MISSING SHOULD BE LOCATED IN ./backend/ SUBDIRECTORY FROM WHICH PROGRAM WAS EXECUTED"
        << std::endl;
        exit (EXIT_FAILURE);
    }
    for (int j= 0; j < currentInventory.size(); ++j) {
        outPutFile << currentInventory[j].getFoodName() <<',' << currentInventory[j].getFoodQuantity() << ',' << currentInventory[j].getFoodCost() << std::endl;
    }
  
}

inventory.h

#ifndef __inventory__
#define __inventory__

#include <iostream>
#include <string>
#include <vector>
#include "food.h"

class inventory {
public:
    inventory();
    ~inventory();
  
    void setFoodQty( const std::string &, int);
    void setFoodPrice ( double price);
    void setFoodName ( const std::string &);
    void toString();
    void addItem();
    void saveInventory();
  
    std::string getFoodName() const;
  
    int getFoodQuantity() const;
    int getInventorySize() const;
  
    void report();
    void indvReport();
  
    double searchForPrice(const std::string &);
  
private:
  
    std::vector <food> currentInventory;
    char foodName[10];
  
    food foodItem;
    int foodQty;
    int inventorySize;
    double foodPrice;
};

#endif

main.cpp


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <time.h>
#include <vector>
#include <algorithm>
#include <cstdlib>


#include "cart.h"
#include "food.h"
#include "inventory.h"
#include "account.h"


using namespace std;

int enterChoice();
int inventoryChoice();
void outputLine(int , string, double);
const std::string currentDate();
void batchRequests();
vector<account> loadAccounts();
void inventoryControl();

enum choices { REQUEST = 1, INVOICE = 2, PROCESS = 3, INVEN_CONTROLS = 4, END = 5 };
enum comms { ADD = 1, REMOVE, CARTREPORT, CHECKOUT, CREDIT };
enum choices2 { ALL = 1, SINGLE , RESTOCK , ADDITEM, BACK };


inventory storeTotal;
//inventory * const invtPtr = &storeTotal;

int main()
{
      
    int menuChoice;

    while ( ( menuChoice = enterChoice()) != END ) {
        switch (menuChoice) {
          
            case REQUEST:
                cout << "please enter the txt file to import for processing" << endl << "(exit will exit program)"
                    << endl << "> ";
                batchRequests();

                break;
            case INVOICE:
                cout <<"processing transactions and updating inventory please wait..."<< endl;

                break;
            case PROCESS:
                cout << "doing work please wait while reciept is printed to screen"<< endl;

                break;
            case INVEN_CONTROLS:
                //system("clr");
                cout << " ...loading inventory controls... " << endl;
                inventoryControl();
              
                break;
            default:
                cerr << "Incorrect choice!"<< endl << "> ";
                break;
        }
      
    }
  
}

int inventoryMenu() {
    cout << "would you like to: "<< endl;
    cout <<"1.) list all items in inventory" << endl;
    cout <<"2.) list a single item" << endl;
    cout <<"3.) restocking" << endl;
    cout <<"4.) add new items" << endl;
    cout <<"5.) return" << endl << "> ";
    int choice2;
    cin >> choice2;
    return choice2;
}

void inventoryControl() {
    int cho;
    while ( (cho = inventoryMenu()) != BACK) {
        switch (cho) {
            case ALL:
                storeTotal.report();
                break;
            case SINGLE:
                storeTotal.indvReport();
                break;
            case RESTOCK:
                break;
            case ADDITEM:
                storeTotal.addItem();
                break;
            case BACK:
                break;
            default:
                cerr << "incorrect choice!"<< endl << "> ";
                break;
        }
    }
}

void outputLine(int account, string name, double balance) {
    cout << left << setw(10) << account << setw(13) << name << setw(7) << setprecision(2) << right << balance <<endl;
}

int enterChoice() {
    cout << " Welcome to the store! " << endl << "today is: " << currentDate()<< endl;
    cout << "1.) Send a request file" << endl;
    cout << "2.) view invoice" << endl;
    cout << "3.) process order" << endl;
    cout << "4.) inventory controls" << endl;
  
    cout << "5.) quit" <<endl << "> ";
    int choice1;
    cin >> choice1;
    return choice1;
}

const std::string currentDate() {
    time_t     now = time(0);
    struct tm tstruct;
    char       buf[80];
    tstruct = *localtime(&now); //pointing
    //extract just the date from the system time
    strftime(buf, sizeof(buf), "%x", &tstruct);
    return buf;
}

void batchRequests() {
    inventory storesUp;
  
    string requestPath;
    cin >> requestPath;
    if (requestPath == "exit") {
        exit(3);
    }
    ifstream inOut;
    inOut.clear();
    inOut.open( requestPath.c_str() );
    while (inOut.fail()) {
        if (requestPath == "exit") {
            exit(3);
        }
        inOut.clear();
        cerr << "File not found"<< endl << "please enter the absolute file path"<<endl<<"> ";
        cin >> requestPath;
        inOut.open(requestPath.c_str());
    }
    vector<account> accounts = loadAccounts();
    //cart myCart;
    vector<string> commands;
    string line;
  
  
    //adds each line to a vector for processing
    while (std::getline(inOut, line)) {
        commands.push_back(line);
    }
  
    for (int i=0; i<commands.size(); i++) {
      
        //work space variables
        string newCommand;
        int accountNumber;
        string foodToAdd;
        int qtyToAdd;
      
        //finding locations split by different delimiters
        size_t commandLocation = commands[i].find_first_of(":");
        size_t accountLocation = commands[i].find_first_of(",");
        size_t foodLocation = commands[i].find_last_of(",");
      
      
        //parsing the commands
        newCommand = commands[i].substr(0,commandLocation);
        accountNumber = stoi(commands[i].substr(commandLocation +1, accountLocation - commandLocation -1));
        foodToAdd = commands[i].substr(accountLocation +1, foodLocation - accountLocation -1);
        qtyToAdd = stoi(commands[i].substr(foodLocation+1));
      
        food workingFood(foodToAdd,qtyToAdd);
      
        for ( int i = 0; i < accounts.size(); ++i){
          
            if (accountNumber == accounts[i].getAccountNumber()) {
                double test = storesUp.searchForPrice(workingFood.getFoodName());
                workingFood.setFoodCost(storesUp.searchForPrice(workingFood.getFoodName()));
                accounts[i].addToCart(workingFood);
                cout << endl << endl << test <<endl;
            }
        }
    }
  
  
  
    inOut.close();
  
}

vector<account> loadAccounts() {
  
    vector<account> acc;
    std::ifstream inOut("/Users/tj/Documents/cis2252/cis2252_final_project/cis2252_final_project/backend/CUSTOMERS.TXT",
                        std::ios::in);
    if (!inOut) {
        std::cerr << "CUSTOMER FILE MISSING SHOULD BE LOCATED IN ./backend/ SUBDIRECTORY FROM WHICH PROGRAM WAS EXECUTED"
        << std::endl;
        exit (EXIT_FAILURE);
    }
    std::string buffer;
    while (std::getline(inOut, buffer)) {
      
      
        //finding locations split by different delimiters
        size_t accountNumberLocation = buffer.find_first_of(":");
        size_t creditLocation = buffer.find_last_of(",");
      
        account currentAccount( stoi(buffer.substr(0,accountNumberLocation)),
                         (buffer.substr(accountNumberLocation +1, creditLocation - accountNumberLocation -1)),
                         stod(buffer.substr(creditLocation+1)));
      
        acc.push_back(currentAccount);
    }
    inOut.close();
    return acc;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote