Question

In: Computer Science

I am having a lot of difficulty on problem 2 I dont know how to use...

I am having a lot of difficulty on problem 2 I dont know how to use switch.

Branching and looping

Objectives:

1. Write a program that uses branching and a while loop. 2. Using boolean expressions and primitive variable types.

Note: if you don’t have a laptop, work with another person. When you are done with the exercise, show your TA that you both worked on the assignment together and you will both get credit for the work.

Problem 1:

Name your program Lastname_firstname_Recitation3_1.cpp.

For this recitation exercise, you are going to write a program to prompt the user for the height of a building in feet (ft).
Then, use the height to print out the name of the building and its height ranking using the following information:

Rank Height (in ft)

1 714

2 709

3 698

Building name Republic Plaza
1801 California Street Wells Fargo Center

The program should check the input with the information provided in the table above and print the name and ranking accordingly. If the input does not match any of the above mentioned heights then print out ​“Height does not match that of the three tallest buildings in Denver. Please enter a correct height. Would you like to try again? Enter Y/N”​. If the user enters Y (yes), then prompt the user for the height of a building in feet (ft). If the user enters N (no), then exit out of the program.(Use a While loop)

Output:
714 ft is the height of Republic Plaza. It is the tallest building in Denver.

Or,
709 ft is the height of 1801 California Street. It is the second tallest building in Denver.

Or,
698 ft is the height of Wells Fargo Center. It is the third tallest building in Denver.

Or,
Height does not match that of the three tallest buildings in Denver. Please enter a correct

height. Would you like to try again? Enter Y/N.

Problem 2:

Name your program Lastname_firstname_Recitation3_2.cpp.

So you would have used the if and else statements in Problem 1 to achieve the desired output. For Problem 2 you need to make a small change which shows the implementation of switch statement to achieve the same output as in problem 1.

switch( controlling expression ) {

case Constant_1: Statement_Sequence_1;

break; case Constant_2:

Statement_Sequence_2;

break; ...

case Constant_n: Statement_Sequence_n;

break; default:

Default_Statement_Sequence;

}

To get credit for this lab exercise:

▪ Please zip both the files and submit your Lastname_firstname_Recitation3.zip file to Moodle under the ‘Recitation 3 Submit’ link.

▪ Show the TA your code and run your program before leaving the classroom.

Solutions

Expert Solution

// C++ code
#include <iostream>
using namespace std;


int main( )
{
    int height;
    char again;

    // WHile loop
    // PROGRAM 1
    while(true)
    {
        cout << "\nEnter Height: ";
        cin >> height;

        if(height == 714)
            cout << "714 ft is the height of Republic Plaza. It is the tallest building in Denver.\n\n";
        else if(height == 709)
            cout << "709 ft is the height of 1801 California Street. It is the second tallest building in Denver.\n\n";
        else if(height == 698)
        cout << "698 ft is the height of Wells Fargo Center. It is the third tallest building in Denver.\n\n" ;
        else
        cout << "Height does not match that of the three tallest buildings in Denver.\nPlease enter a correct height.\n\n";

        cout << "Would you like to try again? Enter (Y/N): ";
        cin >> again;

        if(again == 'N' || again == 'n')
            break;
    }

    // WHile loop
    // PROGRAM 2
    while(true)
    {
        cout << "\nEnter Height: ";
        cin >> height;

        switch (height)
        {
            case 714:
                cout << "714 ft is the height of Republic Plaza. It is the tallest building in Denver.\n\n";
                break;
            case 709:
                cout << "709 ft is the height of 1801 California Street. It is the second tallest building in Denver.\n\n";
                break;
            case 698:
                cout << "698 ft is the height of Wells Fargo Center. It is the third tallest building in Denver.\n\n" ;
                break;
            default:
                cout << "Height does not match that of the three tallest buildings in Denver.\nPlease enter a correct height.\n\n";
                break;
        }

        cout << "Would you like to try again? Enter (Y/N): ";
        cin >> again;

        if(again == 'N' || again == 'n')
            break;
    }
  

    return 0;
}


/*
output:

Enter Height: 768
Height does not match that of the three tallest buildings in Denver.
Please enter a correct height.

Would you like to try again? Enter (Y/N): y

Enter Height: 709
709 ft is the height of 1801 California Street. It is the second tallest building in Denver.

Would you like to try again? Enter (Y/N): y

Enter Height: 714
714 ft is the height of Republic Plaza. It is the tallest building in Denver.

Would you like to try again? Enter (Y/N): y

Enter Height: 698
698 ft is the height of Wells Fargo Center. It is the third tallest building in Denver.

Would you like to try again? Enter (Y/N): n

*/


Related Solutions

I am having difficulty figuring out the rest of this problem, primarily with regards to calculating...
I am having difficulty figuring out the rest of this problem, primarily with regards to calculating APIC and Retained earnings for Stock Dividends. Also, I need assistance with the fourth problem, how to calculate the total value of shareholders' equity. Could you please help show me how to solve? Accounting for Share Transactions The shareholders' equity section of the consolidated balance sheet of Wilson Industries appeared as follows at the beginning of the year: Shareholders' Equity Class A common stock,...
These are the correct answers but I am having difficulty figuring out how these figures were...
These are the correct answers but I am having difficulty figuring out how these figures were reached. On March ​1, 2018​, Nailtique Nail Salons issued $450,000 of 15​-year, 5 percent bonds payable. The bonds were sold for $432,000. The bonds pay interest each August 31 and February 28​, and any discount or premium is amortized using​ straight-line amortization. Requirement 1. Fill in the blanks to complete each statement. a. Nailtique Nail Salons' bonds are priced at (express the price as...
I am having difficulty with this problem. My break-even point in dollar sales totals appears to...
I am having difficulty with this problem. My break-even point in dollar sales totals appears to be off by several hundred dollars.   Pittman Company is a small but growing manufacturer of telecommunications equipment. The company has no sales force of its own; rather, it relies completely on independent sales agents to market its products. These agents are paid a sales commission of 14% for all items sold. Barbara Cheney, Pittman’s controller, has just prepared the company’s budgeted income statement for...
I'm having trouble figuring out the constraints to this problem. I know that I am maximizing...
I'm having trouble figuring out the constraints to this problem. I know that I am maximizing 55x + 45y, however the variables are throwing me off. I only need help on question #1 as it would be a great help to understanding the rest of what the questions are asking. The problem is as follows: NorCal Outfitters manufactures a variety of specialty gear for outdoor enthusiasts. NorCal has decided to begin production on two new models of crampons: the Denali...
Hi, I am having a little difficulty understanding how an auditor would test the Inventory and...
Hi, I am having a little difficulty understanding how an auditor would test the Inventory and Warehousing Cycle. What is the difference (Audit Objectives) between substantive tests of transactions for inventory and tests of balances for inventory? How would an auditor use the transaction related objectives to perform Substantive tests of transactions in Inventory? How would that differ from Tests of Details of balances (balance related objectives) in inventory with examples? Thank you so much as I am a little...
Hello, I am having difficulty with this assignment. I chose Amazon as my stock, but I...
Hello, I am having difficulty with this assignment. I chose Amazon as my stock, but I am confused on what they're asking :             Choose a stock that interests you. Utilizing Bloomberg (or other financial websites) as a source of data, collect the following      information:                         a. The stock’s Beta                         b. The rate of return on the market (S&P 500 Index)                         c. The risk-free rate (rRF)                         d. The last dividend paid (D0)...
I am having a little difficulty understanding how E&P applies to the tax law and where...
I am having a little difficulty understanding how E&P applies to the tax law and where it is used on the tax return. I read that E&P has been included in the tax code since 1916, but if it includes income that is typically nontaxable, what is it used to calculate in the tax return?  
I am trying to solve this problem, but I don't know which test to use: For...
I am trying to solve this problem, but I don't know which test to use: For average risk funds only, test the proportion of funds with Sales Charges is not 50% use α = 0.10. Explain your conclusion. Here is the contingency table with the data: Sales charge Yes No total Risk Low 6 8 14 Avg 42 34 76 High 24 23 47 Total 72 65 137 Context of the problem: Mutual funds are the most common way people...
Hi I am having the following problem. At the moment I am trying to create a...
Hi I am having the following problem. At the moment I am trying to create a bode plot for the following function. G(s)=(Ks+3)/((s+2)(s+3)) Note: Not K(s+2)! I then want to plot multiple bode plots for various values of K. Eg. 1,2,3, etc. I am having two separate issues. 1. How do I define the TF with a constant K in the location required (a multiple of s in the numerator) 2. How do I create multiple bode plots for values...
Hi there, I am having difficulty with the attached homework question. If you guys could please...
Hi there, I am having difficulty with the attached homework question. If you guys could please help work through the steps. My balance sheet isn't balancing :/ These financial statement items for Fairview Corporation at year-end, July 31, 2017. Salaries and wages payable $2,080 Salaries and wages expense 57,500 Supplies expense 15,600 Equipment 18,500 Accounts payable 4,100 Service revenue 66,100 Rent revenue 8,500 Notes payable (due in 2020) 1,800 Common stock 16,000 Cash 29,200 Accounts receivable 9,780 Accumulated depreciation-equipment 6,000...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT