Skill Building Exercises

 < Day Day Up > 



  1. if statements: Write a program that declares two integer variables, a and b, initialized to values of your choice. In this program write ten if statements that use the following conditions:

    (a <= b)

    !(b == a)

    (3 < a) && (3 < b)

    (a || b)

    (((++a) == (--b)) || b)

    (a ^ b)

    ((a && b && (!0)) || true)

    (b == 10)

    (int c = b)

    (a || (!b))

    Disassemble your source code and examine how each if statement and its condition is implemented in assembly.

  2. if-else statement: Write a program that declares two char variables, a and b, and initialize them both to ‘ ‘. Write ten if-else statements using the following condition expressions:

    (a = ‘y’)

    (a == ‘Y’)

    (!(b = ‘n’))

    (b == ‘n’)

    (‘c’ <= b)

    ((‘A’ <= a) && (a <= ‘Z’))

    (a == b)

    (a != b)

    ((b >= a) || (a <= ‘1’))

    (a && b && ‘0’)

  3. nested if-else statements: Write a program using nested if-else statements that reads character input from the keyboard one character at a time and performs the following operations:

    • if the input is ‘1’ through ‘5’, add 1 to the character value and print the resulting character to the screen,

    • if the input is ‘6’ through ‘9’, add 5 to the character value and print the resulting character to the screen,

    • if the input is ‘a’ through ‘z’, convert to upper case and print to the screen,

    • if the input is ‘A’ through ‘Z’, convert to lower case and print to the screen.

  4. switch statement: Rewrite exercise three above using a switch statement.

  5. while statement: Add a while statement to the code you wrote in exercise four to repeatedly process keyboard input. Use a sentinel value to terminate the loop.

  6. do-while statement: Use do-while statements to calculate the following: Prompt the user for the value of n.

  7. for statement: Rewrite exercise 6 using for statements.



 < 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