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
void getData(string& name, int& age);
Student(string name, int age);
void print(void);
char m_name[20];
int m_age;

10 Years
Discussion Span
Last Post by Nick Evan

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.

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...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.