Question
Please use c++ , I am uploading my code and it needs to be adjusted according to the new instructions. your help is really appreciated
Please use c++ , I am uploading my code and it needs to be adjusted according to the new instructions. your help is really appreciated ( please try to fix the code)
#include
using namespace std;
string Customername; //declaring variables string streetAddress; string zipCode; int totalCost = 0;
void customerInformation(); //function prototype
float cart[145][5]; int index = 0; int Loadfunction(float array1[][4], int value) {
for (int j = 0; j
void customerInformation(){ // customer information function fstream Output("customerinfo.txt", ios::out); cout > Customername; Output
cout > streetAddress; Output
cout > zipCode; Output
}
void Load(float array2[][5]) { fstream Outfile("Invoice.txt", ios::out); //print to invoice.txt
Outfile
double totalcost = 0; for (int i = 0; i
} Outfile
void addToCart(float Productname, int itemnumber, int qty, float productcost,float totalCost) { //add data to shopping cart
cart[index][0] = itemnumber; cart[index][1] = Productname; cart[index][2] = qty;cart[index][3] = productcost;cart[index][4] = (qty*productcost);cart[index][5] = totalCost + cart[145][5];
index++;
}
int main() { // main function
float a[145][4];
fstream infile("ProductData.csv", ios::in); //file input
infile.seekg(26L, ios::beg);
for (int rowcount = 0; rowcount > a[rowcount][0]; infile.seekg(8L, ios::cur); infile >> a[rowcount][1]; infile.seekg(1L, ios::cur); infile >> a[rowcount][2]; infile.seekg(1L, ios::cur); infile >> a[rowcount][3]; infile.seekg(1L, ios::cur); }
int useritemnumber;
int count = 0; //counter set to 0 do { cout > useritemnumber; Loadfunction(a, useritemnumber); int index = Loadfunction(a, useritemnumber);
if (Loadfunction(a, useritemnumber) == -1) { //when item is not found cout
int QTY; cout > QTY;
while (QTY > a[index][3]) { //while quantity is greater than stock cout > QTY;
}a[index][3] = a[index][3] - QTY; addToCart(Productname, useritemnumber, QTY, ProductCost, totalCost);
}
count++; } while (!useritemnumber == 0); Load(cart); if (infile.fail()) { cout
}
customerInformation();
system("pause");
return 0; }
Feature Updates Dynamic Memory - You no longer know how many items are in the inventory file. You now have to be able to accept any number of items. When the program is graded they inventory list will be in the same format but the number of items in the list will be unknown until after your program is running 1. The first item in the inventory file is the number of items in the list. Read in the first line and create a dynamic memory based upon this number a. b. Instead of using arrays you must use structs to store the data. Points will be deducted for not using a struct. You need to update your search function to work with the new dynamic data and struct c. 2. You need to create a shopping cart for the user. Use a data structure of your choice to store what the user has selected to purchase. Remember the user can add as many items to their cart as there are in the inventory list. You need to be able to search through the shopping cart. If a person enters in a duplicate item that is already in the cart then it should increase the qty in the cart. You need to make sure that you have enough inventory to support the change. Do not worry right now about the user removing anything in the cart a. b. c. d. Add in a function that prints the customers cart out. Anytime a user types "cart" when entering items your program should print the user current contents of the cart. You must write this as a function or points will be deducted. Prepare for the next customer by updating the inventory file. After the customer is done shopping you need to update the inventory file so that it matches the new gty's of items left in inventory. Do not just overwrite the file. You must use seekp to update the qty's a. The file should be the same name and same format as when vou first loaded the 3. file Remember to delete any allocated memory at the correct times of your program! Failure to do this will cause a reduction in your grade
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started