C++ language. All three parts should be one main program, with each part executing sequentially. Part 1. Ask the user t
Posted: Tue Apr 12, 2022 10:25 am
C++ language. All three parts should be one main program, with
each part executing sequentially.
Part 1.
Ask the user to enter eight integer temperatures. Use getline.
Assume that the user enters only valid data.
Store the temperatures in an integer array. After all eight
temperatures have been entered, display them all
back to the user. Next, compute the average temperature and display
it.
Depending on your logic, you may need two, or three, loops. One
loop reads the temperatures, a second loop
displays them, and a third loop is used to sum them so that you can
compute the average. However, you may
design your logic such that you only require two loops. You could
place the summing in one of the other
loops. There is no need to count the number of temperatures, since
that number is a given – it is 8. Compute
and display the average as a floating point number. Sample
dialog:
Enter temperature 1: 38
Enter temperature 2: 115
Enter temperature 3: -4
...
Enter temperature 8: 45
You entered 38 as temperature 1
You entered 115 as temperature 2
You entered -4 as temperature 3
...
You entered 45 as temperature 8
The average temperature was 47.73
Notice how each input prompt contains the temperature
number, and how the display shows the temperature
number. Make sure your code does this.
Part 2.
Ask the user to enter a list of integer temperatures. Use getline.
You don’t know in advance how many
temperatures will be entered, but it will be at least one and no
more than 100. Store the temperatures in an
integer array. You may assume that the user input will contain only
valid numeric data. The user specifies the
end of the list by entering the word “stop.” When the user enters
stop, display the temperatures, compute
their average, and display it. Compute and display the average as a
floating point number. You may assume
that the user will enter stop before you run out of space in the
array. Sample dialog:
Enter a temperature, or STOP: 42
Enter a temperature, or STOP: 43
Enter a temperature, or STOP: stop
You entered 42
You entered 43
The average temperature is 42.5
Part 3.
GPA calculator. Read a set of input from the console. Use getline.
Input looks like this:
a 4
which indicates a grade of A in a four-hour course. You may assume
that all the input from the user will be
valid:
• The grade will always be in position 0.
• The grade will only be one of a, b, c, d, or f.
• The grade will be followed by one space.
• The hours will be an integer in the range 1-4.
• The user will enter at least one grade/hours combination.
• The maximum number of grade/hours combinations is 10.
The user indicates no more input by entering stop.
At this point, display the entered grades and hours figures, along
with the GPA. Sample session:
GPA Calculator
Enter a grade and number of hours, or stop
a 4
Enter a grade and number of hours, or stop
b 3
Enter a grade and number of hours, or stop
c 2
stop
The grades data you entered were
a 4
b 3
c 2
The GPA is 3.22
The GPA is computed as follows.
Each grade/hours combination must be converted to a number of
“grade points.” To do this, a letter grade
can be considered to have a numeric value. An A has value 4, a B 3,
C 2, D 1, and F zero. Multiply the letter
grade value by the number of hours to get the grade points for that
combination. For example, a B in a four-
hour class would give 12 grade points.
Add up the grade points for all the combinations. To compute the
GPA, divide the grade points by the total
number of credit hours. Try the example above to see how this
works. The GPA should be displayed with at
least two decimal places.
each part executing sequentially.
Part 1.
Ask the user to enter eight integer temperatures. Use getline.
Assume that the user enters only valid data.
Store the temperatures in an integer array. After all eight
temperatures have been entered, display them all
back to the user. Next, compute the average temperature and display
it.
Depending on your logic, you may need two, or three, loops. One
loop reads the temperatures, a second loop
displays them, and a third loop is used to sum them so that you can
compute the average. However, you may
design your logic such that you only require two loops. You could
place the summing in one of the other
loops. There is no need to count the number of temperatures, since
that number is a given – it is 8. Compute
and display the average as a floating point number. Sample
dialog:
Enter temperature 1: 38
Enter temperature 2: 115
Enter temperature 3: -4
...
Enter temperature 8: 45
You entered 38 as temperature 1
You entered 115 as temperature 2
You entered -4 as temperature 3
...
You entered 45 as temperature 8
The average temperature was 47.73
Notice how each input prompt contains the temperature
number, and how the display shows the temperature
number. Make sure your code does this.
Part 2.
Ask the user to enter a list of integer temperatures. Use getline.
You don’t know in advance how many
temperatures will be entered, but it will be at least one and no
more than 100. Store the temperatures in an
integer array. You may assume that the user input will contain only
valid numeric data. The user specifies the
end of the list by entering the word “stop.” When the user enters
stop, display the temperatures, compute
their average, and display it. Compute and display the average as a
floating point number. You may assume
that the user will enter stop before you run out of space in the
array. Sample dialog:
Enter a temperature, or STOP: 42
Enter a temperature, or STOP: 43
Enter a temperature, or STOP: stop
You entered 42
You entered 43
The average temperature is 42.5
Part 3.
GPA calculator. Read a set of input from the console. Use getline.
Input looks like this:
a 4
which indicates a grade of A in a four-hour course. You may assume
that all the input from the user will be
valid:
• The grade will always be in position 0.
• The grade will only be one of a, b, c, d, or f.
• The grade will be followed by one space.
• The hours will be an integer in the range 1-4.
• The user will enter at least one grade/hours combination.
• The maximum number of grade/hours combinations is 10.
The user indicates no more input by entering stop.
At this point, display the entered grades and hours figures, along
with the GPA. Sample session:
GPA Calculator
Enter a grade and number of hours, or stop
a 4
Enter a grade and number of hours, or stop
b 3
Enter a grade and number of hours, or stop
c 2
stop
The grades data you entered were
a 4
b 3
c 2
The GPA is 3.22
The GPA is computed as follows.
Each grade/hours combination must be converted to a number of
“grade points.” To do this, a letter grade
can be considered to have a numeric value. An A has value 4, a B 3,
C 2, D 1, and F zero. Multiply the letter
grade value by the number of hours to get the grade points for that
combination. For example, a B in a four-
hour class would give 12 grade points.
Add up the grade points for all the combinations. To compute the
GPA, divide the grade points by the total
number of credit hours. Try the example above to see how this
works. The GPA should be displayed with at
least two decimal places.