Writing a simple C++ PROGRAM (Practice)
Consider a simple textual table describing the catalogues of retail stores, with a line for each product offered by a store, like
Argos Barbie 6.99
Argos PS2 159.99
Hamleys Barbie 16.99
Each line consists of three words: a vendor code, a product code and the price of that product from that vendor (a floating point number).
Define a class to hold the catalogue record.
Write a function to read a series of catalogue records from a file into a vector of catalogue objects. You will need to use the class ifstream, which is derived from istream, like so:
#include <fstream>
...
ifstream in("catalog");
... istream operations ...
The constructor opens the file; you can then test in to see whether it succeeded.
Write a main program that reads from standard input a series of lines describing orders, like
Barbie 200
PS2 1
Barbie 2
where each line consists of two words: a product code (as in the catalogue file) and a requested quantity (a whole number).
For each input line, the program should produce on the standard output a line for each store stocking that product, combining the information from both records. For example, the above inputs might result in
Barbie 200 Argos 6.99
Barbie 200 Hamleys 16.99
PS2 1 Argos 159.99
Barbie 2 Argos 6.99
Barbie 2 Hamleys 16.99
If there are no store records for a particular vendor, there will be no output for that line.
© BrainMass Inc. brainmass.com June 7, 2023, 2:30 pm ad1c9bdddfhttps://brainmass.com/computer-science/cpp/writing-a-simple-c-program-practice-13353
Solution Preview
Hi,
<br> In my code (attached file) I've declared two classes: first ...
Solution Summary
Writing a simple C++ PROGRAM (Practice) is modeled.
Free BrainMass Quizzes
-
Quiz on basics of javascript programming language.
-
This quiz contains questions about C# classes and variables.
-
Inserting and deleting in a linked list
This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.
-
We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.
-
This quiz tests a student's knowledge about C++ operators.