Skill Building Exercises

 < Day Day Up > 



  1. typedef: Use the typedef specifier to declare synonyms for the integer or float data types better suited to model data from the domains below. For example, if the domain is Banking, and the data to model is Currency, then you could create a type synonym with typedef in the following manner;

    typedef float Currency;

    Domain

    Data to Model

    Banking

    Currency, Transactions

    Physics

    Speed, Time, Velocity, Acceleration

    Computers

    Operand, Opcode, Instruction

    Chemistry

    Molecules

    Writing

    Words, Paragraphs, Sentences

    Census

    Population

    Government

    Laws, Statutes

    Plumbing

    Fixtures

  2. enum: a. Write the declaration for an enumerated type named Direction and give it the state values North, North- East, East, South-East, South, South-West, West, & North-West. b. Write the declaration for an enumerated type named PenPosition and give it the state values Down and Up.

  3. enum: a. Write the declaration for an enumerated type named Safety and give it the state values Safe and Armed. Assign Safe the value 1 and Armed the value 2.

  4. structures: Give the declaration for a structure named BlockType that contains the following data members: An array of 15 characters named Model, and two floats named height and width.

  5. structures: Give the declaration for an Employee structure containing the following data members: Two character arrays of length 26 named employee_f_name and employee_l_name, a float member named pay_amount, and six functions named setEmployeeFirstName, setEmployeeLastName, getEmployeeFirstName, getEmployeeLastName, setEmployeePayAmount, and getEmployeePayAmount. Declare the data members private and the member functions public.

  6. structures: Give the declaration for a structure named RobotRat containing the following data members: Two ints named row and col, an enumerated type variable named pen_position, and another enumerated type variable named direction. The enumerated types for these variables were declared in Skill Building Exercise 2.

  7. Array of structures: Using the Employee structure declared in skill building exercise 5, write a program that declares an array of five employees and use each function to set the data members of each employee. Use a for loop to add up all the employee pay amounts and print the value to the screen.

  8. Array of pointers to structures: Convert the array program you wrote in the previous exercise to use pointers to Employee objects. Dynamically create six Employees and call the functions to set their attributes. Sum the total of their pay as you did before.

  9. classes: Convert the Employee structure to a class and rebuild your program. What changes did you have to make to get it to compile and run?

  10. Array of classes: Convert the array of Employee structs program you wrote in exercise 7 to an array of Employee classes. What changes, if any, did you have to make to the program?



 < 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