1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
creativ13 [48]
3 years ago
12

Write a program that reads raw data from a file that contains an inventory of items. The items should be sorted by name, and the

total value of the inventory calculated. A nice report is printed to a data file including the sorted inventory data.

Computers and Technology
1 answer:
Anika [276]3 years ago
4 0

Answer:

//C++ code

#include<iostream>

#include<fstream>

#include<iomanip>

using namespace std;

/*===============================================*/

// a structure called prod

struct prod

{

string name;// – a string, assumed to have no spaces

double price; // –adollaramount

int inStock; // – the number of items currently in stock.

};

//Fucntion Prototypes

void readInventory(prod products[], int& size);

/*===============================================*/

/*returns: a dollar amount, the total value of the inventory*/

double totalValue(prod products[], int size);

/*===============================================*/

// Sorts the given array by name

void sort(prod products[], int size);

/*===============================================*/

/*a report to a file called “report.txt”.

When the file fails to open, print

“Unable to open output file.” and end.*/

void writeReport(prod products[], int size);

/*===============================================*/

//Function definitions

/*===============================================*/

void writeReport(prod products[], int size)

{

ofstream outfile("report.txt");

outfile << fixed << setprecision(2);

if (!outfile)

{

cout << "Unable to open output file.\n";

return;

}

outfile << "+------------------------------+\n | Current Inventory |\n\

\n+------------------------------+\nNAME PRICE #\n\

\n-------------------- ------- ---\n";

for (int i = 0; i < size; i++)

{

outfile << products[i].name << " " << products[i].price << " " << products[i].inStock << endl;

}

outfile << "+------------------------------+\n";

outfile << "Number of products: " << size << endl;

outfile << "Inventory total value: " << totalValue(products, size) << endl;

cout << "Report written to file\n";

//close the output stream

outfile.close();

}

/*===============================================*/

void sort(prod products[], int size)

{

for (int i = 0; i < size; i++)

{

for (int j = i+1; j < size; j++)

{

if (products[i].name > products[j].name)

{

//swapping

prod temp = products[i];

products[i] = products[j];

products[j] = temp;

}

}

}

}

/*===============================================*/

double totalValue(prod products[], int size)

{

double total = 0;

for (int i = 0; i < size; i++)

{

total += products[i].inStock * products[i].price;

}

return total;

}

/*===============================================*/

void readInventory(prod products[], int& size)

{

// Open a file called “inventory.txt”

//and read the data from the file into the partial array

//.If the file fails to open,

//print “Unable to open input file”

//and set the number of products to 0.

size = 0;

ifstream inFile("inventory.txt");

if (!inFile)

{

cout << "Unable to open input file.\n";

return;

}

string name;

double price;

int qunatity;

while (inFile >> price >>qunatity >>name)

{

if (price != -1 && qunatity != -1 && name != "endofdata")

{

products[size].name = name;

products[size].inStock = qunatity;

products[size].price = price;

size++;

}

}

cout << "inventory read\n";

//close the stream

inFile.close();

}

/*===============================================*/

int main()

{

//declares a partial array of products

prod products[100];

int size;

// invokes readInventory()

readInventory(products, size);

// invokes sort()

sort(products, size);

// invokes writeReport()

writeReport(products, size);

// ends with the standard system pause.

system("pause");

return 0;

}

please see attachment for inventory text and output.

You might be interested in
Im timed!!!!!!!!!!!!!!!!!!<br><br> I NEED HELP ASAP<br> THANK YOU SO MUCH
Troyanec [42]

Answer:

card sorting

Explanation:

tell me if im wrong...

6 0
2 years ago
Read 2 more answers
Which is the best method of marketing a game to casual players?
Phoenix [80]
A casual game is a video game targeted at or used by casual gamers. Casual games may exhibit any type of gameplay or genre. They are typically distinguished by simple rules and by reduced demands on time and learned skill, in contrast to more complex hardcore games. They typically impose low production and distribution costs on the producer. Casual games are often played on a personal computer online in web browsers, but are also popular on game consoles and mobile phones.

Hope this helped. Have a great day! :D
3 0
3 years ago
Read 2 more answers
What is the difference between ARM and INTEL Chip?
tia_tia [17]
With the ever-present rumor of ARM MacBooks<span> gaining renewed energy, it’s time to get an understanding of the technical differences between ARM processors and the more common x86 processors made by </span>Intel<span> and AMD.</span>
8 0
3 years ago
_____ transparency exists when the end user or programmer must specify the database fragment names but does not need to specify
madam [21]

Answer:

The correct answer to the following question will be "Local mapping".

Explanation:

  • A data independence standard in global DBMSs where questions can be constructed without understanding the local formats. Knowledge of quotas of pieces and components is however important.
  • With the transparency of local mapping, the user wants to determine both fragment location and name of data items, keeping in mind any replication that may occur.
  • This is clearly a more complicated and time-consuming question for all the users to answer than the first. A program that only offers it the amount of transparency would be unlikely to be satisfactory to later part-users.

Therefore, "Local mapping" is the right answer.

6 0
3 years ago
Do you think our attitude (whether positive or negative) is something we are born with or that we have power to control within o
Rom4ik [11]

Answer:

I think your attitude is something you develop

Explanation:

I think you develop your attitude and that effects the way you respond to something like if you've got a bad attitude and something bad just happened you tend to lash out and get mad or something but if you have good attitude and something bad just happened you would either brush it off or stay calm and fix it and there are a ton of different ways people react to different situations those were just examples I think your attitude is effect by the way you were raised if you were raised in a bad family your attitude would probably be mean or something.

5 0
3 years ago
Other questions:
  • Tornado Alley is located in the middle of the United States, extending from Texas up through the Dakotas. The above statement is
    14·1 answer
  • Which of these options would likely have a better playback experience in your presentation?
    8·2 answers
  • What does the Chart Elements option allow you to change? A. Values B. Color C. Style D. Axis titles
    13·1 answer
  • THE bestValue PROBLEM Using the Camera structure defined in file p1.cpp, write the function named bestValue(). The function take
    13·1 answer
  • I wonder how world is created
    12·2 answers
  • You can send messages that include photos and videos between mobile devices using ________ technology.
    12·1 answer
  • If we are using an 4-character password that contains only lowercase English alphabetic characters (26 different characters), ho
    15·2 answers
  • Count positive and negative number and compute the average. The program will have the user input an unspecified number of intege
    6·1 answer
  • .Write a MATLAB script that VECTORIZES (eliminates the loop) the following code. (4points)
    14·1 answer
  • Declare a typedef struct named jumper_t that will have four parts: character array name that is 16 in length, double array of tr
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!