Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

So I have a CS project where I have a shopping cart and for the 2nd part we are supposed to make additions the only

So I have a CS project where I have a shopping cart and for the 2nd part we are supposed to make additions the only concept/question that is giving me trouble is :

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.

the file is an excel spreadsheet and the first cell of the first line is how many items the file has, so how do I use dynamic memory to create an array of objects or am I supposed to be approaching this a different way because the example number is 121 so how am I supposed to store that many objects without using a dynamic array filled with a struct to store ill post the first part of the code and a picture of the excel sheet:

#include "stdafx.h"

#include

#include

#include

#include

using namespace std;

int main(){

//Declaring vairbles and arrays and such

string item[100];

string name[100];

string cost[100];

string qty[100];

// extra is for the extra stuff when trying to read and indexes and quantity arrays store info

string extra;

int indexes[100];

int quantity[100];

//open excel sheet

ifstream ProdData;

ProdData.open("ProductData.csv");

//test if file exist

if (ProdData){

//gets over the extra stuff

getline(ProdData, extra);

//fills array with info from excel

for (int x = 0; x

getline(ProdData, item[x], ',');

getline(ProdData, name[x], ',');

getline(ProdData, cost[x], ',');

getline(ProdData, qty[x]);

}

//asking the user for item #

int input;

cout

cin >> input;

/umber of items wanted

int num = 0;

//keeps going while user input is not '0'

while (input != 0){

int index = -1;

for (int x = 0; x

if (input == stoi(item[x]))

index = x;

//displays info

if (index != 0){

int amount;

cout

cout

bool valid = false;

//amount user wants

do{

cout

cin >> amount;

//checks stock of product

if (stoi(qty[index]) == 0){

cout

valid = true;

}

else if (amount > stoi(qty[index]))

cout

else{

indexes[num] = index;

quantity[num] = amount;

valid = true;

num++;

stoi(qty[index]) =stoi(qty[index]) - amount;

}

} while (!valid);

}

else

cout

//goes back in the loop to keep going till '0' is entered

cout

cin >> input;

}

string user, home, zip;

//establishing and asking the customers personal info

cout

cin.ignore();

getline(cin, user);

getline(cin, home);

getline(cin, zip);

//opening and creating the text file

ofstream output;

output.open("invoice.txt");

//printing out the invoice

output

output

output

output

double total = 0;

for (int x = 0; x

double totalI = quantity[x] * stod(cost[indexes[x]]);

total += totalI;

output

}

output

output

//close the text file

output.close();

}

else

cout

ProdData.close();

}

image text in transcribed

Productbats - Exel nsert page Lnyout lorulas unts Revew View Add-ns p lesm 8le.me whstyouwsnt to do hne Normal uriked Cell POSSIBLET LOSS 5might be lost E you sive thie warkbcok n the comma-deim ted ea ronmat To pieserve these features save t in an Excel tie format. Den't show aqgiwe 19000 Product 2 22039 Product3 481 13.4G 101 y9599 Product 1046 Product17 1890 Product 3.64 21220 Product 17 G3293 Product 20 32109 Product 7525G Product 2 y3/0,' 13 | Product 23 74094 Product 7 90808 Product 01209 Product 2 8.45 20 34984 Product 20.89 3277830 Product318.36 23 29153 Product 3 67624 Product 20.9 ProductData(1) (1) | 1V Productbats - Exel nsert page Lnyout lorulas unts Revew View Add-ns p lesm 8le.me whstyouwsnt to do hne Normal uriked Cell POSSIBLET LOSS 5might be lost E you sive thie warkbcok n the comma-deim ted ea ronmat To pieserve these features save t in an Excel tie format. Den't show aqgiwe 19000 Product 2 22039 Product3 481 13.4G 101 y9599 Product 1046 Product17 1890 Product 3.64 21220 Product 17 G3293 Product 20 32109 Product 7525G Product 2 y3/0,' 13 | Product 23 74094 Product 7 90808 Product 01209 Product 2 8.45 20 34984 Product 20.89 3277830 Product318.36 23 29153 Product 3 67624 Product 20.9 ProductData(1) (1) | 1V

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Real Time Database And Information Systems Research Advances

Authors: Azer Bestavros ,Victor Fay-Wolfe

1st Edition

1461377803, 978-1461377801

More Books

Students also viewed these Databases questions