Structures - C++ Task

Task: Write the following program:
1) Define the strucutre that describes an animal.
2) Create 2 objects of the strucutre.
3) Set values to the object parameters.
4) Display the object parameters on the scree.

Hello my dear programmers, my issue here is that I'm not sure what to put inside the 'int main()' function and also if I didn't miss anything for my void
functions.

Thanks a lot for your help, cheers!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
#include <iostream>

using namespace std;

typedef struct COUGAR
{
    int number_legs;
    int mass;

} COUGAR;

void create_animal(COUGAR any_cougar)
{
    cout<< "How many legs: ";
    cin>> any_cougar.number_legs;
    cout<< "Mass?: ";
    cin>> any_cougar.mass;

}

void display_animal(COUGAR any_cougar)
{
    cout<<"Number of legs: "<<any_cougar.number_legs<<endl;
    cout<<"Mass of the animal: \"" <<any_cougar.mass << "\""<<endl;
}


int main()
{
    cout << "Quiz 11C" << endl;
    COUGAR;


    return 0;
}

Last edited on
I think you're meant to be doing something like
1
2
3
4
5
6
7
8
9
10
11
12
13
// 1) Define the strucutre that describes an animal.
struct Animal {
   int numlegs;
};

/// more code

int main {
    // 2) Create 2 objects of the strucutre.
    Animal cougar;
    Animal spider;
    // more code
}
Um, no my lecturer specifically told me it has to be 1 animal and its two features
So do you want two Cougars, each with legs and mass?

That's not what your description implies.
Sorry but you're focusing not on the right thing, the body of the program is fine for now, I will change the details related to the description later. For now I really need help in the area I pointed out under the question.
I agree with salem c, consider it might be you that is misinterpreting the instructions. I say this based on experience of what teachers usually ask for, and my knowledge of OOP.

To remove any doubt post the assignment verbatim.

To your question, I would start with salem c Code, then initialize each object with some data via a constructor, then display that data, just as the instructions say.
Topic archived. No new replies allowed.