Home > Articles > Programming > General Programming/Other Languages

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

This chapter is from the book

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

  2. Int playNextSong    6_05
    _calloc Xx alphaBetaRoutine
    clearScreen _1312 z
    ReInitialize _    A$
  3. 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.

  4. Given the list in exercise 2, use the following syntax:

  5.    [instance method];

    to rewrite your list in this format.

  6. Imagine that you owned a boat and a motorcycle in addition to a car. List the actions you would perform with each of these. Do you have any overlap between these actions?

  7. Based on question 4, imagine you had a class called a Vehicle and an object called myVehicle that could be either a Car, a Motorcycle, or a Boat. What if you wrote the following:

  8. [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?

  9. 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?

  10. Define a class called Point 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