Name:CIS 1.5 Midterm

1.
4 points

Declare the following variables and set their values:

weight is 200

temperature is 98.6

2.
8 points

Draw the following flow chart to train a new employee checking IDs at the entrance of a club :

Ask a person entering the club for their ID.

If they have ID that shows they are over 21, let them enter the club.

Otherwise if their ID shows they are under 21 or they do not have ID, they cannot enter the club.

For questions 3 through 11:

7 points each

What are the outputs from the following blocks of code:

3.

int i = 1;

i--;

cout < i < endl;

i=10;

i+=5;

cout < i < endl;

4.

int a=10;

if(a%2==0) {

cout < "yeah" < endl;

a=5;

}

if(a==5)

cout < "sushi" < endl;

cout < a < endl;

5.

The following inputs are entered: 20 15 3

int x,y;

x=1;

while(x<=3) {

cin > y;

if(y<5)

cout < "pizza" < endl;

else if (y==15)

cout < "salad" < endl;

else

cout < "noodles" < endl;

x++;

}

cout < "x is " < x < endl;

6.

int x=5, y=10;

if(x==10 & y==5)

cout < "hey" < endl;

if(x==5 || y==5)

cout < "free" < endl;

if(y!=10)

cout < "den" < endl;

if(y!=5)

cout < "frog" < endl;

if(x==5 & y!=10 || x==5)

cout < "fred" < endl;

7.

int i;

for (i=30; i>5; i = i-5)

cout < i < endl;
cout < "after: " < i < endl;

8.

int i;

i = 2;

do

{

cout < i < endl;

i = i + 2;

}

while (i <9);

9.

Read the lines carefully!

int x = 1;

char c;

while(x<=10) {

switch ( x ) {

case 1:

c = 'A';

x=5;

break;

case 2:

case 3:

c = 'B';

break;

case 4:

case 5:

c = 'C';

x=10;

break;

default:

c = 'E';

x=11;

break;

}

cout < "Letter: " < c < endl;

}

10.

Read the lines carefully!

int main() {

int i=5,k=25;

while(i<=7) {
k-=i;
cout < i < " " < k < endl;
if(k-i>=10) {
cout < "Cherry" < endl;
}

if(i-k==0) {
cout < "Pear" < endl;
}
else {
cout < "Orange" < endl;
}
i++;

}

}

11.

for(int i=2; i<=10;i+=3){

cout < "Flip: ";

if(i%2==0 & i>=6)

cout < i < " Heads" < endl;

if(i==2 || i<=7)

cout < i < " Tails" < endl;

}

5 Points

Write a C++ style comment listing your name and the current year.

15.

20 points

PLEASE WRITE NEATLY!

Write a complete program from scratch. All the proper include lines, namespace, etc. The program should do the following:

A group of elementary students have an advanced lemonade stand. They have a laptop computer that will keep track of the number of cups for each sale and the amount of money for each sale. At the end, save the total number of cups sold and total amount of cents to the file.

Open a file called results.txt to be written to. Assume the file will be created without error. This will store the results of the lemonade orders.

Lemonade costs 25 cents per cup.

The program will

  1. Ask the customer how many cups of lemonade they would like to buy. They can buy any amount they wish that is greater than 0. Ignore a 0 input value.

●Entering a negative number will cause the program to save the total amount sold and then exit.

  1. Store in results.txt the amount or cups that a customer bought, and the amount of the sale.
    Only enter in positive numbers, greater than 0. Do not say -1 cups sold, for example.

For example:

1 cup, 25 cents

2 cups, 50 cents

3 cups, 75 cents

4 cups, 100 cents

5 cups, 125 cents

etc, etc.

  1. Repeat steps 1 and 2 until a negative number has been entered.
  2. After the person is no longer enters in cups sold. Save the total amount of cups and total amount of cents collected to the file.

●Total cups: 10Total cents: 250

  1. Make sure to close the file when you are done with it.
  2. Exit the program.

1 of 8