Question: !!C++!! 10THE countCoins PROBLEM Write a function countCoins that accepts an input stream and an output stream as arguments. The input stream represents a person's
!!C++!!

10THE countCoins PROBLEM Write a function countCoins that accepts an input stream and an output stream as arguments. The input stream represents a person's money grouped into stacks of coins. Add up the cash values of all the coins and print the total money at the end. Input is arranged as pairs of tokens, where each pair begins with an integer and is followed by the type of coin, which will be either "pennies" (1 cent each), "nickels" (5 cents each), "dimes" (10 cents each), or "quarters" (25 cents each), case-insensitively. A given coin might appear more than once on the same line. For example, if the input file contains the following text: 3 pennies 2 quarters 1 pennies 3 nickels 4 dimes 3 pennies are worth 3 cents, and 2 quarters are worth 50 cents, and 1 penny is worth 1 cent, and 3 nickels are worth 15 cents, and 4 dimes are worth 40 cents. The total of these is 1 dollar and 9 cents, therefore your function would produce the following output if passed this input data. Notice that the function should show exactly two digits after the decimal point, so it says 09 for 9 cents: Total money: $1.99 Here is a second example. Suppose the input file contains the following text. Notice the capitalization and spacing: 12 QUARTERS 1 Pennies33 PeNnIeS 10 niCKELS Then your function would produce the following output: Total money: $3.84 You may assume that the file contains at least 1 pair of tokens. You may also assume that the input is valid; that the input has an even number of tokens, that every other token is an integer, and that the others are valid coin types 10THE countCoins PROBLEM Write a function countCoins that accepts an input stream and an output stream as arguments. The input stream represents a person's money grouped into stacks of coins. Add up the cash values of all the coins and print the total money at the end. Input is arranged as pairs of tokens, where each pair begins with an integer and is followed by the type of coin, which will be either "pennies" (1 cent each), "nickels" (5 cents each), "dimes" (10 cents each), or "quarters" (25 cents each), case-insensitively. A given coin might appear more than once on the same line. For example, if the input file contains the following text: 3 pennies 2 quarters 1 pennies 3 nickels 4 dimes 3 pennies are worth 3 cents, and 2 quarters are worth 50 cents, and 1 penny is worth 1 cent, and 3 nickels are worth 15 cents, and 4 dimes are worth 40 cents. The total of these is 1 dollar and 9 cents, therefore your function would produce the following output if passed this input data. Notice that the function should show exactly two digits after the decimal point, so it says 09 for 9 cents: Total money: $1.99 Here is a second example. Suppose the input file contains the following text. Notice the capitalization and spacing: 12 QUARTERS 1 Pennies33 PeNnIeS 10 niCKELS Then your function would produce the following output: Total money: $3.84 You may assume that the file contains at least 1 pair of tokens. You may also assume that the input is valid; that the input has an even number of tokens, that every other token is an integer, and that the others are valid coin types
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
