Questionscs1114 REVIEW of Details Test Closed Laptop Period

Questionscs1114 REVIEW of Details Test Closed Laptop Period

QUESTIONScs1114 REVIEW of details test – closed laptop period

We do not give practice tests.

This is a sample of some of the things that you are responsible for – do not believe that if you know only the things on this test that they will get an A on any real test.

You must know everything that has been covered in lecture, in the text, in the online recitations and in the labs.

The purpose of this exercise to let you learn some of the things you do not know – so you can go out and learn them.

Note that this worksheet does not thoroughly test your problem-solving / programming ability but on the test you will required to write programs and/or short sections of code (code fragments)

1. What is the purpose of variables?

2. State the rules for valid identifiers (what’s an identifier)?

3. What are the 5 arithmetic operators? (symbols and names)

4. State the rules regarding the types of the operands with arithmetic operators (what’s an operand?)

5. State the rules about the value and type of arithmetic expressions (what’s an expression?)

meaning what type is the result depending on the types of the operands

6. What is the type and value of 13 / 7 ?

of 3 + 2 * 8 ?

7. What are precedence and associativity?

8. What is the value stored in x after each of the following assignment statements?

int x;

x = 3.9;

x = -3.9;

9. Given:

double y(7.291842), z(110.4269777);

Display these on the same line each with 4 decimal places in columns that are 12 wide.

[REMOVED]10. Rewrite the previous question using different ways of formatting.

11. Did the code you wrote for the two previous questions change the contents of the variables?

12. Round off the value stored in a double variable named q to 4 decimal places.
Could you use cout.precision(4)or cout < setprecision(4)to accomplish this?

13. Define something for π (use 3.14159 for the value).

[REMOVED]14. Define a variable to be used to store whether or not the user entered the number 5.

[REMOVED]15. If you didn’t initialize the variable in the previous question, why not?
[REMOVED]What value should have been used? Why?

[REMOVED]16. Write the word YES on the screen if the user did enter the number five – do this [REMOVED]using your variable from the previous question.

17. What are the bool values?

18. Can numeric values coerce to bool values? (what’s coercion? what’s casting?)
Give some examples of numeric to bool conversions.

19. List the six relational (comparison) operators.

20. State the type rules or operands with the relational operators..

21. What is the type of an expression involving a relational operator?

22. What is the opposite of ?

23. What is the type and value of 3 != 3 ?

24. List the logical (boolean) operators

25. State the type rules for operands to be used with the logical operators.

26. What is the type of an expression involving a logical operator?

27. What is the type and value of ( 3<4 ) || ( 3 >= 8 )

28. Given:

int x, y;

bool b;

b = ( x < y ) & ( y != 7 );

What is the value of b

if x is 1 and y is 1?

if x is 1 and y is 2?

if x is 1 and y is 7?

29. Using the definitions from the previous question, is this valid C++?

if ( b ) {

30. If r and t are doubles, is r != t always going to produce the result you might expect? Why?

31. What is short circuit evaluation?

32. What is the precedence of ||?

33. Consider the following with and without the parentheses: ((3<4)||(8!=8))&(9>=2)
When does the system stop evaluation subexpressions?

34. Given:

bool a(false), b(true), c(true);
What is the type and value of this expression:a||(b&c)

35. Why is ( 3 < 4 ) == true dumb?

36. What is the value of x = y as a bool value if x contains 2 and y contains 3?

37. Explain why this cannot be called a cout statement. What is really going on?

cout < ;

where is some variable or other expression or calculation or manipulator or string

38. Explain the rules for cin > ;

where is a char variable

where is a string variable.

where is an int variable

where is a double variable.

What is whitespace?

Create your own examples and try them in .NET to check if .NET follows the rules.

How can the cin object be made to allow more input after a FAIL state is entered?

Controlling statements

39. There are four main kinds of statements. We group them as follows:

  • statements that happen once and are done
  • statements that control the execution of other statements
  • looping
  • branching
  • statements that cause execution to jump to another place in the program
  • exceptions (which are not part of this course)

A statement is kind of like an “activity unit” in the execution sequence.

We see it as a Step in the debugger.

Below are all the C++ statements we have covered so far along with some things that are not statements.

Identify which of the categories listed above each statement falls into.
If it is not a statement, say so and explain.

variable definition (with or without initialization) (like int value(5); )

input statement

output statement

x + y

for

while

do while

if

if else

if else if else if … else

if else if else if … else if

switch

return;

return _____; // _____ is some expression

assignment statement (like x=3; or y *= 7;)

else

global const definition

type

scope

block { … }

test (like x <= 4 )

cout statement

cin statement

40. What type must the test be in any controlling statement? The test is the thing inside the ( ) in a controlling statement that is used to make the decision.

41. What are the three looping statements in C++ and when do you use each?

42. What are the branching statements in C++ and when do you use each?
(HINT: there are 5 different kinds of branching statements)

43. Why is this code wrong?

if ( n < 4 )

cout < “blah blah\n”;

if ( n > 4 )

cout < “other blah blah\n”;

if ( n == 4 )

cout < “yet more blah blah\n”;

44. Write the code that asks the user for their birthdate (an int like 27) and prints YES on the screen if their birthdate is the same as yours. Question: what is supposed to happen if their birthdate is not the same as yours? Question: would there be any consts? Question what is a code fragment? On the test if we ask you to write a code fragment or show you a code fragment, do you know what is meant?

45. To thoroughly test your code from the previous question, how many runs of the program would you need to do and what would be the values you need to input when pretending to be the user?

46. What is the output of this code?

NOTE: this is only a code fragment. If you say there is no output because there is not a complete program, you will have earned a ZERO for this question on a test. Assume the rest of the program is there and works. Note that you will not be allowed to type this code into .NET and run it on a test. No computers of any sort – including calculators – are allowed on the tests and final.

for ( int q = 7 ; q > -2 ; q-=3 ) {

for ( int s = q+3 ; s < q+5 ; ++s )

cout < q < " " < s < " " < s/q < endl;

}

47. According to the definition of C++ (not the way MS VC++ .NET might do things) what is the scope of variable q in the last question? That is, what is the scope of a loop variable?

[REMOVED]48. What is the output of this code? What is stored in x after each line of code is executed?

[REMOVED]int x(7);

[REMOVED]cout < x++ < endl;

[REMOVED]cout < x-- < endl;

[REMOVED]cout < x++ < endl;

[REMOVED]cout < --x < endl;

49.

Given the code below and assuming that q contains some meaningful value, write the code to do the following with q: If q is less than or equal to 0, write HELLO 88 times; if q is between 33 and 55 (inclusive), write the word POP followed by the word OOPS 22 times - unless q is 39 or 41; but if q is bigger than 55 and evenly divisible by 5, write the word OUT q times.

int q;
… // q gets a value somehow

// continue writing here

[REPEAT]50.Controlling statements can be grouped in to two basic kinds. What are they and when to [REPEAT]you use each?

[REPEAT]51.Each test - the thing inside the ( ) in a controlling statement - must be of what type?

[REPEAT]52. What are the three looping statements in C++ and when do you use each?

[REPEAT]53. What are the branching statements in C++ and when do you use each (HINT: there are [REPEAT]5 different kinds of branching statements)?

54. Write the code that asks the user for their birthdate (an int like 27) and prints YES on the screen if their birthdate is the same as yours. Question: what is supposed to happen if their birthdate is not the same as yours? Question what is a code fragment? On the test if we ask you to write a code fragment or show you a code fragment, do you know what is meant?

55. To thoroughly test your code from the previous question, how many runs of the program would you need to do and what would be the values you need to input when pretending to be the user?

56. Last Question: What topics, before functions, was not covered in this review?

pg 1 of 5