Saturday, 11 January 2014

CHAPTER 2—C++ PROGRAMMING BASICS

Questions:
----------
1. Dividing a program into functions 
a. is the key to Object-Oriented Programming. 
b. makes the program easier to conceptualize. 
c. may reduce the size of the program. 
d. makes the program run faster. 
2. A function name must be followed by ________. 
3. A function body is delimited by ________. 
4. Why is the main() function special? 
5. A C++ instruction that tells the computer to do something is called a ________. 
6. Write an example of a normal C++ comment and an example of an old-fashioned /* comment. 
7. An expression 
a. usually evaluates to a numerical value. 
b. indicates the emotional state of the program. 
c. always occurs outside a function. 
d. may be part of a statement. 
8. Specify how many bytes are occupied by the following data types in a 32-bit system: 
a. Type int 
b. Type long double 
c. Type float 
d. Type long 
9. True or false: A variable of type char can hold the value 301. 
10. What kind of program elements are the following? 
a. 12 
b. ‘a’ 
c. 4.28915 
d. JungleJim 
e. JungleJim() 
11. Write statements that display on the screen 
a. the character ‘x’. 
b. the name Jim. 
c. the number 509. 
12. True or false: In an assignment statement, the value on the left of the equal sign is always equal to the value on the right. 
13. Write a statement that displays the variable george in a field 10 characters wide. 
14. What header file must you #include with your source file to use cout and cin? 
15. Write a statement that gets a numerical value from the keyboard and places it in the variable temp. 
16. What header file must you perform #include with your program to use setw? 
17. Two exceptions to the rule that the compiler ignores whitespace are ________ and ________. 
18. True or false: It’s perfectly all right to use variables of different data types in the same arithmetic expression. 
19. The expression 11%3 evaluates to ________. 
20. An arithmetic assignment operator combines the effect of what two operators? 
21. Write a statement that uses an arithmetic assignment operator to increase the value of the variable temp by 23. Write the same statement without the arithmetic assignment operator. 
22. The increment operator increases the value of a variable by how much? 
23. Assuming var1 starts with the value 20, what will the following code fragment print out? 
cout << var1--;
cout << ++var1;
24. In the examples we’ve seen so far, header files have been used for what purpose? 
25. The actual code for library functions is contained in a ________ file.
__________

No comments:

Post a Comment