Homework #11
- Goal:
Design the constructor and the destructor of a class.
- Please UPLOAD your homework (ZIP or RAR file) to TA at
http://ms11.voip.edu.tw/cs102/
- Deadline: 2008/5/4 08:30 AM
- Requirement:
- Define a class Student, which has three data members:
- name
- This ia only a character point, so you need to
dynamically allocate the memory space from the free store for the name of a
student.
- gender
- This data member belongs to a enumeration data type
"Gender", which has two possible values Female and Male.
See P.60-62 in Chapter 2 to review this concept.
- age
- The reasonable value of age cannot be larger than 200,
so choose an appropriate data type for it.
- name and gender are public, but age is private. Other student
can only know your age via an AskedBy() member function.
- Carefully design the constructor and destructor to allocate and
release memory to store student names.
- The actual age of a woman is a secret.
- If a man asks her, then
younger students (with ages less than or equal to 20) will reply
an age which is 50% more, so that it sounds more "mature".
On the contrary, older students will give a reply which is only 80%
of her actual age, to make herself "younger".
- If she is asked by a female friend, she will tell the truth
because her friend knows this trick.
- For a male student, he will tell you his actual age because
there is nothing to hide.
- Suppose we have 4 students:
- Alice, Female, 28
- Bob, Male, 20
- Charlie, Male, 40
- Denise, Female, 16
- Write a program to display a table which shows the answer they
will get when they are asking each other's age. You should obtain
something like:
Asked By | Alice | Bob | Charlie | Denise
|
---|
Alice | 28 | 22 | 22 | 28
|
Bob | 20 | 20 | 20 | 20
|
Charlie | 40 | 40 | 40 | 40
|
Denise | 16 | 24 | 24 | 16
|