程序代写代做代考 javascript scheme database Java algorithm Aims

Aims
Assigment2: Functions
CS5002 – Programming Principles and Practice
Due Date: Tuesday 25th October 2016 at 9pm Weight: 30% of the coursework (and the module)
The aim of this assignment is that you should learn to
 Process arrays;
 Write and call functions; and
 Perform calculations
Introduction
This is the second coursework in CS5002, which is designed to practise more advanced programming concepts such as arrays, functions, and objects in small real-world problems. You will write programs to complete programming questions 1 and 2, which are the main compulsory part of this coursework. Question 3 is an additional extension activity, which is optional. Without doing any extension activities the highest mark that you can achieve is 17.
Programming Questions
Question 1:
Write a program which acts as a database for a hospital to look through patient records. You should use arrays to store the following information:
Patient ID number (CHI number)
Name
GP Doctor
Last measured heart rate (bpm)
0404847102
Oprah Blunt
Dr Mirren
48
3003745085
Kylie Banks
Dr Khalifa
74
0412689170
Michael Sigler
Dr Swift
114
0202923266
Khloe Foxx
Dr Clooney
92
2006473093
Justin Ora
Dr Mirren
121
1003478700
Rita Bieber
Dr Aniston
61
1310940614
Zayn Jackson
Dr DiCaprio
68
2006303716
Jamie Goulding
Dr Clooney
70
0211488682
Snooki Carey
Dr Lavigne
65
You may enter this information directly into the code.

Implement the following functions:
1. printAllPatients() – this function should print the whole database of patients to the console in a sensible format.
2. printByPatientName(name) – this function should print the details of a patient with a specified name.
3. printByGP(GP) – this function should print only the patients looked after by the specified GP doctor.
4. printOverHR(HR) – this function should print only the patients which are over the specified heart rate.
5. printAllPatientsSorted(sortedBy) – this function should print all the patients sorted by either Heart rate, by Patient Name or by GP. The parameter should specify which ordering is requested. The function should also support sorting in reverse order.
Test your code with user inputs. Try using multiple functions at once in your testing – i.e. print all the patients by one GP doctor, sorted by heart rate; or print all the patients by a particular GP doctor under a certain heart rate.
Note: To gain full credit, the program should satisfy the following requirements:
1. It should be able to deal with “no found” cases; that is, what if there exists no match for
the user’s input.
2. It should be robust to deal with invalid input; that is, the user inputs nothing.
3. It should be robust to deal with names that are correctly spelled but with incorrectly
upper/lower-case. How do you help the user to search the right answer?
4. The displayed result should be informative, displaying the information in an easy-to-
read way.
Question 2:
A persons Community Health Index (CHI) number uniquely identifies them as a person within the Scottish healthcare system. A 10 digit CHI number has four parts – an initial 6 digits for the persons date of birth (DDMMYY) (DD=day, MM = Month, YY = year (eg 7th February 1975 would be 070275), two randomly generated integer digits, an integer digit (0-9) which represents the gender at birth (even for women odd for men), and a final check digit calculated using a modulus 11 algorithm.
The final check character of a CHI number is calculated as follows from the initial 9 digits:
1. The first 9 digits from the left to right are multiplied by a weighting factor (11 minus it’s position), e.g. when first 9 digits is 221078889:
2. the nine products are summed. For example: 20+18+8+0+42+40+32+24+18 = 202
3. the check digit is 11 minus the product modulo 11.
For example, 202 % 11 = 4, so the check digit is 11 – 4 = 7. Making the full CHI number: 2210788897.
Digits
2
2
1
0
7
8
8
8
9
Weighting factor
10
9
8
7
6
5
4
3
2
Product
20
18
8
0
42
40
32
24
18

If the check digit is 10 then the CHI number is invalid and cannot be used, if the check digit is 11 a check digit of 0 is used instead.
1. Add a valid(CHI) function. The function should return true is CHI number is valid, and false otherwise.
2. Add a validateCHIs() function which checks every patient in the database for CHI validity. If a CHI number is invalid, the patient should be printed to the console, and removed from the database. If all are valid, the function should give appropriate output.
Test the above with new CHI numbers (both correct and incorrect).
Question 3 (Optional):
JavaScript has a built-in function sort() for sorting values.
Research two simple methods of sorting numbers, Selection Sort and Bubble Sort, and implement a program in JavaScript which, given an array of positive integers, returns a sorted array of integers. Try with different inputs to demonstrate its correctness and robustness. What happens when you input very large numbers of array elements? Is there a difference between Bubble Sort and Selection Sort?
Report
Your report should include the output of your programs in snapshot and a description of your design choices and any difficulty that you have encountered. You should show evidence of testing your programs.
Submission
Code: save each of your programs as a .js file; for e.g., cs5002-assignment2-Q1.js.
Save your report as a PDF document. Now package up your JavaScript code and PDF report into one .zip file (for eg, cs5002-assignment2.zip). You need to submit this zip file to the MMS in the slot for Assignment 2.
You should submit your code and report to MMS. Each student should submit the complete set. You should write your own code to answer the assignment questions, only as additional extensions you may also use functions or code from elsewhere (with relevant citations), the core submission should be your own code.
Weighting and Marking
This practical is worth 30% of the grade for CS5002. See the standard mark descriptors in the School Student Handbook:
http://info.cs.st-andrews.ac.uk/student-handbook/learning- teaching/feedback.html#Mark_Descriptors
Lateness
The standard penalty for late submission applies (Scheme B: 1 mark per 8 hour period, or part thereof):
http://info.cs.st-andrews.ac.uk/student-handbook/learning- teaching/assessment.html#lateness-penalties
Good Academic Practice
The University policy on Good Academic Practice Applies:
https://www.st-andrews.ac.uk/students/rules/academicpractice/