Define the class Student which has name (char name[20]) and age(int). Define the default constructor, member functions get_data() for taking the name and age of the Student, print() for displaying the data of Student.


i hv tried it.. am new to this language, am learning, this is what i had done.. will you plz help me out.. :(

class Student
{
public:
void getData(string& name, int& age);
Student(string name, int age);
void print(void);
private:
char m_name[20];
int m_age;
}

Looks like the only thing you do not have is the default constructor. That is a constructor with no parameters.

you have char arrays and strings mixed up. If your teacher is ok with it, I would use only strings, it'll make your live alot easier

In the implementation of the contructor, just assign the values given to the contructor to the two private variables (m_name and m_age)

the function print is by far the easiest one. Just use cout << to display the two private variables. These will always have a value if you follow my advice on the contructor.

The getData function is a little bit trickier. Do you know how to pass values by reference? Your code suggests that you do, but I guess it was given to you by you teacher?

With this information, try to write some more code to implement at least the constructor and print code. Come back if you encounter any problems.

The instructions posted say nothing about coding the implementation of that class. Only need to declare the class.

The instructions posted say nothing about coding the implementation of that class. Only need to declare the class.

Whoops, I misread that completely :icon_redface:

At anifeelings:

Disregard my post completely. Do as Ancient Dragon said and your done..
My apologies for any confusion my post may have cost...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.