EXAM 1A – Fall 2017

 

 

A)   (16 points) Show what is printed by the following program:

 

#include<iostream>

using namespace std;

int main()

{

       int officeCapacity = 21;

       int office = 0;

       int workers = 62;

 

       while (workers > 0)

       {

             cout << "Assigning #" << office + 1 << " office\n";

             workers -= officeCapacity;

             if (workers > 0)

                    cout << "Workers left: " << workers << endl;

             office++;

       }

 

      

       return 0;

}

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

 

 

 

B)    (16 points) What is printed by the following code?

 

#include<iostream>

using namespace std;

int main()

{

       bool discountAllowed = true;

       int items = 4;

       double x = 4.5;

 

       if (items > 0 && discountAllowed)

       {

             items = items * 2;

             if (items < 10)

                    discountAllowed = false;

       }

       else if (items > 0)

       {

             items++;

       }

       cout << "Items: " << items << ' ' << items % 3 << ' ' << items / 3 << endl;

       if (!discountAllowed && 6 - 1.5 == x || 6 + x == 0)

             cout << "Good Day!";

       else

             cout << "See you later!";

       system("PAUSE");

       return 0;

}

 

 

 


 

 

C)    (48 points)Short Answer Questions:

 

When asked to write code in this section, do not write full programs.

 

 

a)     Use a loop: Write the C++ code that prints out the numbers from 1 to 100 and their squares (the number raised to the 2nd power).  Your output should be (here are the first four lines, but there are 100 lines in the output):

 

1  1

2  4

3  9

4  16

.

.

.

.

.

 

 

 

 

b)     Write the C++ code (not a full program!!!) that computes a worker’s salary. The code prompts the user for number of hours worked and salary per hour. It prints the total check for the user. If the user works more than 35 hours, the user gets a bonus of $2 for every hour worked. Remember to declare variables

 

 

 

 

 

 

 

 

 

 

 

c)     Write the C++ code that (50 times!) keeps prompting the user to enter an integer!  The code prints out the sum of all the integers that are EVEN.

 

 

 

 

 

 

d)     Given:

 

char letter, code;

 

 

Write the C++ code that prints out "BOTH ARE!" if letter and code both contain upper case letters  (A-Z) in the alphabet. Otherwise, the code prints out: "NO!"

 

 

 

 

 

 

 

 

 

D)   (20  points) Write a full program, including comments, that computes the final cost for a cell phone bill. 

 

AT&T has two choices for unlimited plans: Unlimited Choice and Unlimited Plus. Both unlimited plans allow up to 10 lines. For two lines, the Unlimited Choice plan starts at $125 per month, and Unlimited Plus starts at $155. Each additional line beyond the first two is an extra $20 per month. Federal Universal Service Fund fees are 18.8% (of the total) additional charge.

 

Write code that prompts the user for the plan (choice or plus), and prompts the user for the number of lines. The code prints out the total amount due each month.