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

Hi I\'m doing a c++ final project that is due on wed, the project involves makei

ID: 3845551 • Letter: H

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 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 <iostream>

int signIn(vector<User>&);
void addUser(vector<User>&);
void displayUsers(vector<User>&);

int main() {

vector<User> *allUsers = new vector<User>();
int UserPosition = -1;


bool done = false;
while (done == false) {
  cout << " Enter 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<User>& allUsers) {
string testUserName;
string testPassword;
int testUserPosition = -1;
bool isvalid = false;
//validating username
while (isvalid == false) {
  cout << "UserName : ";
  cin >> testUserName;
  for (int x = 0; x < allUsers.size(); x++) {
   if (testUserName == allUsers.at(x).getUserName()) {
    isvalid = true;
    testUserPosition = x;
   }
  }
  if (isvalid == false) {
   cout << "UserName Is Not Valid. Try again ";
   
  }
}
//validating password
isvalid = false;
while (isvalid == false) {
  cout << " Password : ";
  cin >> testPassword;
  if (testPassword == allUsers.at(testUserPosition).getPassword()) {
   isvalid = true;
   return testUserPosition;
  }
  if (isvalid == false) {
   cout << "Password Is Not Valid ";
  }
}
return -1;
}


void displayUsers(vector<User>& allUsers) {
cout << "Displaying Users ";
for (int x = 0; x < allUsers.size(); x++) {
  cout << allUsers.at(x).getUserName() << endl;
  cout << allUsers.at(x).getPassword() << " ";
}
}


void addUser(vector<User>& users) {
string Testusername;
string Password;
cout << "Enter A New UserName : ";
cin >> Testusername;
cout << " Enter A New Password : ";
cin >> Password;
User user(Testusername, Password);
users.push_back(user);
}

=================================================================== User.h

#pragma once
#include <iostream>
#include <string>
#include <vector>
#include "Item.h"
#include "Inventory.h"

using namespace std;

class User {
private:
string UserName;
string Password;
vector<Item>Cart;
public:
void shopInventory(User*, vector<Item>);
void showCart(User*);
void checkout(User*);
string getUserName() { return UserName; }
string getPassword() { return Password; }

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<Item> inventory) {
for (int x = 0; x < inventory.size(); x++) {
  inventory.at(x).printItem(inventory.at(x));
}
cout << "Would You Like To Add An Item To Your Cart? Y or N ";
char choice;
cin >> choice;
if (toupper(choice) == 'Y') {
  cout << "Enter The Item To Add 0 to " << inventory.size();
  int add;
  cin >> add;
  user->Cart.push_back(inventory.at(add));
}
}


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 <string>
#include <iostream>
#include <vector>
#include <algorithm>
typedef std::string String;
class Item
{
private:
int inStock = 0;
int itemNumber = 0;
String itemName = "";
String itemBrand = "";
float itemPrice = 0;
bool sold;
public:
Item();
~Item();

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 <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include "Item.h"
#include <fstream>

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<Item> inventory;

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

Explanation / Answer

#include "User.h"
#include <iostream>

int signIn(vector<User>&);
void addUser(vector<User>&);
void displayUsers(vector<User>&);

int main() {

vector<User> *allUsers = new vector<User>();
int UserPosition = -1;


bool done = false;
while (done == false) {
  cout << " Enter 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<User>& allUsers) {
string testUserName;
string testPassword;
int testUserPosition = -1;
bool isvalid = false;
//validating username
while (isvalid == false) {
  cout << "UserName : ";
  cin >> testUserName;
  for (int x = 0; x < allUsers.size(); x++) {
   if (testUserName == allUsers.at(x).getUserName()) {
    isvalid = true;
    testUserPosition = x;
   }
  }
  if (isvalid == false) {
   cout << "UserName Is Not Valid. Try again ";
   
  }
}
//validating password
isvalid = false;
while (isvalid == false) {
  cout << " Password : ";
  cin >> testPassword;
  if (testPassword == allUsers.at(testUserPosition).getPassword()) {
   isvalid = true;
   return testUserPosition;
  }
  if (isvalid == false) {
   cout << "Password Is Not Valid ";
  }
}
return -1;
}


void displayUsers(vector<User>& allUsers) {
cout << "Displaying Users ";
for (int x = 0; x < allUsers.size(); x++) {
  cout << allUsers.at(x).getUserName() << endl;
  cout << allUsers.at(x).getPassword() << " ";
}
}


void addUser(vector<User>& users) {
string Testusername;
string Password;
cout << "Enter A New UserName : ";
cin >> Testusername;
cout << " Enter A New Password : ";
cin >> Password;
User user(Testusername, Password);
users.push_back(user);
}

=================================================================== User.h

#pragma once
#include <iostream>
#include <string>
#include <vector>
#include "Item.h"
#include "Inventory.h"

using namespace std;

class User {
private:
string UserName;
string Password;
vector<Item>Cart;
public:
void shopInventory(User*, vector<Item>);
void showCart(User*);
void checkout(User*);
string getUserName() { return UserName; }
string getPassword() { return Password; }

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<Item> inventory) {
for (int x = 0; x < inventory.size(); x++) {
  inventory.at(x).printItem(inventory.at(x));
}
cout << "Would You Like To Add An Item To Your Cart? Y or N ";
char choice;
cin >> choice;
if (toupper(choice) == 'Y') {
  cout << "Enter The Item To Add 0 to " << inventory.size();
  int add;
  cin >> add;
  user->Cart.push_back(inventory.at(add));
}
}


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 <string>
#include <iostream>
#include <vector>
#include <algorithm>
typedef std::string String;
class Item
{
private:
int inStock = 0;
int itemNumber = 0;
String itemName = "";
String itemBrand = "";
float itemPrice = 0;
bool sold;
public:
Item();
~Item();

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 <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include "Item.h"
#include <fstream>

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<Item> inventory;

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));
}

}

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