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
Who is the CEO of Quora?
irina [24]
Adam D'Angelo is the CEO and co-founder of Quora, an online knowledge market. He was also chief technology officer and <span>vice president of engineering for Facebook.</span>
5 0
2 years ago
What are the names of different types of tablets<br>​
jekas [21]

Answer:

iPad

IPad mini

IPad Pro

IPad air

Samsung Galaxy tab

Galaxy Tab e

galaxy tab pro

Galaxy tab 2

Explanation:

Also maybe could you look at my 3 biology questions i really need help

5 0
2 years ago
Jenny is working on a laptop computer and notices that the computer is not running very fast. She looks and realizes that the la
Stolb23 [73]

Answer:

You are allowed to take out the old ram to replaice it, so replaice it with 2 new 4 GB of ram you dont need to unless the laptop has already 4 GB of ram the type of ram you will use is DDR3 most newer pc's have DDR4 since laptopes are smaller you would need older ram

Explanation:

8 0
3 years ago
Read 2 more answers
Whose massively popular photo led to the creation of google images?
Alex
Jennifer Lopez’s picture led to the creation of google images.
5 0
3 years ago
Question 1 Fill in the blank: Internet search engines are an everyday example of how Boolean operators are used. The Boolean ope
nikdorinn [45]

The Boolean operator OR expands the number of results when used in a keyword search. Thus, the correct option is D.

<h3>What is the Boolean operator?</h3>

The Boolean operator may be defined as an important tool that is utilized in the programming languages for the junctions to integrate or exclude keywords in a search, resulting in more attention and generative outcomes.

The Boolean operators are major of three types with specific functions and properties. They are:

  • AND
  • NOT
  • OR

Therefore, the Boolean operator OR expands the number of results when used in a keyword search. Thus, the correct option is D.

To learn more about Boolean operators, refer to the link:

brainly.com/question/1675220

#SPJ1

4 0
2 years ago
Other questions:
  • How do forensic pathologist determine time of death
    13·1 answer
  • What is the keyboard shortcut Ctrl+Z used for?
    14·2 answers
  • When might be the best time to start saving for retirement?
    5·2 answers
  • How to write greater than or equal to in excel if function
    7·1 answer
  • Please tell me what is basic HTML tags and its function please ​
    8·1 answer
  • D is the correct answer
    8·2 answers
  • Which key combination should you use
    9·2 answers
  • Computer always produces wrong output true or false<br>​
    7·1 answer
  • If I use the command right(90), which way will Tracy turn?<br> If correct I mark brainlist
    10·1 answer
  • you want to upgrade your windows 10 professional computer to windows 11 professional. you begin by checking the hardware and dis
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!