|
|
 |
|
|
|
|
return someShort; |
|
|
|
|
|
|
|
|
14. Active error detection leaves error hunting to C++ and the operating system, whereas passive error detection requires the programmer to do the error hunting. (True or False?) |
|
|
|
|
|
|
|
|
Programming Warm-Up Exercises |
|
|
|
|
|
|
|
|
1. Find out the maximum and minimum values for each of the C++ simple types on your machine. On most systems, these values are declared as named constants in the files limits.h and float.h in the standard include directory. |
|
|
|
|
|
|
|
|
2. Using a combination of printable characters and escape sequences within one string, write a single output statement that does the following in the order shown: |
|
|
|
 |
|
|
|
|
Prints Hello |
|
|
|
 |
|
|
|
|
Prints a (horizontal) tab character |
|
|
|
 |
|
|
|
|
Prints There |
|
|
|
 |
|
|
|
|
Prints two blank lines |
|
|
|
 |
|
|
|
|
Prints Ace (including the double quotes) |
|
|
|
|
|
|
|
|
3. Write a While loop that copies all the characters (including whitespace characters) from an input file inFile to an output file outFile, except that every lowercase letter is converted to uppercase. Assume that both files have been opened successfully before the loop begins. The loop should terminate when end-of-file is detected. |
|
|
|
|
|
|
|
|
4. Given the following declarations |
|
|
|
 |
|
|
|
|
int n;
char ch1;
char ch2; |
|
|
|
 |
|
|
|
|
and given that n contains a two-digit number, translate n into two single characters where ch1 holds the higher-order digit, and ch2 holds the lower-order digit. For example, if n = 59, ch1 would equal 5, and ch2 would equal 9. Then output the two digits as characters in the same order as the original numbers. (Hint: Consider how you might use the / and % operators in your solution.) |
|
|
|
|
|
|
|
|
5. In a program you are writing, a float variable beta may potentially contain a very large number. Before multiplying beta by 100.0, you want the program to test whether it is safe to do so. Write an If statement that tests for a possible overflow before multiplying by 100.0. Specifically, if the multiplication would lead to overflow, print a message and don't perform the multiplication; otherwise, go ahead with the multiplication. |
|
|
|
|
|
|
|
|
6. Declare an enumeration type for the course numbers of computer courses at your school. |
|
|
|
|
|
|
|
|
7. Declare an enumeration type for the South American countries. |
|
|
|
|
|
|
|
|
8. Declare an enumeration type for the work days of the week (Monday through Friday). |
|
|
|
|
|
|
|
|
9. Write a value-returning function that converts the first two letters of a work day into the type declared in Exercise 8. |
|
|
|
|
|
|
|
|
10. Write a void function that prints a value of the type declared in Exercise 8. |
|
|
|
|
|