1. Rewrite the following if-else chain by using a switch statement:
if (factor == 1)
pressure = 25.0;
else if (factor == 2)
pressure = 36.0;
else if (factor == 3)
pressure = 45.0;
else if ((factor == 4) || (factor == 5) || (factor == 6))
pressure = 49.0;

2. Explain why for the following program it is not possible to rewrite the if/else statement as a switch statement.
int main()
int digout;
double inlbs;

cout << "Enter the input weight: ";
cin >> inlbs;

if (inlbs < 60)
digout = 1011;
else if (inlbs >= 60)
digout = 1100;
else if (inlbs >= 70)
digout = 1101;
else if (inlbs >= 80)
digout = 1110;
else if (inlbs >= 90)
digout = 1111;

cout << "The digital output is " << digout << endl;
return 0;

3. Write out the output of the following code snippet. Briefly describe the affect that the continue has on the loop.

int i;
for (i = 0; i < 14; i++)
if ((i % 4) == 0)

cout << i << ", ";
cout << endl;

4. Follow the instructions for each problem below involving arrays:
a. Declare an array of 150 doubles representing samples in a graph. Set the first sample 4.23. Then print the value of the first sample to the console.
b. Declare an array of 25 characters representing a password. Set the last character of the password to the literal ‘a’.
c. Declare an array of 9 integers representing a runs for each baseball inning. Using a for loop, set each inning to be the value zero.

5. (Upload as a Source File) Write a program that stores the following resistance values in an array named resistance 16, 27, 39, 56, and 81. Your program should also create two arrays named current and power, each capable of storing five double-precision numbers. Using a for loop and a cin statement, have your program accept five user-input numbers in the current array when the program is run. Your program should store the product of the values of the squares of the current array and the resistance array in the power array. For example, use power[1] = resistance[1] * current[1] * current[1]. Your program should display the following output (fill the chart):

Resistance Current Power

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

1. Answer
case 1:
pressure = 25.0;
case 2:
pressure = 36.0;
case 3:
pressure = 45.0;
case 4:
case 5:
case 6:
pressure = 40.0;
$40.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Visual Basic Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats