Explore BrainMass

Writing a simple C++ PROGRAM (Practice)

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

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 October 16, 2018, 4:05 pm ad1c9bdddf

Solution Preview

<br> In my code (attached file) I've declared two classes: first ...

Solution Summary

Writing a simple C++ PROGRAM (Practice) is modeled.

Similar Posting

Practice Program Loops, Simple I/O & Simple Calculations

Need Some Assisstance With A Practice Problem:

Be sure you have access to an ANSI C (not C++) compiler. Code compiles for C++ may or may not be compatible with C.


1. You are to write the basis for what will become, in increments, a small "banking system." This first increment just maintains up to 25 accounts and 0 - 1 million transactions.

2. Store the 25 accounts, including account numbers and balances as an array or arrays, as appropriate.

3. Input will consist of a transaction type (CR for credit and DB for debit), an account number and an amount.

4. You are to (1) initialize the accounts with a zero balance; (2) read in the transactions and adjust the balance of the matching account appropriately; (3) at the end of the program, print out the balances for all accounts.

5. Things to remember:

a) What if the account number on a transaction doesn't match an existing account number?

b) What if an account balance drops below zero? Overdrafts are not allowed.

c) What if the transaction type doesn't match DB or CR?

View Full Posting Details