Suggest
that every candidate creates a “Win32 Console Application” project (or any
other project that they feel comfortable with) and the folder created by VC++
(maybe named as the candidate’s name ?) should be returned here (they can even
use notepad if they don’t like VC++, but the studio will help them
debug/compile the problem). We only need the files with the class/functions
requested (we expect one .h and one .cpp file) if too difficult for you to
select then send the entire folder
Visual
C++ 2008 Express Edition can be installed from here if required:
1.Write a C++ class (Employee)
that has name (string) and weight (int) as protected data members.
The name can be of any length.
Implement the
following methods in the class: constructor
(takes a name and a weight as parameters), destructor,
GetName (returns the name), GetWeight (returns the weight) and a virtualmethod GetType that returns the type of object (employee in this
case).
2.Add a second class named Manager, inherited from
Employee that has the same
constructor as Employee and also overrides
the method GetType to return the new object type: manager.
3.In a global function add the
following objects to an array of void
pointers of size 10:
-type employee: name Matt,
weight 89
-type employee: name John,
weight 79
-type employee: name Andy,
weight 59
-type manager: name Nick, weight
65
-type employee: name Chris,
weight 86
-type employee: name Rob, weight
75
-type manager: name Conrad,
weight 83
-type manager: name David,
weight 110
-type employee: name Richard,
weight 63
-type manager: name Paul, weight
95
4.Implement a function called Sort that sorts the array
given above by the object type (managers
first) and then by weight (ascending)
if the type is the same.
General observations:
-no external/API functions
should be used (like string, use char* instead of any library versions of
string)
-it is not necessary to output/format
the results, these can be seen by running the program in debug mode
-help documentation can be used
-if point 2 is too difficult
then marks will be given for point 4 even if the sorting is done only byweight using same type objects in the array
-besides functionality, marks
will be given for the style of coding and the tidiness of the code
// PART 2 of the test class CManager: public CEmployee { public: CManager(char* strName, int nNameLen, int nWeight) : CEmployee(strName, nNameLen, nWeight) {}
// PART 1 of the test // 评: {对参数 strName, nNameLen, nWeight的合法性未做检查, 也没有错误处理机制 } CEmployee::CEmployee(char* strName, int nNameLen, int nWeight) { m_strName = new char[nNameLen + 1]; for (int i = 0; i < nNameLen; i++) { m_strName[i] = strName[i]; } m_strName[nNameLen] = 0;