[go: up one dir, main page]

0% found this document useful (1 vote)
230 views10 pages

COS10008 Assignment2-TP1-2019

Uploaded by

qwerty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
230 views10 pages

COS10008 Assignment2-TP1-2019

Uploaded by

qwerty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

COS10008 – Foundations of Technical Programming

Foundations of Technical Programming


Assignment 2
1 x 15 = 15 marks
2 X 5 = 10 marks
Total = 25 marks

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.

Please visit https://goo.gl/hQ87zg for more details.

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

©Copyright: 2019 Swinburne University of Technology CRICOS: 0011D TOID: 3059


Assignment 2 10/04/2019
Version 1 Page 1 of 10
COS10008 – Foundations of Technical Programming

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:

a. The program should be menu driven


b. Each member could maintain zero (0) or many policies
c. Each policy will be linked a member
d. Each policy will have a non-negative premium
e. The types of policies are car, health, travel and pet
f. The program should be capable of reading any number of members and any number of policies under
each member
g. The program should have facility to search members by member name
h. The program should have facility to calculate the total premium across all the policies
i. The program should have facility to display all members and policies details

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:

a. Use appropriate C – language constructs to create member records - Structures


b. Use appropriate C – language constructs to create policy records – Nested Structures
c. Ensure your approach allows a member to maintain 0 or many policies
d. Use enum to create policy types
e. Use dynamic member allocation to create and maintain any number of members and policies.
f. Total premium calculation should be done using Recursive Function

©Copyright: 2019 Swinburne University of Technology CRICOS: 0011D TOID: 3059


Assignment 2 10/04/2019
Version 1 Page 2 of 10
COS10008 – Foundations of Technical Programming

The main menu of your program should be:

1. Add new member


2. Display all members
3. Search member by name
4. Calculate total premium
5. Exit

Enter your choice---1

On selection of option: 1, the following details to be collected

a. Enter the member details:


b. Member Name:
c. Member ID:
d. How may policy/ies for the member

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 two in the main menu:

1. Add new member


2. Display all members
3. Search member by name
4. Calculate total premium
5. Exit

Enter your choice---2

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

Member Name: Amber


Member ID: 1001
Policy ID: P101
Type: Health
Premium: 1200

©Copyright: 2019 Swinburne University of Technology CRICOS: 0011D TOID: 3059


Assignment 2 10/04/2019
Version 1 Page 3 of 10
COS10008 – Foundations of Technical Programming

Member Name: Aiden


Member ID: 1002
Policy ID: P102
Type: Health
Premium: 1000

Policy ID: P103


Type: Car
Premium: 800

On selection of option 3 in the main menu:

1. Add new member


2. Display all members
3. Search member by name
4. Calculate total premium
5. Exit

Enter your choice---3

On selection of option 3 from the main menu, the program to display the following options:

Enter the name of the member: Amber

Details for Amber:


Member ID: 1001
Number of Policies: 1
Policy ID: 101
Type: Health
Premium: 1200

Enter the name of the member: Helen

Sorry, no details for Helen found.

On selection of option 4 in the main menu:

1. Add new member


2. Display all members
3. Search member by name
4. Calculate total premium
5. Exit

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

Total premium: 2000

©Copyright: 2019 Swinburne University of Technology CRICOS: 0011D TOID: 3059


Assignment 2 10/04/2019
Version 1 Page 4 of 10
COS10008 – Foundations of Technical Programming

On selection of option 5 in the main menu:

1. Add new member


2. Display all members
3. Search member by name
4. Calculate total premium
5. Exit

On selection of option 5, the program should terminate.

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

This question has two parts.


Part 1:
Write a complete program to draw rectangles on a SwinGame graphics window with width 1 and height
equal to the values of the array elements.
Your program should have four functions, main(), get_color(), fill_array() and draw_bar().

use SIZE 800

©Copyright: 2019 Swinburne University of Technology CRICOS: 0011D TOID: 3059


Assignment 2 10/04/2019
Version 1 Page 5 of 10
COS10008 – Foundations of Technical Programming

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

©Copyright: 2019 Swinburne University of Technology CRICOS: 0011D TOID: 3059


Assignment 2 10/04/2019
Version 1 Page 6 of 10
COS10008 – Foundations of Technical Programming

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

©Copyright: 2019 Swinburne University of Technology CRICOS: 0011D TOID: 3059


Assignment 2 10/04/2019
Version 1 Page 7 of 10
COS10008 – Foundations of Technical Programming

Output:

©Copyright: 2019 Swinburne University of Technology CRICOS: 0011D TOID: 3059


Assignment 2 10/04/2019
Version 1 Page 8 of 10
COS10008 – Foundations of Technical Programming

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.

©Copyright: 2019 Swinburne University of Technology CRICOS: 0011D TOID: 3059


Assignment 2 10/04/2019
Version 1 Page 9 of 10
COS10008 – Foundations of Technical Programming

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

©Copyright: 2019 Swinburne University of Technology CRICOS: 0011D TOID: 3059


Assignment 2 10/04/2019
Version 1 Page 10 of 10

You might also like