Question

Question 1 The following program asks the user for the current temperature (in Fahrenheit). Provide a...

Question 1

The following program asks the user for the current temperature (in Fahrenheit).

Provide a total of 7 valid test cases (one for each message). Do not provide invalid test

cases.

Add a

series of if statements (if with multiple alternatives i.e. if/else if/else) so that

one

of the

following messages is printed based on the temperature value:

Temperature (F) Message

>90 “Go swimming.”

<=90, >80 “Turn on air conditioning.”

<=80, >70 “Do nothing.”

<=70, >55 “Turn on heat.”

<=55, >30 “Wear a heavy coat.”

<=30, >0 “Wear gloves.”

<=0 “Stay inside, make a fire.”

// Include ALL the compiler directives you need in the program

/* to be filled in*/

using namespace std;

int main()

{

int temperature;

cout << “Please enter the current temperature (F): “;

cin >> temperature;

// add cascading if-else statements to complete the program

/* to be filled in by student */

system(“pause”);

return 0;

}

Test #

Valid / Invalid Data

Description of test

Input Value

Actual Output

Test Pass / Fail

1

Valid

Pass

2

Valid

Pass

3

Valid

Pass

4

Valid

Pass

5

Valid

Pass

6

Valid

Pass

7

Valid

Pass

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ code

============================================================================================

#include<iostream>

using namespace std;

int main()

{

int temperature;

cout << "Please enter the current temperature (F): ";

cin >> temperature;

// add cascading if-else statements to complete the program

/* to be filled in by student */


if(temperature>90)
{
   cout<<"Go swimming.\n";
}
else if(temperature>80)
{
   cout<<"Turn on air conditioning.\n";
}
else if(temperature>70)
{
   cout<<"Do nothing.\n";
}
else if(temperature>55)
{
   cout<<"Turn on heat.\n";
}
else if(temperature>30)
{
   cout<<"Wear a heavy coat.\n";
}
else if(temperature>0)
{
   cout<<"Wear gloves.\n";
}
else
{
   cout<<"Stay inside, make a fire.\n";
}


return 0;

}

============================================================================================

Output

============================================================================================

est #

Valid / Invalid Data

Description of test

Input Value

Actual Output

Test Pass / Fail

1

Valid

91 Go swimming.

Pass

2

Valid

81 Turn on air conditioning.

Pass

3

Valid

71 Do nothing.

Pass

4

Valid

56 Turn on heat.

Pass

5

Valid

31 Wear a heavy coat.

Pass

6

Valid

0 Wear gloves.

Pass

7

Valid

-3 "Stay inside, make a fire.

Pass

Add a comment
Know the answer?
Add Answer to:
Question 1 The following program asks the user for the current temperature (in Fahrenheit). Provide a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Spring 2019/2020 Lab 04: Boolean type and if-statements 1. Write a program that reads four integer...

    Spring 2019/2020 Lab 04: Boolean type and if-statements 1. Write a program that reads four integer numbers, then outputs the maximum number of the four and their average. 2. Write a program to enter a number then state if the number has the following descriptions: • If it is even or odd • if it is a multiple of 8 or not 3. Write a program that enters a temperature and prints an appropriate message according to the following: Temperature...

  • Question 3 Run the following code and explain, using your own words, what is happening with...

    Question 3 Run the following code and explain, using your own words, what is happening with each variable (w,x,y,z) and what is the difference between ++x and w++ (is there any influence on the result between prefix or postfix ++ operator?). Provide a snippet of the output showing the result. int main() { int w = 20, x = 20; int y = 5, z = 5; y = y + (++x); z = z + (w++); cout << "x="...

  • Exercise 5.4 The following program is supposed to convert a temperature in degree Fahrenheit to degree...

    Exercise 5.4 The following program is supposed to convert a temperature in degree Fahrenheit to degree Celsius, but it will not produce the correct result. Use type casting to fix the problem and run the program for the test values. Call your new program ex54.cpp. Test cases: 32 F is 0 C 212 F is 100 C PROGRAM: #include using namespace std; int main( ) {       int t_in_fah, t_in_cel;  //Notice that we declared these two as integers, not the best...

  • This program should be written in C Thoroughly following the Code Conventions, write an efficient program,...

    This program should be written in C Thoroughly following the Code Conventions, write an efficient program, which ask the user for their numeric grade, and determines and displays the equivalent letter grade, based on the following information: Use appropriate data types and initialize the variables correctly Use the following grading scale: A: 90 - 100 B: 80 - < 90 C: 70 - < 80 D: 60 - < 70 F: 0 - < 60 If the input is invalid,...

  • Write a C++ program that will provide a user with a grade range if they enter...

    Write a C++ program that will provide a user with a grade range if they enter a letter grade. Your program should contain one function. Your function will accept one argument of type char and will not return anything (the return type will be void), but rather print statements to the console. Your main function will contain code to prompt the user to enter a letter grade. It will pass the letter grade entered by the user to your function....

  • program. 13. What's the output of the following program? #include< iostream> #include&math> using namespace std; int...

    program. 13. What's the output of the following program? #include< iostream> #include&math> using namespace std; int p 7; void main) extern double var int p abs(-90); system( "pause"); double var = 55; 14. How many times does "#" print? forlint i 0;j< 10; +ti) if(i-2141 6) continue; cout<< "#"; 15. Write the function declaration/prototype for a, pow function b floor function 16. State True or False a. b. c. d. e. isupper function returns a double value for loop is...

  • Question 4: Provide at least 4 test cases. Prompt the user to input 3 doubles, a,...

    Question 4: Provide at least 4 test cases. Prompt the user to input 3 doubles, a, b and c. Which will represent the coefficients in the quadratic equation ax2 + bx + c = 0. Print out the solutions (if any) of the quadratic equation. If no root exists (this happens if a == 0, or b2 <4ac) print the message No real root. Sample input/ user entries shown in red Corresponding output Enter a, b and c which represent...

  • This program will take the user's input as a temperature in degrees Fahrenheit. The user will...

    This program will take the user's input as a temperature in degrees Fahrenheit. The user will then click a radio button indicating whether a table of temperatures, starting with the entered value, will be displayed in increments of 5 degrees F or 10 degrees F. When a submit button is clicked your code will display a HTML table of temperature values. The first column will be temperatures in degrees Fahrenheit, given in increments of 5 or 10 degrees F, depending...

  • Assignment Develop a program to analyze one or more numbers entered by a user. The user...

    Assignment Develop a program to analyze one or more numbers entered by a user. The user may enter one or more numbers for analysis. Input should be limited to numbers from 1 through 1000. Determine if a number is a prime number or not. A prime number is one whose only exact divisors are 1 and the number itself (such as 2, 3, 5, 7, etc.). For non-prime numbers, output a list of all divisors of the number. Format your...

  • I need help with the following assignment: Write an application named DailyTemps that continuously prompts a...

    I need help with the following assignment: Write an application named DailyTemps that continuously prompts a user for a series of daily high temperatures until the user enters a sentinel value of 999. Valid temperatures range from -20 through 130 Fahrenheit. When the user enters a valid temperature, add it to a total; when the user enters an invalid temperature, display the error message: Valid temperatures range from -20 to 130. Please reenter temperature. Before the program ends, display the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT