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
What type of electronic monitoring involves an offender being contacted periodically by telephone or beeper to verify his or her
Masja [62]
The type of electronic monitoring that involves an offender being contacted periodically by telephone or beeper to verify his or her whereabouts is called the programmed contact. It is a method used in investigations to monitor the offender in a certain situation where he is forced to remain.
7 0
3 years ago
Roark has just joined a company and in his role as a lead analyst, he will be responsible for determining which systems developm
hram777 [196]

Answer:

Agile/adaptive methods.

Explanation:

The user has just decided to join a firm and will also be accountable to determine whether that system development technique that group uses to establish the latest software for a significant medical distributor to his position as just a lead analyst.

After that, he consumes a week for the purpose to understand his group members for reason to know their strengths and weakness and how would they work under pressure.

So, the following method is required for him to understand about the disadvantages of each of them.

4 0
3 years ago
Which of the following is NOT a common grammar adjustment which is identified by grammar-check software?
Sedbober [7]

Answer:

Shortened versions of phrases Ex:(l ol, s mh, i dk, ect.)

Explanation:

Hope that this helps, if you have any more question please feel free to contact me, hope you have an amazing rest of your day. ;D

7 0
2 years ago
PLEASE HELP there are TWO ANSWERS
pickupchik [31]

Answer:

Pero un campo cuyo tipo de datos es Número solo puede almacenar datos numéricos. ... Por ejemplo, los valores que se almacenan en un campo Texto solo pueden contener ... Para más información, haga clic en los tipos de datos siguientes. ... Controla la conversión de frases en las versiones asiáticas de Windows.

5 0
3 years ago
You have just assembled your first PC. You hit the power button and the computer turns on. As the computer runs through POST, it
Paha777 [63]

Answer:

Explanation:

If the HDD is spinning, this means that the power cable is correctly connected and that the drive is receiving power and powering on. However, this does not mean that the HDD is functioning correctly and reading the information. Therefore, the next logical step would be to check the SATA cable that connects the drive to the motherboard. The cable may be broken or maybe the SATA slot on the motherboard. Switch out the cables and plug it into another slot. If this does not work, then it may be that the HDD is broken. Multiple Beeps can also mean that the RAM or CPU is not plugged in correctly or broken.

6 0
3 years ago
Other questions:
  • To set up a slide show you should do all of the following except ______.
    9·1 answer
  • HTTP is made to facilitate which kind of communication?
    11·1 answer
  • How to get the absolute value in coding begginners?
    13·2 answers
  • How often does colleges update the cost of attendance on their website?.
    13·1 answer
  • If two hosts are connected by five networks, how many frames will there be when one host sends a packet to the other host? 1 2 5
    13·1 answer
  • What does running the “sudo” command do?
    6·1 answer
  • You have to cut a wood stick into pieces. The most affordable company, The Analog Cutting Machinery, Inc. (ACM), charges money a
    10·1 answer
  • hi pls help me how to connect my imac to our wifi cause it’s not showing the wifi option (use pic for reference)
    7·1 answer
  • Answer all of the questions,
    7·1 answer
  • What is used for risk response control?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!