Write a C++ function with the following signature: void readAndConvert() The function takes no parameters and returns no value. Instead, it reads its input from std::cin and writes its output to std::cout. Both the input and output are information describing a sequence of stock trades, albeit in different formats. Input format The input will be formatted according to the following specification. You may freely assume that the input will be in the format described here; it doesn't matter what your function does with input that doesn't meet those requirements. The first line of the input will contain a positive integer, which will specify the number of trades whose information will be present in the input. The second line of the input will contain the stock's symbol, which is a sequence of uppercase letters. The third line of the input will contain a brief description of the stock, which is any arbitrary sequence of characters. After that will be one line for each trade — so the integer on the first line tells you how many more lines there will be — which will contain three pieces of information separated by spaces: A sequence of lowercase letters that specifies a confirmation number for the trade. The price paid for each share, which is a number that will always have exactly two digits after the decimal point. A positive integer specifying the number of shares traded. One example input that follows that format is as follows, though your function would need to work on any input that follows the specification, not just the one example. 4 BOO Forever Boo Enterprises bqrzxfq 50.00 100 hhpncstvz 60.75 200 cjjm 7.90 150 frqyzvt 100.15 175 Output format Your function's output is a reorganization of the information from the input, which you would write in the following format. The first line of output would contain the stock's symbol, followed by a space, followed by the description surrounded by parentheses. Each subsequent line of output describes one of the trades from the input, in the following format: The confirmation number, surrounded by brackets, followed by a space and then integer number of dollars spent in the order (i.e., the number of shares times the price per share, always rounding to the floor of the number). The correct output for the example input above is as follows. BOO (Forever Boo Enterprises) [bqrzxfq] 5000 [hhpncstvz] 12150 [cjjm] 1185 [frqyzvt] 17526 It is irrelevant whether your function prints all of the output only after reading the input, or whether it prints the output while it reads input; this is your choice. The only requirement is that your output meets the formatting requirements.
Write a C++ function with the following signature:
void readAndConvert()
The function takes no parameters and returns no value. Instead, it reads its input from std::cin and writes its output to std::cout. Both the input and output are information describing a sequence of stock trades, albeit in different formats.
Input format
The input will be formatted according to the following specification. You may freely assume that the input will be in the format described here; it doesn't matter what your function does with input that doesn't meet those requirements.
- The first line of the input will contain a positive integer, which will specify the number of trades whose information will be present in the input.
- The second line of the input will contain the stock's symbol, which is a sequence of uppercase letters.
- The third line of the input will contain a brief description of the stock, which is any arbitrary sequence of characters.
- After that will be one line for each trade — so the integer on the first line tells you how many more lines there will be — which will contain three pieces of information separated by spaces:
- A sequence of lowercase letters that specifies a confirmation number for the trade.
- The price paid for each share, which is a number that will always have exactly two digits after the decimal point.
- A positive integer specifying the number of shares traded.
One example input that follows that format is as follows, though your function would need to work on any input that follows the specification, not just the one example.
4 BOO Forever Boo Enterprises bqrzxfq 50.00 100 hhpncstvz 60.75 200 cjjm 7.90 150 frqyzvt 100.15 175
Output format
Your function's output is a reorganization of the information from the input, which you would write in the following format.
- The first line of output would contain the stock's symbol, followed by a space, followed by the description surrounded by parentheses.
- Each subsequent line of output describes one of the trades from the input, in the following format:
- The confirmation number, surrounded by brackets, followed by a space and then integer number of dollars spent in the order (i.e., the number of shares times the price per share, always rounding to the floor of the number).
The correct output for the example input above is as follows.
BOO (Forever Boo Enterprises) [bqrzxfq] 5000 [hhpncstvz] 12150 [cjjm] 1185 [frqyzvt] 17526
It is irrelevant whether your function prints all of the output only after reading the input, or whether it prints the output while it reads input; this is your choice. The only requirement is that your output meets the formatting requirements.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images