Quiz

    1. Question : (TCO 4) A variable declared before and outside all function blocks
    2. Question : (TCO 4) What is the value of i after the following code fragment executes?
    3. Question : (TCO 4) How many times will variable i be printed to the screen?
    for (i = 1 ; i <= 20 ; i = i + 2);
    {
    cout << “ “ << i ;
    }
    4. Question : (TCO 4) Which looping statement is best if the number of iterations is known?
    5. Question : (TCO 4) C++ selection statements include
    6. Question : (TCO 4) If firstName and lastName are string object variables, which statement can be used to combine (append or concatenate) the two into a single string variable?
    7. Question : (TCO 4) Which type of error does the following code fragment cause?
    8. Question : (TCO 4) The code below computes the length of a C-style string. What should the value of FLAG be?
    9. Question : (TCO 4) Which type of error does the following code fragment cause?
    10. Question : (TCO 4) What is the declaration for a C-style string that can hold a name with up to 3 printable characters (for example, “Ron”)?
    11. Question : (TCO 4) What is the output of the following code?
    12. Question : (TCO 4) Which of the following function definitions uses pass-by-values?
    13. Question : (TCO 4) Which of the following statements call the following function correctly?
    14. Question : (TCO 4) What is the output of the following code?
    15. Question : (TCO 4) A Distance class has two private members, ‘feet’, of type int, and ‘inches’, of type double. Which prototype correctly declares the copy constructor for such class?
    Distance Distance(const Distance &);
    Distance(const Distance &);
    int Distance(int, double);
    Distance(feet, inches);
    16. Question : (TCO 4) The word const inside the parentheses of the following declaration of isEqual
    bool isEqual (const Distance & rightSideObject) const;
    ensures the member variables of the called objects are protected (cannot be changed).
    ensures the argument passed in to the function is protected (cannot be changed).
    ensures the return value of the function is protected (cannot be changed).
    ensures the return value is routed to the proper variable.
    17. Question : (TCO 4) Given the following class definition and lines of code, Line 1 in main is a call to what?
    class Distance
    {
    private:
    int feet;
    double inches;
    public:
    Distance( );
    Distance(int initFt, double initIn);
    void setFeet(int feetIn);
    void setInches(double inchesIn);
    int getFeet() const;
    double getInches( ) const;
    };
    int main( )
    {
    Distance d1; //Line 1
    const int MAX = 100; //Line 2
    Distance list[MAX]; //Line 3
    Distance d2(1, 2.3); //Line 4
    Distance * pDist; //Line 5
    d1.feet = 5; //Line 6
    // etc. – assume the remaining code is correct
    }
    The 0-argument Distance constructor
    The 2-argument, int, double, Distance constructor
    The 2-argument, double, int, Distance constructor
    The 1-argument, int, Distance constructor
    18. Question : (TCO 4) Creating one class from another in a parent/child hierarchy is an example of
    19. Question : (TCO 4) Which of the following is a valid declaration to overload the following function?
    int whatever (double x);
    20. Question : (TCO 4) How many parameters are required to overload the pre-increment operator for a class as a member function?
    21. Question : (TCO 4) Given the following definitions and statements,
    void myFunction (double * dptr);;
    double data [10];
    which of the following statements correctly calls the function passing in the address of the data array?
    22. Question : (TCO 4) Assume you have to write a class that makes use of dynamic memory allocation (the class needs to allocate and de-allocate memory). According to best practices, where would the keyword ‘delete’ be placed?
    23. Question : (TCO 4) When writing a class, the compiler automatically creates some support functions for the class. What are some of these functions?
    24. Question : (TCO 4) Assume you have to write a class that makes use of dynamic memory allocation (the class needs to allocate and de-allocate memory). According to best practices, where would the keyword ‘new’ be placed?
    25. Question : (TCO 4) What is wrong with the following C++ statements?
    int * iptr;
    double d = 123.321;
    iptr = &d;
    cout << *iptr;
    The cout statement does not contain an endl.
    The space following the ampersand should not be there.
    The iptr variable cannot be given an address of a double.
    All of the above

                                                                                                                                      Order Now