Class Questions

This is a discussion on Class Questions within the C++ Programming forums, part of the General Programming Boards category; I have a simple question from a class of mine on dynamic arrays. When allocating an array of objects, what ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    14

    Class Questions

    I have a simple question from a class of mine on dynamic arrays.

    When allocating an array of objects, what constructor is used to initialize all of the objects in the array?

    A. The automatic copy constructor
    B. The constructor specified at the declaration
    C. The default constructor
    D. None of the above

    What are your thoughts on this question?

    I was learning towards B, but then I wasn't sure.

    Thanks!

    -Shane

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    My vote is for C.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    14
    Alright, I have another one that I'm kinda stuck on

    Which situation does not use the copy constructor?

    A. Calling a function with a reference parameter
    B. Calling a function with a value parameter
    C. Declaring a variable to be a copy of another existing object
    D. Returning a value from a function
    E. All of the above situations use the copy constructor

    I'm thinking that it is E, but I didn't know whether a value parameter is copied or not

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    161
    When allocating an array of objects, the default constructor is used.

    As for the last question, the copy constructor is not used when passing by reference.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    14
    Alright, this one is really stumping me

    What is the usual worst-case performance for resizing a container class that stores its data in a dynamic array?

    A. Constant Time
    B. Logarithmic Time
    C. Linear Time
    D. Quadratic Time

    Any helpful information on this question would be appreciated.

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    51
    When allocating an array of class objects, the constructor which takes no parameters is called, either the default or the user defined constructor. As usual if no, 'no parameters constructor' is defined but a constructor that does take parameters is defined, that will result in a compiler error

    as for the worst case one, i think it's the quadratic, although i'm not too sure.

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Instead of asking others for answers to your homework, perhaps you should actually do some research of your own. Besides, it's against board rules.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    14
    Alright how about this.

    How do you calculate worst case performance for a given function?


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  2. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 08:10 AM
  3. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  4. Series of class questions #1
    By kippwinger in forum C++ Programming
    Replies: 4
    Last Post: 10-02-2003, 04:28 AM
  5. class member access denied
    By chiqui in forum C++ Programming
    Replies: 2
    Last Post: 05-27-2002, 02:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21