1. (TCO 1) Explain how two-dimensional arrays are passed to functions. In your e
ID: 3549566 • Letter: 1
Question
1. (TCO 1) Explain how two-dimensional arrays are passed to functions. In your explanation include a two-dimensional array declaration and initialization, a function prototype that receives a two-dimensional array, and a function header with an empty body that matches the function prototype. Demonstrate how a two-dimensional array is passed to the function as an argument. (Points : 10)Question 2. 2. (TCO 1) Given the following array declaration and program statement, describe in detail the condition and what potential problems could occur if a program containing both was compiled and executed.
int array[5][4] = {0};
array[4][4] = 5; (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) Explain what a base class access specifier is and how it affects inheritance. (Points : 10)
Question 7. 7. (TCO 4) If a class is derived private 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 namespace is and provide general syntax of a namespace statement. (Points : 10)
Question 2. 2. (TCO 1) Given the following array declaration and program statement, describe in detail the condition and what potential problems could occur if a program containing both was compiled and executed.
int array[5][4] = {0};
array[4][4] = 5; (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) Explain what a base class access specifier is and how it affects inheritance. (Points : 10) Question 7. 7. (TCO 4) If a class is derived private 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 namespace is and provide general syntax of a namespace statement. (Points : 10) Question 2. 2. (TCO 1) Given the following array declaration and program statement, describe in detail the condition and what potential problems could occur if a program containing both was compiled and executed.
int array[5][4] = {0};
array[4][4] = 5; (Points : 10)
Explanation / Answer
Explain how two-dimensional arrays are passed to functions. In your explanation include a two-dimensional array declaration and initialization,
a function prototype that receives a two-dimensional array, and a function header with an empty body that matches the function prototype.
Demonstrate how a two-dimensional array is passed to the function as an argument. (Points : 10)
int array[4][5] = {0};
// function header with empty body.
void print_2d_array(int array[4][5])
{
}
two-dimensional array can be passed to function like above pass the entire contents of array to function.
Question 2. 2. (TCO 1) Given the following array declaration and program statement, describe in detail the condition and what potential
problems could occur if a program containing both was compiled and executed.
int array[5][4] = {0};
array[4][4] = 5; (Points : 10)
last row and last element of array array[4][3] = 5;
so trying to write in location 4,4 leads to memory overwrite and thus memory corruption.
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)
#include<iostream>
using namespace std;
class number
{
private:
int num; // data hiding only class can access.out side users cant access.
public:
number() { num =0; }
number(int k) { num =k; }
int get_num() { return num; } // encapsulation.
};
int main()
{
number n1(5);
cout << n1.get_num() << endl;
return 0;
}
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)
default constructor assumes default values for its class members.
while parameterized constructor user can pass values that are to be assigned to class member through constructor.
example below.
#include<iostream>
using namespace std;
class number
{
private:
int num; // data hiding only class can access.out side users cant access.
public:
number() { num =0; }
number(int k) { num =k; }
int get_num() { return num; } // encapsulation.
};
int main()
{
number n1(5);
cout << n1.get_num() << endl;
return 0;
}
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)
class Engine
{
private:
double horsepower;
public:
double get_horsepower() { return horsepower; }
};
class Automobile
{
private:
Engine myEngine;
public:
Automobile()
{
// Access horsepower of myEngine object as below.
// it is public function
// belong to class Engine
// access attribute is public because we need to access that.
cout << myEngine.get_horsepower() << endl;
};
Question 6. 6. (TCO 4) Explain what a base class access specifier is and how it affects inheritance. (Points : 10)
if derived class inherits base class with public attribute then all public member variable of base class will be made public to derived class also.
if derived class inherits base class with private attribute then all public member variable of base class will be made private to derived class also.
if derived class inherits base class with protected attribute then all public member variable of base class will be made protected to derived class also.
Question 7. 7. (TCO 4) If a class is derived private 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)
If a class is derived private from a base class, public members of base class will be made private to derived class
protected members of base class will be made private to derived class
private members of base class will be made private to derived class
Question 8. 8. (TCO 8) Describe what a namespace is and provide general syntax of a namespace statement. (Points : 10)
namespace is collection of operations used by only program that declare namespace.
namespace name
{
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.