Home > Articles > Programming > General Programming/Other Languages

  • Print
  • + Share This
This chapter is from the book


  1. Which of the following are invalid names? Why?

    Int             playNextSong    6_05
    _calloc         Xx              alphaBetaRoutine
    clearScreen     _1312           z
    ReInitialize    _               A$
  2. Based on the example of the car in this chapter, think of an object you use every day. Identify a class for that object and write five actions you do with that object.
  3. Given the list in exercise 2, use the following syntax to rewrite your list in this format:

    [instance method];
  4. Imagine that you own a boat and a motorcycle in addition to a car. List the actions you perform with each of these. Do you have any overlap between these actions?
  5. Based on question 4, imagine that you have a class called Vehicle and an object called myVehicle that could be either Car, Motorcycle, or Boat. Suppose that you write the following:

    [myVehicle prep];
    [myVehicle getGas];
    [myVehicle service];

    Do you see any advantages of being able to apply an action to an object that could be from one of several classes?

  6. In a procedural language such as C, you think about actions and then write code to perform the action on various objects. Referring to the car example, you might write a procedure in C to wash a vehicle and then inside that procedure write code to handle washing a car, washing a boat, washing a motorcycle, and so on. If you took that approach and then wanted to add a new vehicle type (see the previous exercise), do you see advantages or disadvantages to using this procedural approach over an object-oriented approach?
  7. Define a class called XYPoint that will hold a Cartesian coordinate (x, y), where x and y are integers. Define methods to individually set the x and y coordinates of a point and retrieve their values. Write an Objective-C program to implement your new class and test it.
  • + Share This
  • 🔖 Save To Your Account