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
Explain the difference between social engineering and reverse social engineering.
san4es73 [151]
Social Engineering is the art of eliciting sensitive information from people by tricking them. Like through phishing, fake emails that contain a virus and fake programs. They get your password or any other sensitive information by making you think the website/program is legit. That's why you should always make sure the new website/program you visited is safe.

Reverse Social Engineering is, on the other hand, where the initial attacker becomes attacked. Or the victim redirects the attacker to someone who can counter the attacker. E.g attackers call the front desk and ask for information X. Instead or giving him information X, front desk redirects the call to the security department. An example is where the attacker is fed false information. Law enforcement agencies often perform this attack.
5 0
3 years ago
To find your personal learning style you can
JulsSmile [24]
Https://simplelifestrategies.com/sls-learningstyle/ this list may help ypu decide
6 0
3 years ago
Read 2 more answers
Which statement best explains taxation without representation was a major issue for colonists?
Sauron [17]
Taxation without representation was a major issue for the colonists, because they were being unfairly taxed by the British without having a representative in the British Parliament to represent them ans state that they were against this. It was also one of the driving forces of the American Revolution, as it was just one of the grievances the colonists were experiencing from the British. 
4 0
3 years ago
Write essay about pokhara​
myrzilka [38]

Explanation:

Pokhara is the second most visited city in Nepal, as well as one of the most popular tourist destinations. It is famous for its tranquil atmosphere and the beautiful surrounding countryside. Pokhara lies on the shores of the Phewa Lake. From Pokhara you can see three out of the ten highest mountains in the world (Dhaulagiri, Annapurna, Manasalu). The Machhapuchre (“Fishtail”) has become the icon of the city, thanks to its pointed peak.

As the base for trekkers who make the popular Annapurna Circuit, Pokhara offers many sightseeing opportunities. Lakeside is the area of the town located on the shores of Phewa Lake, and it is full of shops and restaurants. On the south-end of town, visitors can catch a boat to the historic Barahi temple, which is located on an island in the Phewa Lake.

On a hill overlooking the southern end of Phewa Lake, you will find the World Peace Stupa. From here, you can see a spectacular view of the lake, of Pokhara and Annapurna Himalayas. Sarangkot is a hill on the southern side of the lake which offers a wonderful dawn panorama, with green valleys framed by the snow-capped Annapurnas. The Seti Gandaki River has created spectacular gorges in and around the city. At places it is only a few meters wide and runs so far below that it is not visible from the top

5 0
3 years ago
Custom parameters 1, 2 and 3 provide the same end value for all keywords. true or false?
lesya [120]
Is a Microsoft Bing ads certification Exam question.
I think that the correct answer is:
False

Source and more info: <span>https://goo.gl/JUw7Bw</span>
3 0
2 years ago
Other questions:
  • What does the Sort feature do with a database
    13·1 answer
  • What type of program would use to create a personal budget?
    14·1 answer
  • Write a function that iteratively appends random 1's and 0's to an array to form a binary number. The function returns the binar
    13·1 answer
  • [Submit on zyLabs] Please write a function with one input, a matrix, and one output, a matrix of the same size. The output matri
    10·1 answer
  • To see a custom, object-specific action on the palette of the page layout editor: A. Click Layout Properties on the page layout
    11·1 answer
  • Betrand Meyer developed the ______ programming language which is not type-safe because it violates the law of contravariance.
    9·1 answer
  • In the code segment below, assume that the int variable n has been properly declared and initialized. The code segment is intend
    5·1 answer
  • Some websites are dedicated to cataloguing information. Since these sites contain so much data, these sites are usually organize
    11·2 answers
  • Can you please help me with the AP Computer Science Fill in the blank. What goes on number 5 8 and 18. I don’t understand this I
    8·1 answer
  • Dennis would like to include a video in a presentation. The source of the video is on the internet, but he would like to ensure
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!