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
frozen [14]
3 years ago
6

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 positive integer specifying the number of shares traded. o The price paid for each share, which is a number that will always have exactly two digits after the decimal point. • A sequence of lowercase letters that specifies a confirmation number for the trade. 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. BOO Forever Boo Enterprises 100 50.00 barzxfq. 200 60.75 hhpncstvz 150 7.90 cjjm 175 100.15 fryzyt 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 description of the stock, followed by a space, followed by the symbol surrounded by parentheses. • Each subsequent line of output describes one of the trades from the input, in the following format: o The confirmation number, followed by a colon and a space, followed by the 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. Forever Boo Enterprises (BOO) barzxfq: 5000 hhpncstvz: 12150 cjjm: 1185 fryzyt: 17526 It is irrelevant whether your program 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.
Computers and Technology
1 answer:
shepuryov [24]3 years ago
4 0

Answer:

The function is as follows:

void readAndConvert(){

   int n; string symbol,name;

   cin>>n;

   cin>>symbol;

   cin.ignore();

   getline (cin,name);

   vector<string> trades;

   string trade;

   for (int inps = 0; inps < n; inps++){

       getline (cin,trade);

       trades.push_back(trade);}

   

   cout<<name<<" ("<<symbol<<")"<<endl;

   for (int itr = 0; itr < n; itr++){

       string splittrade[3];        int k = 0;

       for(int j=0;j<trades.at(itr).length();j++){

           splittrade[k] += trades.at(itr)[j];

           if(trades.at(itr)[j] == ' '){

               k++;    }}

cout<<splittrade[2]<<": "<<floor(stod(splittrade[1]) * stod(splittrade[0]))<<endl;        }

   }

Explanation:

See attachment for complete program where comments are used to explain each line

Download cpp
You might be interested in
To use the wireless network in the airport you must pay the daily fee unless you are a subscriber to the service. Express your a
just olya [345]

Answer:

s ----> w V d

Explanation:

<em>s: You are a subscriber to the service</em>

<em>w: You can use the wireless network in the airport</em>

<em>d: You pay the daily fee</em>

From the statement, we can deduce that To use the wireless in the airport, you either have to be a subscriber to the service or you pay the daily fee.

The statement can be written logically as :

If you are a subscriber to the service, then you can use the wireless network in the airport or you can pay the daily fee

it can be written symbolically as:

s --------> w V d

5 0
4 years ago
Managers seeking competitive intelligence can use any of the scores of online​ databases, some of which are free and some for wh
hoa [83]
Unfortunately, you didn't share the list of sources of competitor​ information so  it is getting difficult to give the answer which will suit the task. But since you have to choose non-online database the most popular one is internal employee group. 
Hope that will help you in some measure.
8 0
3 years ago
Which lines of the code, marked by Q, are legally declared based on the scope of the variable?​
WINSTONCH [101]

inside a function or a block which is called local variables

4 0
2 years ago
You are using a polynomial time 2-approximation algorithm to find a tour t for the metric traveling salesman problem. Which of t
Svet_ta [14]

Answer:

B. The cost of tour t is at most twice the cost of the optimal tour.

Explanation:

You are using a polynomial time 2-approximation algorithm to find a tour t for the traveling salesman problem.

The cost of tour t is at most twice the cost of the optimal tour

The equation represented as Cost(t) <= 2 Cost(T)

Where

Cost (t) represents cost of tour t

Cost(T) represents cost of the optimal tour

3 0
3 years ago
What are three ways science and technology are related and what are three ways they are different?
photoshop1234 [79]

Answer:

Science contributes to technology in at least six ways: (1) new knowledge which serves as a direct source of ideas for new technological possibilities; (2) source of tools and techniques for more efficient engineering design and a knowledge base for evaluation of feasibility of designs; (3) research instrumentation,

Explanation:

3 0
3 years ago
Other questions:
  • Assume that to_the_power_of is a function that expects two int parameters and returns the value of the first parameter raised to
    11·1 answer
  • using unsafe sites may be a. harmful to your computer c. okay as long as you don���t leave any personal information b. okay as l
    9·2 answers
  • How is steering different from turning ? Need help //:
    13·1 answer
  • Where can you find additional commands to include in menu options?
    12·1 answer
  • How many dimples are on the titleist pro v1 golf ball?
    13·1 answer
  • Write a program that converts or calculates values. Use the following guidelines to write your program:
    8·1 answer
  • Write an expression using membership operators that prints "Special number" if special_num is one of the special numbers stored
    13·1 answer
  • Python;
    6·1 answer
  • What two things should you do before starting the design process
    8·1 answer
  • OCR Airlines allows passengers to carry up to 25kg of luggage free of charge. Any additional luggage is charged at £10 per kg. N
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!