Question: Hi I'm doing a c++ final project that is due on wed, the project involves makeing an inventory so far I created a sign in
Hi I'm doing a c++ final project that is due on wed, the project involves makeing an inventory so far I created a sign in and new user functions to be able to save the items the that user buys under his name and password. However, iIneed in inventory.cpp a fucntion to delete an item if the user want to, also a fucntion to find or search an item by the user inputing the item ID or brand (I was thinking to use maps). Im using files to read and write the items names, prices, Id, and brand. The program that I have is not well done, and needs a lot of improvement, I need help to finish this project. Overall, the project is a inventory and im a file to read and write and save all the items information, the project need to have a add, remove, seacrh or find an item based on user inputing its id or brand, also include a total price of the things the user bought, also I need to use maps in some way. PLEASE I NEED HELP! take a look of the program I have so far. Please run the program to have a better view of what the project is about. Please I need help to have a program runing
======================================================== main.cpp
#include "User.h" #include
int signIn(vector
int main() {
vector
bool done = false; while (done == false) { cout << "\tEnter A Command 1. Sign in 2. New User 3. Display List Of Users"; int input = 0; cin >> input;
//To Sign in if (input == 1) { UserPosition = signIn(*allUsers); User user(&allUsers->at(UserPosition)); //system("cls");
} //To create a new User if (input == 2) { addUser(*allUsers); } //To see all users if (input == 3) { displayUsers(*allUsers); } }
}
int signIn(vector
void displayUsers(vector
void addUser(vector
=================================================================== User.h
#pragma once #include
using namespace std;
class User { private: string UserName; string Password; vector
User(); User(User*); ~User();
User(string userName, string password) { this->UserName = userName; this->Password = password; } };
======================================================================= User.cpp
#include "User.h"
User::User() {}
User::User(User* user) { int input = 0; bool done = false; while (done == false) { cout << "Enter -1 To Sign Out Welcome " << user->getUserName() << ", What Do You Want To DO? 1. Shop Inventory 2. Show Cart "; cin >> input;
//To Show Inventory if (input == 1) { Inventory inventory; shopInventory(user, inventory.inventory); }
//To Show Cart if (input == 2) { showCart(user); cout << "Would you like Check Out These Items ? y/n "; char choice; cin >> choice; if (toupper(choice) == 'Y') { checkout(user); } } //?? if (input == 3) {
} //To Quit if (input == -1) { done = true; } } }
User::~User() {}
void User::shopInventory(User* user, vector
void User::showCart(User* user) { for (int x = 0; x < user->Cart.size(); x++) { user->Cart.at(x).printItem(Cart.at(x)); } }
void User::checkout(User* user) { float grandtotal = 0; for (int x = 0; user->Cart.size(); x++) { grandtotal += user->Cart.at(x).getPrice(); }
cout << "You Have " << Cart.size() << "Items In Your Cart You Have A Grand Total Of: " << grandtotal << "$ Would You Like To Proceed? Enter Y or N"; char choice; cin >> choice; if (toupper(choice) == 'Y') { user->Cart.clear(); cout << "Thank You For Your Purchase "; } else return; }
========================================================================= Item.h
#pragma once #include
void printItem(Item &);
void setitemNumber(); void setName(); void setBrand(); void setPrice(); void setStock();
int getitemNumber(); String getName(); String getBrand(); float getPrice(); };
=================================================================== item.cpp
#include "Item.h"
Item::Item() { std::cout << "Creating New Item "; setName(); setitemNumber(); setBrand(); setPrice(); setStock(); }
Item::~Item() {}
void Item::printItem(Item &item) { std::cout << "######### ITEM DETAILS ##############" << std::endl; std::cout << "Item details are : " << "Item name : " << item.getName() << " " << "Item brand : " << item.getBrand() << " " << "Item serial number : " << item.getitemNumber() << " " << "Item price : " << item.getPrice() << " " << std::endl; std::cout << "######### ITEM DETAILS ##############" << std::endl; }
void Item::setitemNumber() { int Number = 0; std::cout << "Enter the item number" << std::endl; std::cin >> Number; this->itemNumber = Number; }
void Item::setName() { String Name; std::cout << "Enter the name of the item" << std::endl; std::cin >> Name; this->itemName = Name; }
void Item::setBrand() { String Brand; std::cout << "Enter the brand of the item" << std::endl; std::cin >> Brand; this->itemBrand = Brand; }
void Item::setPrice() { float Price; std::cout << "Enter the price of the item" << std::endl; std::cin >> Price; this->itemPrice = Price; }
void Item::setStock() { int AmountStock; std::cout << "Enter the quantity in stock" << std::endl; std::cin >> AmountStock; this->inStock = AmountStock; }
int Item::getitemNumber() { return itemNumber; } String Item::getName() { return itemName; } String Item::getBrand() { return itemBrand; } float Item::getPrice() { return itemPrice; }
================================================================= Inventory.h
#pragma once #include
using namespace std;
class Inventory { public: Inventory() { ifstream infile("inventory.txt", ios::in); char any[255];
while (!infile.eof()) { infile.getline(any, 50); cout << any << endl; } infile.close(); }; ~Inventory() {}; vector
void saveItem(Item); void addItem(); void deleteItem(); void printAll(Inventory); private: const int maxInventory = 20;
};
================================================================= Inventory.cpp
void Inventory::saveItem(Item item) { ofstream file; file.open("inventory.txt", ios::out | ios::app); if (file.fail()) { cout << "Failed To Open File "; } else { file << item.getName() << endl; file << item.getBrand() << endl; file << item.getitemNumber() << endl; file << item.getPrice() << endl; } file.close(); }
void Inventory::addItem() { Item newItem; inventory.push_back(newItem); saveItem(newItem); }
void Inventory::deleteItem() {
}
void Inventory::printAll(Inventory inventory) { for (int x = 0; x < inventory.inventory.size(); x++) { inventory.inventory.at(x).printItem(inventory.inventory.at(x)); }
}
================================================================= Inventory.txt
chips 12 344353 lays book 35 255456 drama
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
