COS10008 Assignment2-TP1-2019
COS10008 Assignment2-TP1-2019
You may be asked to demonstrate/explain your work to the tutor, if you are
absent/unavailable or fail to demonstrate properly, zero marks will be awarded.
Please note, this is an individual task and it will be checked for plagiarism. All the
involved parties will be penalised if any plagiarism is found.
Instructions
1. This assignment contains 3 questions (topics from week 1 to 10), one question
carries 15 marks and two questions 5 marks each.
2. Submit only one document (Single word document)
3. Copy and paste your codes into word document
4. Copy and paste the screen shot of the output window in the same word document
5. Use only .doc, .docx extensions – no other format will be accepted for marking
6. Marks will be given for proper indentation and comments
7. For question 3 use SwinGame (SwinGame SDK is available on the Canvas).
Qn1. 15 Marks
A leading insurance provider maintain their customer (Member) details based on the following database table
structure.
Member Policy
Member_ID Name Count of Policy_ID Member_ID Policy_Type Premium
policies Ex: P101 1001 Health 1200
Ex: 1001 Amber 1 Ex: P102 1002 Health 1000
Ex: 1002 Aiden 2 Ex: P103 1002 Car 800
The insurance company has approached you to develop a simple menu drive program to read and manage
members and policies details. The company has made the following requirements:
As part of this assessment, you are required to develop C – language-based program to fulfil the above
requirements. Your program should be based on the following instructions:
Based on the input to option d, the program should read policy details
a. Enter policy ID
b. Enter Policy type
c. Enter premium
On selection of option 2, the program to display all the member details and details of each policy/ies held by the
member. The output to be in the following format
On selection of option 3 from the main menu, the program to display the following options:
On selection of option 4 from the main menu, the program to display the following the total premium for the
insurance company (The total premium calculation should be implemented using Recursive Function).
Qn2. 5 Marks
Create a one-dimension array to read 20 alphabetical letters (your program should be able to detect and
print out an error message if a non-alphabetical letter is inputted).
As each letter is entered, print it only if it has been entered before.
Write a function that can sort the array after all 20 letters have been entered.
Write another function that print out the most frequent letter and number of time it was entered.
Prepare for the case where all 20 letters are different, or all are the same. Use the smallest possible
variables and minimum array size to solve the problem.
Qn3. 5 Marks
---------------------------------
Function: Main
---------------------------------
Local Variables:
- data (struct sample array with 800 (use SIZE) elements)
Steps:
1: Open a Graphics Window with title “Array rectangles” that is
800x700
2: Call srand() function
3: Call fill_array() passing data array
4: Do
5: Process Events
6: Clear the Screen to COLOR_WHITE
7: Call draw_bar() function passing data array
8: Refresh the Screen limiting it to 60 FPS
9: While Window Close is not Requested
---------------------------------
Function: get_color
---------------------------------
Parameters received – num (integer value)
Return type - color
Local Variables:
- clr (color)
- hue (float)
Steps:
1: set hue, the value of num devided with screen height (typecast for
float value)
2: set clr, the value returned by hsbcolor(hue,0.7,0.8)
3: return clr
---------------------------------
Function: fill_array
---------------------------------
Parameters received – data (struct sample array)
Return type - void
Local Variables:
- i (int for loop counter)
Fill the data array’s value element with 800 random integers ranging
between 0 to 699 (you can take modulus with screen height.
Fill the data array’s clr element with color returned by getcolor
function (getcolor function is called by passing each array element)
---------------------------------
Function: draw_bar
---------------------------------
Parameters – data (struct sample array)
Return type - void
Local Variables:
- i (int for loop counter)
- x,y, rectwidth (float values)
Steps
1: Set the rectwidth the value 1
2: Start a for loop that runs 800 times
3: Set x, the value of rectwidth times i
4: Set y, the value Screen Height – data[i].value
5: Fill Rectangle with data[i].clr, at position x,
y, with width rectwidth and height value part of data
array
Output:
Once you have completed part 1 extend your program to include a sort_data function. When the user
press the key S or R (SKEY and RKEY) the sort_data function should be called and it should sort the
rectangles in ascending order as shown below. Sort function is called with in the main inside do … while
loop.
---------------------------------
Function: sort_data
---------------------------------
Parameters – data (int array)
Return type - void
Local Variables:
- I,j and temp (int)
Steps
1: for i, starts at 0 goes to SIZE -1
2: for j, starts at 0 goes to SIZE-1-i
3: if value part of data[j] > value part of data[j+1]
4: Set temp, the value part of data[j]
5: Set value part of data[j], the value part of data[j+1]
6: Set value part of data[j+1] equal to temp