Chapter 1 Exercises

Chapter 1  Introduction to Object-Oriented Programming   After-Class Exercises

1. Explanation of terms

1. Abstraction: Abstraction is to ignore the non-essential features of things that are not related to the current goal, and emphasize the essential features related to the current goal, so as to find out the commonality of things, and classify the common things into one category to obtain an abstraction. concept.

2. Encapsulation: Encapsulation in object-oriented methods is to combine the attributes and behaviors of the abstracted objects into an independent unit, and to hide the internal details of the object as much as possible

3. Message: Message is a mechanism designed by object-oriented programming to describe the communication between objects. A message is a request from one object to another object to perform some operation.

2. Fill in the blanks

( 1 ) At present, there are two important programming methods: process-oriented structured programming method and object-oriented programming method.  

( 2 ) The modules in the structured programming method are composed of three basic structures of sequence , selection and circulation .

( 3 ) In the structured programming method, the program can be expressed as program = data structure + algorithm ; while in the object-oriented programming method, the program can be expressed as program = object + message.

( 4 ) The basic module in the structured programming method is the procedure ; while the basic module in the object-oriented programming method is the class .

( 5 ) Object-oriented programming method has the characteristics of abstraction, encapsulation, inheritance and polymorphism.

Three, multiple choice

( 1 ) Object-oriented programming focuses on the design of ( B ).

    A. Object         B. Class         C. Algorithm         D. Data

( 2 ) In object-oriented programming, the mechanism for organizing the properties and behaviors of objects in the same module is called ( C )

   A. Abstraction          B. Inheritance      C. Encapsulation         D. Polymorphism

( 3 ) In object-oriented programming, classes are related to the outside world through ( D ).

   A. Object          B. Class         C. Message         D. Interface

( 4 ) In object-oriented programming, the communication mechanism between objects is ( C )

   A. Object          B. Class         C. Message         D. Interface

( 5 ) In the description of the relationship between C++ and C language, ( D ) is wrong.

  AC language is a subset of                C++ and BC language is compatible with C++

  C.C++ makes some improvements to      C. D.C ++ and C are both object-oriented

( 6 ) Object-oriented programming treats data structures together with ( A ) as an interdependent, indivisible whole.

  A. Algorithms               B. Information                 C. Data hiding                  D. Data abstraction

( 7 ) The following ( A ) are not elements of an object-oriented system.

  A. Overloading               B. Object                  C. Class                           D. Inheritance

( 8 ) The following statement is correct ( BC ).

A. Putting data structures and algorithms in the same function is data encapsulation

B. A class can acquire the characteristics of another class through inheritance

C. Object-oriented requires programmers to focus on the essential characteristics of things and look at programs from an abstract point of view

D. When the same message is received by different objects, the resulting behavior is the same, which is called consistency

( 9 ) The following statement is correct ( AD ).

A. An object is an area of ​​computer memory that can hold code and data

B. The object is actually a program with relatively independent functions

C. The data can be shared among the various objects is a major advantage of the object

D. In an object-oriented program, objects can only communicate with each other through messages

Fourth, judgment questions

( 1 ) In high-level programming languages, classes are generally used to implement objects. A class is a collection of objects with the same properties and behaviors, and it is a template for creating objects. ( right )

( 2 ) C++ language only supports the abstraction, encapsulation, inheritance and other characteristics of object-oriented technology, but not polymorphism. ( wrong )

( 3 ) Messages in object-oriented programming should contain "how to" information. ( wrong )

( 4 ) A message can only produce a specific response effect. ( wrong )

( 5 ) The design of the class and the inheritance mechanism of the class realize the reusability of the software module. ( right )

( 6 ) Neither C++ language nor Java language is a pure object-oriented programming language. (wrong)

( 7 ) Learning C++ language is the only way to learn object-oriented programming method. ( wrong )

( 8 ) In the C++ language, classes are tools that support data encapsulation. ( right)

5. Short answer questions

(1) What is the structured programming method? What are its advantages and disadvantages?

Answer: The structured programming method focuses on the functions to be implemented by the system, starting from the input and output of the system, analyzes what the do, and then considers how to do these things, and decomposes the functions of the system from the top to the bottom. The functional structure of the system and the corresponding program module structure are established, and a relatively complex program system design task is effectively decomposed into many sub-tasks that are easy to control and process, which is convenient for development and maintenance. With the growth of program size and complexity, this process-oriented structured programming approach has obvious deficiencies. The first is the issue of data security. Since the data is shared by each module, it is insecure. Once an error occurs, it is difficult to find out the reason. The second is poor maintainability and reusability. It separates the data structure and the algorithm into independent entities. Once the data structure needs to be changed, the entire program is often involved. The workload of modification is huge and new errors are easily generated. Every new approach to an old problem brings additional overhead. In addition, the application program of the GUI is difficult to describe and realize by the process, and it is also difficult to develop and maintain.

(2) What is the object-oriented programming method? What are its advantages?

 Answer: In object-oriented programming, the program is designed as a set of cooperating objects rather than a set of cooperating functions. In a program, attributes are represented by data and used to describe the static characteristics of objects; behaviors are implemented by program code and used to describe the dynamic characteristics of objects. It can be seen that in the object-oriented programming method, the object is the encapsulation . There are various connections between objects, and they communicate through messages. A program can be expressed as: program = object + message In object-oriented programming, it focuses on the design of classes. The class is the basic program module of the object-oriented language, through the design of the class, to complete the entity modeling task. A class communicates with the outside world through a simple external interface. Operations in one class will not process data in another class, so the independence of program modules and data security are well guaranteed. The execution of the program depends on the sequence of events, and the sequence of messages drives the execution of the program. It is not necessary to predetermine the sequence of message generation, which is more in line with the reality of the objective world. And object-oriented programming method provides an effective way to reuse software, solve big and complex problems, and has the characteristics of abstraction, encapsulation, inheritance and polymorphism.

(3) What is the difference between the structured programming method and the object-oriented programming method in treating the relationship between data structures and algorithms?

 Answer: In the structured programming approach, data structures and algorithms are separated into independent entities. In object-oriented programming , data structures and algorithms are encapsulated together into an independent unit, the object, and the internal details of the object are hidden as much as possible. The private properties of an object can only be read and modified by the behavior of the object, and the connection with the outside world acts as an external interface through public behavior .

 

 

    

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325723285&siteId=291194637