Skill Building Exercises

 < Day Day Up > 



  1. Disassembly: Write a short program that adds two integer literals together and assigns the result to an integer variable. Disassemble the program and study the resulting output.

  2. Fundamental Type Sizes: Write a program demonstrating the use of the sizeof operator and calculate the sizes of all the fundamental data types for your development environment.

  3. Fundamental Type Value Ranges: Write a program demonstrating the use of the numeric_limits template class and calculate the range of values of all the fundamental data types for your development environment.

  4. Hex To Binary Conversion: Convert the following hexadecimal numbers to binary:
    0xD3F45C88
    0x864EE701
    0xAAFFAAFF
    0x37808978
    0xA1E5A1E5

  5. Decimal to Binary Conversion: Convert the following decimal numbers to binary. Indicate the smallest C++ data type necessary to represent the value:
    34 (ASCII)
    -246
    32,746
    124,256
    4, 294,967,295

  6. Multiple Character Literals: What integer value does the character literal ‘Stop’ represent?

  7. Operator Usage: Write a program that demonstrates the use of each of the following operators: postfix ++ and prefix ++, postfix and prefix --, *, /, %, +, -, <<, >>, <, >, <=, >=, ==, !=, &, ^, |, &&, ||, ?:, *=, /=, %=, +=, -=, >>=, <<=, &=, ^=, |=.

  8. Exiting main(): Write three short programs demonstrating how to exit the main() function using 1) a return statement, 2) the exit() function, and 3) the exit() function with a clean-up function registered with the atexit() function.

  9. Variable Scoping and Linkage: Write a short, two-file program demonstrating the following aspects of variable scoping and linkage and answer the associated questions:
    -Declare an integer variable named shared_global in one file and redeclare it with the extern keyword and use it in the other file. What effect does using the variable in each file have on the value of the variable?
    -Declare an integer variable named file_global in both files using the static keyword. What effect does using this variable in each file have on the value of the variable?
    -In the body of the main() function declare and initialize an integer variable named var1. Print its value to the screen using the cout object.
    -Below the cout statement declare a local block using the braces { }, and print the variable again using the cout object. Did its value change? Explain why or why not.
    -In the local block, below the cout statement, redeclare and initialize to a different value from the original, the variable var1. Print var1 to the screen using the cout object. Did its value change? Explain the results.
    -Is there a way to access the original var1 variable from within the local block?

  10. IOStream Input and Output: Write a short program demonstrating simple iostream input and output using the cin and cout objects. Declare a few variables of various types and set their values via the keyboard using the cin object. Use the technique shown in this chapter to catch bad input. Print the contents of each variable to the screen using the cout object.



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net