Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. (TCO 1) Describe the conceptual model of a two-dimensional array. Include in

ID: 3664105 • Letter: 1

Question

1. (TCO 1) Describe the conceptual model of a two-dimensional array. Include in your explanation how a two-dimensional array might be used, why these arrays are similar to tables, and how to declare and initialize a two-dimensional array. (Points : 10)

Question 2.2. (TCO 1) Describe an example of a two-dimensional character array that could be used to hold a set of text data that might be displayed on a hand-held information display device such as an MP3 player. Describe what each of the two dimensions might represent and the data that would be held in the array, and provide an example array declaration. (Points : 10)

Question 3.3. (TCO 2) Explain how encapsulation and data hiding are incorporated in C++ classes. Why are these concepts important in object-oriented programming? (Points : 10)

Question 4.4. (TCO 2) Explain the difference between a parameterized constructor and a default constructor. Provide an example class that includes both types of constructors.(Points : 10)

Question 5.5. (TCO 3) Assume that a definition of class Automobile has a composite object called myEngine of class Engine. Also assume that all the data members of class Engine that contain information about the engine such as displacement, horsepower, torque, and so on are all private data members of the Engine class.
Write the function prototype that would be required for an object of class Automobile to access the data member horsepower of the myEngine object. Explain your answer, including what kind of function this is, what class it would be defined in, what its access attribute is, and why it is necessary. (Points : 10)

Question 6.6. (TCO 4) Without considering the access attributes, list and describe which base class members may not be inherited by a derived class and provide a rationale for why this is. (Points : 10)

Question 7.7. (TCO 4) If a class is derived public from a base class, explain how this affects the inheritance of all public, protected, and private members of the base class by the derived class. (Points : 10)

Question 8.8. (TCO 8) Describe what a preprocessor statement is, how it is used, and what part of the development environment it interacts with. Provide a syntactically correct example, describing what it does. (Points : 10)

1. (TCO 1) Describe the conceptual model of a two-dimensional array. Include in your explanation how a two-dimensional array might be used, why these arrays are similar to tables, and how to declare and initialize a two-dimensional array. (Points : 10)

      
      

Explanation / Answer

1. An array keeps track of multiple pieces of information in linear order, a one-dimensional list. However, the data associated with certain systems (a digital image, a board game, etc.) lives in two dimensions. To visualize this data, we need a multi-dimensional data structure, that is, a multi-dimensional array. A two-dimensional array is really nothing more than an array of arrays (a three-dimensional array is an array of arrays of arrays). Think of your dinner. You could have a one-dimensional list of everything you eat:

Or you could have a two-dimensional list of three courses, each containing two things you eat:

In the case of an array, our old-fashioned one-dimensional array looks like this:

And a two-dimensional array looks like this:

2.2:

3.3:

Program statements (code): This is the part of a program that performs actions and they are called functions.

Program data: The data is the information of the program which affected by the program functions.

Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse. Data encapsulation led to the important OOP concept of data hiding.

Data encapsulation is a mechanism of bundling the data, and the functions that use them and data abstraction is a mechanism of exposing only the interfaces and hiding the implementation details from the user.

C++ supports the properties of encapsulation and data hiding through the creation of user-defined types, called classes. We already have studied that a class can contain private, protected and public members. By default, all items defined in a class are private. For example:

The variables length, breadth, and height are private. This means that they can be accessed only by other members of the Box class, and not by any other part of your program. This is one way encapsulation is achieved.

To make parts of a class public (i.e., accessible to other parts of your program), you must declare them after the public keyword. All variables or functions defined after the public specifier are accessible by all other functions in your program.

Making one class a friend of another exposes the implementation details and reduces encapsulation. The ideal is to keep as many of the details of each class hidden from all other classes as possible.

Data Encapsulation Example:

Any C++ program where you implement a class with public and private members is an example of data encapsulation and data abstraction. Consider the following example:

When the above code is compiled and executed, it produces the following result:

Above class adds numbers together, and returns the sum. The public membersaddNum and getTotal are the interfaces to the outside world and a user needs to know them to use the class. The private member total is something that is hidden from the outside world, but is needed for the class to operate properly.

Designing Strategy:

Most of us have learned through bitter experience to make class members private by default unless we really need to expose them. That's just goodencapsulation.

This wisdom is applied most frequently to data members, but it applies equally to all members, including virtual functions.