Thread: what is the difference between...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    18

    what is the difference between...

    ...an array and a class type?

    I have this question on the study guide for my final in Intro to programming in C++... It makes no sense to me, because (at least as far as I understand) they are very different. Kinda like what's the difference between apples and oranges.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    an array is a container for groups of the same data type. A class is really a struct, and of course the whole idea of having structures is so that we can group dissimilar data - strange question if you ask me...
    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;
    }

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    18
    that's what I thought... I'm not sure what he's looking for... I guess just a definition of each

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    18
    one more related question...

    What advantage does a class type have over that of a one dimensional array?

    Again... this question seems like it doesn't make a whole lot of sense, because they would be used in different instances for different reasons...

  5. #5
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    A class/struct can hold multiple different kinds of types, for example
    Code:
    struct Player {
     int health;
     float x;
     float y;
     float z;
     string name;
    };
    An array, on the other hand, can only store one type.

    Code:
    const int NUM_TRIALS=10;
    int diceOutcome[NUM_TRIALS];
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    18
    thank you

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    139
    yup

    arrays are homogeneous
    classes/structs are heterogeneous
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    95
    also a class can have methods to manipulate it's properties

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    12
    class can and it definitely *should* have methods. i consider the use of struct with methods or class w/o methods to be really weird. what do you think?

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    this is Cool

    I know that you have an exam, so go to http://www.cprogramming.com/begin.html
    and there you will be looking for what is the class and what is the array... and then you will see that you can't make a different between class and array because ... array is something and class is something else...

    OK
    Good luck in your exam...
    C++
    The best

  11. #11
    Registered User
    Join Date
    Apr 2002
    Posts
    18
    I've already taken the test... and I know they are completely different... that is what was confusing me

  12. #12
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Talking I hope that you did well

    I hope that you did well in your test...

    anyway...

    You are welcome, here... you can learn... I do learn alot here.. at least I am learning some English...
    C++
    The best

  13. #13
    Unregistered
    Guest
    Originally posted by chomper
    class can and it definitely *should* have methods. i consider the use of struct with methods or class w/o methods to be really weird. what do you think?
    A struct can't have methods. Unless you get into pointing to a function and that isn't pretty.

  14. #14
    www.entropysink.com
    Join Date
    Feb 2002
    Posts
    603
    I have problems seeing the link between Structs and Classes.....

    OK, they can both hold data of different intrinsic types (which I assume is what you mean by hetrogenous), but one is a "collection" of various lumps of associated data, and the other is an object template with associated data, methods and properties etc. A bit like comparing people with clocks 'cos they both have hands. (IMHO)
    Visit entropysink.com - It's what your PC is made for!

  15. #15
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    A class can hold a collection of variables and functions, a struct can only hold a collection of variables. Look at it as if classes are a better structs.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Review required for program of date difference
    By chottachatri in forum C Programming
    Replies: 6
    Last Post: 10-31-2008, 11:46 AM
  2. Difference Equations / Recurrence Relations
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-05-2007, 10:26 AM
  3. What's the difference between var++ and ++var
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 05-31-2007, 02:27 AM
  4. how to get difference of digits
    By Leeman_s in forum C++ Programming
    Replies: 5
    Last Post: 12-20-2001, 08:32 PM
  5. What is the Difference between ANSI C and non-ANSI C ?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-24-2001, 06:55 AM