Thread: Beginners' Work

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    100

    Beginners' Work

    I need some work to do to process my C++ knowledge. Can you guys help me on some kind of class or some kind of progressive learning that would ask something of me rather than just trying to pull programs to make out of the air? Please, I really want to learn and all I can do is a "Hello World" program and some simplistic cout cin if else programs.

    Help would greatly be appreciated.
    Last edited by blankstare77; 07-21-2005 at 03:45 PM.

  2. #2
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    Well it depends how much you've covered so far but I saw the question below posted on here a few months back and thought it looked quite handy for rekindling my interest in C++. It might not be what your looking for but it seems to me like you could learn lots from it!

    Define a class called Animal with the following data attributes
    Desc : array of 20 character
    Height : float
    Weight : float
    Define a class Bird that inherits from Animal class above wit hthe following attributes:
    Wingspan : float
    Your program should be able to store up to 10 BirdRec records in an array called BirdsArray.

    Your program should at least perform the below operations

    - Add new birds records into BirdsArray
    - Display all birds record
    - Display the bird details with largeST winspan
    - Display the bird details with lowest winspan
    Couldn't think of anything interesting, cool or funny - sorry.

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    WOW that's so cool thank you for responding. Only can i talk to you about some of those things?

    How about arrays (would I notate it like this?)
    int (Variable/Array Name)[# of integers to be stored in this array (indexes)]

    And what does Desc mean (describe maybe?).

    I understand classes.

    Yeah...floating point numbers can be any integer or real number (decimals).

    Do I need to know inheritance for this?

    Really sorry about the questions I just don't know all this stuff but I will learn it soon. Not asking for you to write this for me just need to know the functions, keywords and such.
    Last edited by blankstare77; 07-21-2005 at 04:05 PM.

  4. #4
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    Desc is probably a description, the animals name if you like. This is an inheritance question so there is lots of room to expand and practice with classes.

    Code:
    class Animal
    {
    //animal attributes and functions.
    };
    
    class Bird : public Animal
    {
    //Bird attributes and functions.
    };
    Animal class will be very general, it might include a function called eat( ) for example, which all Animals will do. Bird is a special type of Animal so adds further functionality and characterstics, perhaps fly( )???


    Your best bet is to start with the Animal class only, and make sure you can create animals with a Desc a Weight and a Height that you are able to manipulate. Come back here when you get stuck



    edit : Oh, and yes your array notation looks fine. Some quick examples:
    Code:
    int ages[ 10 ];
    char alphabet[ 26 ];
    Day july[ 31 ];
    Last edited by endo; 07-21-2005 at 04:14 PM.
    Couldn't think of anything interesting, cool or funny - sorry.

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    Wait a minute...there's a C++ function called eat().....or can I just "make" or "name" a function how does that happen? Oh my god I thought I had to rely on keyword functions. Do you tell the function what to do (obviously if you create it)?

  6. #6
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    ok, take this example one step at a time. Look at class definitions, and try the first part about creating an Animal class. eat( ) isn't a standard C++ function, it is something you will have to create for yourself. Its is an action performed by any Animal, whereas fly is only performed by some animals.

    Try taking away this example and creating an Animal class to use in a test program, then move onto bigger things
    Couldn't think of anything interesting, cool or funny - sorry.

  7. #7
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    Code:
    #include <iostream.h>
    
    int main() {
    
    class Animal { 
    public:
    	float Height;
    	float Weight;
    	
    class Bird {
    public:
    	float Wingspan;
    }

    That's what I've got so far. As for the array (that's supposed to be in the Bird structure), is that part of public, private, or none? And for the Bird class to inherit the Animal class...clueless. So how am I doing so far?

  8. #8
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Try not to use old C style headers, change

    Code:
    iostream.h
    to this

    Code:
    iostream
    As for your program looks good but i really dont think you can name somthing in a class public twice, try using private, or only having the public

    oh and the end of the class should be this

    Code:
    };
    not what you have which is the brace without the colon. keep it up looking good, come back if you get stuck.

  9. #9
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    try sticking with the Animal class initially. Look at constructors, destructors, member functions, etc. Then move on to inheritance and playing with the Bird class. Your Animal class should look like this:
    Code:
    class Animal 
    { 
    private:
    	float Height;
    	float Weight;
    };
    Look at creating and manipulating classes, try to find out why the data members should be private and what other functions you should add to the class.
    Couldn't think of anything interesting, cool or funny - sorry.

  10. #10
    C++ Beginner
    Join Date
    Jun 2005
    Posts
    39
    It'll be hard to tell you everything you need to learn classes. It took me quite a while to learn em. goto some sites such as

    www.cplusplus.com
    www.cplusabout.com
    ww.functionx.com

    There are tuts all around the internet. You will need to learn basic classes, functions, arrays, and maybe even pointers if you want to do advanced codes like that.

    Yes you can make eat(). if you do some thing like..

    Code:
    int eat()
    You will have to read on functions to learn more about this
    I'm a beginner C++ programmer, but I have studied HTML and Java. So if you need to help me I should catch on fast =)

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You can have as many public: tags in a class as you want.

    [edit]
    The link to www.cplusabout.com doesn't work.
    [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12
    C++ Beginner
    Join Date
    Jun 2005
    Posts
    39
    I'm a beginner C++ programmer, but I have studied HTML and Java. So if you need to help me I should catch on fast =)

  13. #13
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    Code:
    #include <iostream.h>
    
    int main() {
    
    class Animal { 
    private:
    	int Animals[20];
    protected:
    	float Height;
    	float Weight;
    	
    };
    
    class Bird : protected Animal {
    private:
    	float Wingspan;
    	int BirdsArray[10]
    };
    Well I hope I'm set up right now. Please, if I'm horribly wrong, help.

  14. #14
    *this
    Join Date
    Mar 2005
    Posts
    498
    Code:
    #include <iostream>
    
    int main() { //where does main end???
    
    class Animal { 
    private:
    	int Animals[20];
    protected:
    	float Height;
    	float Weight;
    	
    };
    
    class Bird : protected Animal {
    private:
    	float Wingspan;
    	int BirdsArray[10] //semicolon
    };
    looks good so far

  15. #15
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    SCORE!!!.

    The main doesn't end, I'm doing an assignment and before I code the operations i was just including the framework.

    Now to actually make it do the operations.... Clueless. I'll post some ideas when I code some more.



    Edit: Hmm. Well I'm starting to print some things to the user except that I don't know how to do a Yes/No user input prompt.
    Last edited by blankstare77; 07-22-2005 at 04:41 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM