Final Exam The exam is comprehensive over all

profileTopsolutions
 (Not rated)
 (Not rated)
Chat

Page 1 

Multiple Choice Questions

Question 1.1. (TCO 1) Assume you have the following declaration.

int beta[50];

Which of the following is a valid element of beta?
 (Points : 4)

        beta['0']
      
  beta['1']
      
  beta[0]
      
  beta[50]

 

Question 2.2. (TCO 1) Consider the following statement.

double alpha[10][5];

The number of components of alpha is ____.
 (Points : 4)

        15
      
  50
      
  100
      
  150

 

Question 3.3. (TCO 1) Consider the following declaration.

int j;
int sum; 
double sale[10][7];

Which of the following correctly finds the sum of the elements of the fourth column of sale?
 (Points : 4)

        sum = 0;
for(j = 0; j < 10; j++)
      sum = sum + sale[j][3];

      
  sum = 0;
for(j = 0; j < 10; j++)
      sum = sum + sale[j][4];

      
  sum = 0;
for(j = 0; j < 7; j++)
      sum = sum + sale[j][4];

      
  sum = 0;
for(j = 0; j       sum = sum + sale[j][3];


 

Question 4.4. (TCO 1) Which of the following correctly declares and initializes alpha to be an array of 4 rows and 3 columns with the component type int? (Points : 4)

        int alpha[4][3] = {{0,1,2} {1,2,3} {2,3,4} {3,4,5}};
      
  int alpha[4][3] = {0,1,2; 1,2,3; 2,3,4; 3,4,5};
      
  int alpha[4][3] = {0,1,2: 1,2,3: 2,3,4: 3,4,5};
      
  int alpha[4][3] = {{0,1,2}, {1,2,3}, {2,3,4}, {3,4,5}};

 

Question 5.5. (TCO 1) What is the value of alpha[4] after the following code executes?

int alpha[5] = {0};
int j;
alpha[0] = 2;
for (j = 1; j < 5; j++)
    alpha[j] = alpha[j - 1] + 3;
 (Points : 4)

        5
      
  8
      
  11
      
  14

 

Question 6.6. (TCO 1) Assume you have the following declaration.

charnameList[100];

Which of the following ranges is valid for the index of the array nameList?
 (Points : 4)

        0 through 99
      
  0 through 100
      
  1 through 100
      
  1 through 101

 

Question 7.7. (TCO 2) The member functions of a class should usually be _____. (Points : 4)

        public
      
  private
      
  protected
      
  templates

 

Question 8.8. (TCO 2) Consider the following.

boolclockType::equalTime(constclockType&) const {...}
void clockType::getTime(int&, int&, int&) const {...}


The word ____ at the end of the member functions in the class clockType specifies that these functions cannot modify the member variables of a clockType object.
 (Points : 4)

        void
      
  const
      
  clockType::
      
  &

 

Question 9.9. (TCO 2) Consider the following class definition.

classrectangleType
{
public:
    void setLengthWidth(double x, double y);
    //Postcondition: length = x; width = y;
    void print() const;
    //Output length and width;
    double area();
    //Calculate and return the area of the rectangle;
    double perimeter();
    //Calculate and return the parameter;
    rectangleType();
    //Postcondition: length = 0; width = 0;
    rectangleType(double x, double y);
    //Postcondition: length = x; width = y;
private:
    double length;
    double width;
};

And consider this object declaration.

rectangleTypebigRect(14,10);

Which of the following statements is correct?
 (Points : 4)

        bigRect.setLengthWidth();
      
  bigRect.setLengthWidth(3.0, 2.0);
      
  bigRect.length = 2.0;
      
  bigRect.length = bigRect.width;

 

Question 10.10. (TCO 2) Consider the following class definition.

classcircleType
{
public:
    void set(double r);
    //Postcondition: radius = r;
    void print();
    //Output radius, area, and circumference.
    double area();
    //Postcondition: Calculate and return area.
    double circumference();
    //Postcondition: Calculate and return circumference.
    circleType();
    //Postcondition: radius = 0;
    circleType(double r);
    //Postcondition: radius = r;
private:
    double radius;
};

And consider this declaration.

circleTypemyCircle;
double r;


Which of the following statements is valid in C++?

(i)
cin>> r;
myCircle.area = 3.14 * r * r;
cout 

(ii) 
cin>> r;
myCircle.set(r);
cout
 (Points : 4)

        Only (i)
      
  Only (ii)
      
  Both (i) and (ii)
      
  None of these

Page 2 


 
Multiple Choice

Question 1.1. (TCO 2) Consider the following class definition.

classrectangleType
{
public:
     void setLengthWidth(double x, double y);
     //Postcondition: length = x; width = y;
     void print() const;
     //Output length and width;
     double area();
     //Calculate and return the area of the rectangle;
     double perimeter();
     //Calculate and return the parameter;
     rectangleType();
     //Postcondition: length = 0; width = 0;
     rectangleType(double x, double y);
     //Postcondition: length = x; width = y;
private:
     double length;
     double width;
};


Which of the following class-variable declarations is correct?
 (Points : 4)

        rectanglerectangleType;
      
  class rectangleType rectangle;
      
  rectangleType rectangle;
      
  rectangle rectangleType.area;

 

 

 

 

 

 

 

 

 

 

 

 

Question 2.2. (TCO 2) Suppose you have the following UML class diagram of a class. 

Which of the following is the name of the class? 
(Points : 4)

 

        clock
      
  clockType
      
  Type
      
  ClockType

 

Question 3.3. (TCO 2) Consider the following declaration.

classmyClass
{
public:
    void print();
private:
    int x;
};
myClassmyObject;


Which statement is legal?
 (Points : 4)

        myObject.print = 10;
      
  myClass.print = 10;
      
  myObject.print();
      
  myClass.print();

 

Question 4.4. (TCO 3) Composition is when one or more members of a class are _____. (Points : 4)

        accessed by member functions of the same class
      
  objects of another class type
      
  defined in a separate file
      
  created in a class-tester program

 

Question 5.5. (TCO 3) Composition, like inheritance, demonstrates what software-development advantage of object-oriented programming? (Points : 4)

        Better coordination between software developers
      
  Reduced development time
      
  Reusable code
      
  All of the above

 

Question 6.6. (TCO 3) What is the correct statement for declaring an array of 10 objects of ClassB? (Points : 4)

        ClassB[10];
      
  ClassB->objectB[10];
      
  ClassBobjectB[10];
      
  objectB = new [10] ClassB;

 

Question 7.7. (TCO 3) Which is a true statement about classes and structures? (Points : 4)

        Both classes and structures are private by default.
      
  Both classes and structures are public by default.
      
  Classes are public by default, but structures are private.
      
  Structures are public by default, by class are private.

 

Question 8.8. (TCO 4) A derived class can redefine _____. (Points : 4)

        a private member function of the base class
      
  a public member function of the base class
      
  both public and private member functions of the base class
      
  niether public nor private member functions of the base class

 

Question 9.9. (TCO 4) Which of the following is true about a derived class? (Points : 4)

        A derived class can directly access any member variable of the base class.
      
  A derived class can redefine any public member function of the base class.
      
  A derived class can have, at most, one base class.
      
  A derived class can redefine any member function of the base class.

 

Question 10.10. (TCO 4) Which of the following base class members is never inherited by a derived class, regardless of access attributes? (Points : 4)

        Mutator
      
  Accessor
      
  Constructor
      
  Data


Page 3 


 
Multiple Choice

Question 1.1. (TCO 4) Which of the following base class members is never inherited by a derived class, regardless of access attributes? (Points : 4)

        Mutator
      
  Data
      
  Accessor
      
  Destructor

 

Question 2.2. (TCO 4) Single inheritance means _____. (Points : 4)

        that the derived class is derived from a single base class
      
  that only multiple classes can be derived from the given base class
      
  that only one base class can be derived
      
  Single inheritance is not possible in C++.

 

Question 3.3. (TCO 4) If inheritance is private, then _____. (Points : 4)

        the public and protected members of the base class become private members of the derived class
      
  all the private members of the base class become public members of the derived class
      
  the protected members of the base class become public members of the derived class
      
  none of the members of the base class become members of the derived class

 

Question 4.4. (TCO 5) If p is a pointer variable of type int, and num is an int variable, what is the result of the statement p = &num;? (Points : 4)

        p is equal to num.
      
  p is equal to the address of num.
      
  num is equal to the address of p.
      
  and num are concatenated and assigned to p.

 

Question 5.5. (TCO 5) Given the definition of a class called Employee, which of the following correctly dynamically allocates an array of 20 Employee objects? (Points : 4)

        Employee * myData = new Employee[20];
      
  Employee myData[20] = new Employee[20];
      
  Employee = myData[20];
      
  Employee array = new Employee[20];

 

Question 6.6. (TCO 5) Which of the following statements correctly allocates space to store 15 real numbers? (Points : 4)

        double *dptr = new double[15];
      
  double dptr = new double[15];
      
  double *dptr = new double[14];
      
  real *iptr = new real[14];

 

Question 7.7. (TCO 5) If p is a pointer, which statement uses the pointer and then increments it? (Points : 4)

        *++p
      
  *p++
      
  *p--
      
  *--p

 

Question 8.8. (TCO 6) The operator>>() function overloads the ____ operator. (Points : 4)

        greater than
      
  less than
      
  insertion
      
  extraction

 

Question 9.9. (TCO 6) What is the difference between a friend function and a member function of the class? (Points : 4)

        A friend function is a nonmember function of the class, whereas a member function is a member of the class.
      
  All the member functions of a class are also friend functions.
      
  The prototype for a friend function is not included in the class definition.
      
  The definition of a friend function must be preceded by the class name and the scope resolution operator.

 

Question 10.10. (TCO 6) Which of the following statements is true for the C++ language? (Points : 4)

        The precedence of an operator can be changed.
      
  Every instance of an overloaded operator has the same number of parameters.
      
  It is not necessary to overload relational operators for classes that have only int member variables.
      
  The post increment (++) and the pre increment (++) operators' prototype must be the same, as they use the same symbols (++).

 

Question 11.11. (TCO 6) If you overload the binary arithmetic operator + as a member function, how many objects must be passed as parameters? (Points : 4)

        3
      
  2
      
  1
      
  0

 

Question 12.12. (TCO 7) Overriding a base-class member function with a derived member function demonstrates the concept of _____. (Points : 4)

        overloading
      
  inheritance
      
  polymorphism
      
  abstraction

 

Question 13.13. (TCO 7) If the class Shape is an abstract class, what type of variable may be declared of the type Shape? (Points : 4)

        No variables may be declared because it is an abstract class.
      
  Only arrays of the class Shape may be declared.
      
  Objects of the class Shape may be declared only if an object of a class that is derived from Shape is also declared.
      
  A pointer of the abstract class may be declared.

 

Question 14.14. (TCO 7) Consider the following class definitions.

class Employee { };
class Boss : public Employee { };
class Worker : public Employee { };

Which class(es) should declare the function as virtual if all three classes have a member function double CalculateEarnings();?
 (Points : 4)

        class Boss
      
  class Worker
      
  class Employee
      
  All three classes

 

Question 15.15. (TCO 7) If a destructor of a base class is made virtual, then _____. (Points : 4)

        there is no need to provide a destructor for the derived class
      
  the derived class destructor is automatically made virtual
      
  doing so will generate a compiler error
      
  the default sequence in which the destructors are called when a derived object goes out of scope will change

 

Question 16.16. (TCO 7) Another definition for dynamic binding is _____. (Points : 4)

        late binding
      
  early binding
      
  dynamic allocation
      
  It is not a defined term in C++ programming.

 

Question 17.17. (TCO 8) Which is not a preprocessor directive statement? (Points : 4)

        define
      
  include
      
  ifdef
      
  ifnotdef

 

Question 18.18. (TCO 8) Which preprocessor directive essentially inserts another file into your source file? (Points : 4)

        ifndef
      
  define
      
  include
      
  fstream

 

Question 19.19. (TCO 8) All preprocessor directives begin with a(n) ___. (Points : 4)

        underscore
      
  blank space
      
  #
      
  &

 

Question 20.20. (TCO 8) In a multifile, object-oriented, C++ project, which is the correct statement for the constructor implementation, given that the constructor is correctly defined in the class definition file? (Points : 4)

        Classname:Classname{ }
      
  Classname { }
      
  Classname::Classname { }
      
  Classname { }

Page 4 


 
Essay Questions

Question 1.1. (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 2.2. (TCO 2) Explain the basic C++ syntax for creating a class. Include an explanation of the private and public section of a class and the class members. Include a code segment to illustrate your answer. (Points : 10)

      
      

 

Question 3.3. (TCO 3) Using a personal computer as a base model, write a C++, syntactically correct class definition demonstrating composition. In the class definition, include at least the following three items that are common to a PC: a CD drive, a hard disk drive, and a power supply. You are not required to include any constructors, destructors, or additional member functions; you are only required to list the members that directly show composition and the proper access attributes. (Points : 10)

      
      

 

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

      
      

 

Question 5.5. (TCO 5) Describe what a memory leak is and why it could cause problems. (Points : 10)

      
      

 

Question 6.6. (TCO 6) Assume that three objects of the class Inductor have been instantiated: L1, L2, and L3. Write the overloaded operator prototypes that would be required to perform the following operation. You are only required to write the prototypes, not the implementation code.

L3 = L1 + L2;
 (Points : 10)

      
      

 

Question 7.7. (TCO 7) Define what is meant by the term run-time binding, and list two other terms that are also used to describe it. (Points : 10)

      
      

 

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

      
      



 

    • 12 years ago
    Solution
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      comp220exam_-_answer.docx