COS120 Assignment #2 1 COS220 Assignment #9 Due: Sunday 4/11/21 Late: Sunday 4/18/21 Worth: 60 points The data file inventory.txt contains 15 data sets for products in an inventory where each line...

1 answer below »
Intro to C++.MLA is not relevant.



COS120 Assignment #2 1 COS220 Assignment #9 Due: Sunday 4/11/21 Late: Sunday 4/18/21 Worth: 60 points The data file inventory.txt contains 15 data sets for products in an inventory where each line lists a product name (no blanks), an amount in stock, and a unit price. Code will use three parallel arrays to store the related data. Advanced topics such as vectors, structs, classes, or generic algorithms should not be used. Functions are not required as they were not covered this week. const int NPRODUCTS = 15; // number of products string products[NPRODUCTS]; // array of product names int quantities[NPRODUCTS]; // array of quantities double unitprices[NPRODUCTS]; // array of unit prices Task 1: The user can enter product names, using sentinel value "quit" to end. Use the sequential search algorithm to test if the product is found in the inventory. This algorithm was covered in Wednesday's material. If the product is found, the user enters the quantity desired and the quantity is updated and reported. If the quantity becomes negative, message *** Backordered *** displays. See sample output. Task 2: The inventory is displayed listing product name, amount in stock, unit price and in-stock value (amount in stock times unit price). Items that have a negative amount in stock have an in-stock worth of 0.00. The total in-stock worth is reported. 2 Submit output using your name. Use the same data entries.
Answered 7 days AfterApr 16, 2021

Answer To: COS120 Assignment #2 1 COS220 Assignment #9 Due: Sunday 4/11/21 Late: Sunday 4/18/21 Worth: 60...

Vibhav answered on Apr 17 2021
137 Votes
inventory/inventory.cpp
inventory/inventory.cpp
#include
#include
#includeeam>
#include
using namespace std;
int main(){
    const int NPRODUCTS = 15; // number of products
    string products[NPRODUCTS]; // array of product names
    int quantities[NPRODUCTS]; // array of quantities
    double unitprices[NPRODUCTS]; // array of unit prices
    string line;
    ifstream file("inventory.txt");
    //Read file line by line
    //Split each line using blank space
    //Read and store in respective arrays
    int i=0;
    while(getline(file, line)){
        //Convert line to char array
        char str[line.length()];
        strcpy(str, line.c_str());
        //Tokenize the line read using blank space
        char* token = strtok(str, " ");
        products[i] = token;
        token = strtok(NULL, " ");
        quantities[i] = stoi(token);
        token = strtok(NULL, " ");
        unitprices[i] = stof(token);
        i++;
    }
    for(int i=0; i<...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here