Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Go through this drill step by step to build up your solution You can use any IDE of your choosing, such as CodeBlocks or

C++

  • Go through this drill step by step to build up your solution
    • You can use any IDE of your choosing, such as CodeBlocks or Nano
  • Test each step as you go by entering at least three pairs of values. More values would be better.
  • The completed program through the last step will be checked for correct output and scored
    • Be sure to match the formatting of the tester to receive full points. It will indicate where formatting does not match.
      • Command prompts are omitted to simplify testing
    • You may turn your code in as many times as you like, it will keep your highest score

(1)

  • Write a program that consists of a while-loop that reads in one double each time around
  • Each time through the loop write out the value entered
  • Define two variables to keep track of which is the smallest and which is the largest value you have seen so far
  • If its the smallest or tied for the smallest so far, write The smallest so far after the number.
  • If it is the largest or tied for the largest so far, write The largest so far after the number.
  • Exit the program when a terminating character is entered, such as '|', or if the stream fails. The easiest way is to just check the status of cin after reading:
while(cin >> num) { ... } 

(2)

  • Add a unit to each double entered; that is, enter values such as 10cm, 2.5in, 5ft, or 3.33m.
  • Accept the four units: cm, m, in, ft. Assume conversion factors 1m == 100cm, 1in == 2.54cm, 1ft == 12in.
  • Read the unit indicator into a string. You may consider 12 m (with a space between the number and the unit) equivalent to 12m (without a space). Keep in mind that cin will read them the same way:
while(cin >> num >> unit) { ... } 
  • After converting, each time through the loop write out the value entered in meters

(3)

  • Reject values without units or with illegal representations of units, such as y, yard, meter, km, and gallons.
  • In this case, output ```Invalid unit " and exit the program

(4)

  • Keep track of the sum of values entered (as well as the smallest and the largest) and the number of values entered.
  • When the loop ends, print
    • the smallest
    • the largest
    • the number of values
    • the sum of values.
    • Note that to keep the sum, you have to decide on a unit to use for that sum; use meters.

(5)

  • Keep all the values entered (converted into meters) in a vector. At the end, write out those values.

(6)

  • Before writing out the values from the vector, sort them (that will make them come out in increasing order).

Sample execution:

1.5m 1.5m The smallest so far The largest so far 1.5cm 0.015m The smallest so far 1.5in 0.0381m 1.5ft 0.4572m Smallest: 0.015, largest: 1.5, total: 2.0103 Values: 0.015 0.0381 0.4572 1.5 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 11G SQL

Authors: Joan Casteel

2nd Edition

1133947360, 978-1133947363

More Books

Students also viewed these Databases questions

Question

2 What participation techniques are used?

Answered: 1 week ago