Assessment Overview
This assessment aims at testing basic concepts of C++ programming, such as inheritance, information hiding, overloading, friend functions, vector, constructor and related software engineering concepts. The marking criteria are as follows:
Problem 1 (5 marks)
Write a function
Int[] union_Array (int a[], int lenA, int b[], int lenB)
that constructs the union of two integer arrays and removes any element that occurs more than once. For example, if two arrays of the union_Array are {1, 8, 16 } and {11, 8, 7, 1}, it will return an array of {1, 8, 16, 11, 7}.
Tasks:
1. The length of two arrays should be different and defined by constants using “#define”. (1 mark)
2. Arrays are inputted from the keyboard.(1 mark)
3. Call the function union_Array in your main function. Initialize two arrays. Print out the new array (there is no requirement for the order of the output elements). (1 marks)
4. Compile and run correctly(2 marks)
Problem 2 (5 marks)
Given a student class to represent student information as follows:
class Student{
string stuId;
string name;
double mathScore;
double chineseScore;
double englishScore;
};
Write a program to achieve the following tasks:
1. Use an array to save student information. The length of the array should be defined by a constant using “const”. (1 mark)
2. Student information is inputted from the keyboard. (1 mark)
3. Print out the student ID and average mark of three courses for each student in a descending sequence.(1 mark)
4. Print out student ID whose average mark is smaller than the average mark of all students.(1 mark)
5. Compile and run correctly. (2 marks)
Problem 3 (5 marks)
Given a student structure to represent student information as follows:
structure student{
string stuId;
string name;
double mathScore;
double chineseScore;
double englishScore;
};
Write a program to achieve the following tasks:
1. Use a pointer and linked list to save student information. The length of the linked list (number of student objects) should be inputted from the keyboard. (1 mark)
2. Student information is inputted from the keyboard. (1 mark)
3. Print out the student ID and average mark of three courses for each student in a descending sequence. (1 mark)
4. Print out student ID whose average mark is smaller than the average mark of all students. (1 mark)
5. Compile and run correctly. (1 mark)
Problem 4 (5 marks)
Given a function header as char *findC (char const *source, char const *obj):
Write a program to achieve the following tasks:
1. Write a function to search a character sequence pointed to by a pointer (called “obj”), in another character sequence (called “source”). Return the pointer pointing to the found character. If there is more than one target found in the source, return the pointer pointing to the first one. (2 marks)
Eg1: search for “C” in “ABCDEF”, return the pointer point to ‘C’.
Eg2: search for “Z” in “ABCDEF”, return a NULL pointer.
Eg3: search for “CD” in “ABCDEF”, return the pointer point to ‘C’.
Eg4: search for “CF” in “ABCDEF”, return a NULL pointer.
Eg5: search for “A” in “ABCAFC”, return the pointer point to the first ‘A’.
2. Write a main function to input two strings by the keyboard and print the position of the pointer in the source string(print -1 if the function returns a NULL pointer). (1 mark)
3. Compile and run correctly. (2 marks)
Problem 5 (10 marks)
Given a circle class to represent circle information as follows:
class Circle{
int x;
int y;
double radius;
};
Write a program to achieve the following tasks:
1. The centre point of (x,y) and radius should be inputted from the keyboard. (1 mark)
2. Define a method that can calculate and return the circle’s area. (1 marks)
3. Define an overloading operator + to add two circle objects and get a new circle object. The centre point of the new circle object is the same as the centre point of the first circle object. The area of the new circle object should be the sum of the areas of two circle objects (You can calculate the radius of the new circle based on the sum of the area of two circles). (2 marks)
CPT106 Assessment 1
4. Define a function to print relations of two circles(interaction, tangency, separation and inside) (2 marks)
5. Define a main function to input two circle objects, get a new circle object based on these two circle objects and print the relations of these two circle objects. (2 marks)
6. Compile and run correctly. (2 marks)