程序代写代做 C c++ HONG KONG COMMUNITY COLLEGE Subject Code : SEHH2042

HONG KONG COMMUNITY COLLEGE Subject Code : SEHH2042
Subject Title : Computer Programming
This assignment has a total of SEVEN pages (including this covering page).
Declaration of Original Work
By submitting this assignment to the subject lecturer through Moodle, you hereby declare that the work in this assignment is completely your own work. No part of this assignment is taken from other people’s work without giving them credit. All references have been clearly cited.
You understand that an infringement of this declaration leaves you subject to disciplinary actions such as mark deduction, disqualification or even expulsion by the College.
Important points to follow:
1. You should use the given template file (sehh2042Template.cpp) to answer all questions.
2. Fill your code in the showInfo( ) function to display your name, student ID and class.
3. To answer each question, fill your code in the place as specified in the template file.
4. Apart from inserting codes as mentioned above, you are NOT allowed to modify any
codes in the given template file.
5. You may assume that user always provides valid input. NO error checking is required.
6. You need to follow EXACTLY the requirement and sample output format as stated in
the corresponding question. NO extra display text is required.
7. Make sure that your submitted .cpp file (i.e. template file filled in with your answer) can
be opened and contains no syntax error. Otherwise, you will get ZERO mark as your
work cannot be tested.
8. Only the last submission you made within the designated timeslot will be counted.
9. If necessary, students may be invited to provide more information on their submission.
SEHH2042 1920s2 Additional Assignment Page 1 of 7

Question 1 (15%)
For a computer system, the file size is presented in terms of number of bytes (B). The following units are used to represent larger size: 1KB = 1024B, 1MB = 1024KB, 1GB = 1024MB, and 1TB = 1024GB.
Write a program to display the input number of bytes (a double value) with an appropriate unit, so that the numeric value is always shown within 1024. Display the value in two decimal places. You may assume that the largest value is 1023.99TB.
Sample display 1
123
123.00B
Question 2 (15%)
Sample display 2
12345678912345
11.23TB
Write a program to display the pattern of a glass of wine according to the size input by user. The size is an odd integer at least 5.
Sample display 1 Sample display 2 Sample display 3 Sample display 4
5 7 9 15
|||||||| ||||||||
|*****| | | | |
| | | | | | | | | | |***************| \*************/ \***********/ \*********/ \*******/ \*****/
\***/

|
|
|
|
|
|
|
|

\***/

|
|
|

|*******| | | \*****/ |*********|
\***/ \*******/ — \*****/ | \***/
| — | | | |
— | | |

SEHH2042 1920s2
Additional Assignment
Page 2 of 7

Question 3 (15%)
Write a function counting( ) that accepts two integer arguments, n and k, and returns the number of occurrence of k in n. For example, counting(123456123, 123) should return 2. Demonstrate the use of the function in Q3( ) as shown in the first two lines of the sample displays.
Then, by using the function counting( ), determine the most and largest (or least and smallest) appeared digit of another input integer, as shown in the last two lines of the sample displays.
Sample display (for odd) Sample display (for even)
12342234 34 12342234 34
22
123402345 123402345
40
Note: In 123423450, digits 2, 3 and 4 appear the most (2 times). The largest digit among them is 4. Similarly, digits 1, 0 and 5 appear the least (1 time). The smallest digit among them is 0.
Question 4 (15%)
Implement the class RightTriangle with the following:
– Private data members for the ID, side a and side b of a right triangle: id (int), a (double), b (double);
– A private member function hypo( ) that returns the length of the hypotenuse of a right triangle (Use Pythagorean Theorem in your calculation);
– A constructor function that initializes the data member id of the object that is created;
– A member function setSides( ) that assigns the arguments to data members a and b;
– A member function display( ) that prints the ID, the length of all 3 sides and value of angle A (or
B), in degree format, of the right triangle object. Call hypo( ) in your implementation.
A
3rd digit of Student ID
Find
Odd
The most and largest appeared digit
Even
The least and smallest appeared digit
6th digit of Student ID
Angle to print
Odd
A (angle opposite to side a)
Even
B (angle opposite to side b)
Use 3.14159265 as the π value. B
The code given in Q4( ) demonstrates how the class is used. The sample display below will be produced if the class is implemented correctly. (You can assume all inputs to the member functions are positive when the class is used.)
Sample display (for odd)
1:3/4/5/36.8699 2:5/6/7.81025/39.8056
Sample display (for even)
1:3/4/5/53.1301 2:5/6/7.81025/50.1944
SEHH2042 1920s2
Additional Assignment Page 3 of 7
hypotenuse
b C

Question 5 (20%)
Suppose that there are n students in a class, and that each student has taken t tests. For any two students A and B, we say that A beats B if both of the conditions below are satisfied:
• A’s score is greater than or equal to B’s score on every test.
• There exists at least one test in which A’s score is greater than B’s score.
For every student A, we say that A is unbeaten if no students beats A.
Write a program to find the number of students who are unbeaten. Then return another number
according to the following table:
Remarks: Both n and t are positive integers. The score obtained by a student from any test is a non-negative integer (so, a score of 60.5 is not possible). Do not assume that the maximum score of a test is 100.
Assumptions. The maximum value of n is 1,000, and the maximum value of t is 50.
User inputs:
1. The first line contains a number indicating the value of n.
2. The second line contains a number indicating the value of t.
3. Each of the subsequent n lines contains t numbers, indicating the scores of a student on
the t tests. On each line, the ith number corresponds to the score of the ith test. There is a white space between any two scores.
Program outputs:
1. The first line contains the number of students who are unbeaten.
2. The second line contains the number indicated in the table above.
Sample display (for odd) Sample display (for even)
77 22
5th digit of Student ID
Another number to be returned
Odd
The average score in the first test among the unbeaten students. Display the value in the default format.
Even
The minimum score in the first test among the unbeaten students.
48 70
73 55
48 71
30 80
63 79
70 30
27 50 33 55.3333 30
48 70
73 55
48 71
30 80
63 79
70 30
27 50
SEHH2042 1920s2 Additional Assignment Page 4 of 7

Question 6 (20%)
Write a program to manage a list of records. User first inputs several records, until the string “END” that indicates the end of input. Each record consists of a course code (8-char long string), a student ID (9-char long string) and a score (non-negative, double).
Then the program allows user to search the records by course code (or student ID). If there is no match, the program displays “No such record”. Otherwise, it displays the following and the average, maximum and minimum scores among the matched records. All numeric values are displayed in 1 decimal place.
Assumptions:
– User will input at most 1000 records.
– No duplicate of student ID with the same course code.
6th digit of Student ID
Search by
Display matched records in …
Odd
Student ID
Descending order of course code
Even
Course code
Ascending order of student ID
Sample display – match (for odd)
SEHH2042 19100001A 76.4
SEHH2042 18001234A 85.2
SEHH2042 19000123A 45.5
SEHH3140 18001234A 89.3
SEHH1034 19100001A 45.7
SEHH1034 18001234A 88.4
SEHH2271 18001234A 85.4
END
18001234A
SEHH3140 89.3
SEHH2271 85.4
SEHH2042 85.2
SEHH1034 88.4
Average: 87.1
Maximum: 89.3
Minimum: 85.2
Sample display – no match (for odd)
Sample display – match (for even)
SEHH2042 SEHH2042 SEHH2042 SEHH3140 SEHH1034 SEHH1034 SEHH2271
END
SEHH1034
No such record
SEHH2042 1920s2
Additional Assignment
Page 5 of 7
19100001A 76.4
18001234A 85.2
19000123A 45.5
18001234A 89.3
19100001A 45.7
18001234A 88.4
18001234A 85.4
Sample display – no match (for even)
SEHH2042 19100001A 76.4
SEHH2042 18001234A 85.2
SEHH2042 19000123A 45.5
SEHH3140 18001234A 89.3
SEHH1034 19100001A 45.7
SEHH1034 18001234A 88.4
SEHH2271 18001234A 85.4
END
18001234A
No such record
SEHH2042 SEHH2042 SEHH2042 SEHH3140 SEHH1034 SEHH1034 SEHH2271
END
SEHH1034 18001234A 88.4 19100001A 45.7 Average: 67.1 Maximum: 88.4 Minimum: 45.7
19100001A 76.4
18001234A 85.2
19000123A 45.5
18001234A 89.3
19100001A 45.7
18001234A 88.4
18001234A 85.4

Submission
You are required to insert your C++ code into the given template file, and submit the final source file to Moodle before the deadline. Use your student name and ID as the filename: StudentID_Name.cpp. Remove all spaces, hyphens and other non-letter characters in the filename. A correct filename should look like: 12345678A_ChanTaiMan.cpp.
Grading
Your program (i.e. the template file with your answers) will be executed by script with different test cases in Microsoft Visual Studio. You need to follow EXACTLY the above input and output requirements. Any deviation from the requirement is considered as incorrect and no mark is given for that case.
Syntax error: 100% deduction. You will get 0 mark if your program fails to be compiled. Check your final source file using Microsoft Visual Studio (not those online compliers) carefully before submission.
Runtime error: No mark for the particular test case that triggers the runtime error.
Logic error (bug): No mark for the particular test case that deviates from the requirement. Note that a logic error may lead to failure in ALL test cases of a question, e.g. displaying prompt messages, incorrect spelling and/or number format, or incorrectly decide the odd/even version, etc.
– End of Assignment –
SEHH2042 1920s2 Additional Assignment Page 6 of 7

Appendix
If you implement the questions in separated source files, you need to copy the program codes into the template file for assignment submission. Make sure to test the final source file (i.e. template file with your answers) in Microsoft Visual Studio before submission.
myQuestion1.cpp
1
2
#include
#include
using namespace std;
void display(int n) {
cout << "This is appendix\n"; cout << "Display a number: " << setw(5) << n; } int main() { int number = 1234; display(number); return 0; } 3 Template.cpp // Insert more header files when necessary #include
#include
using namespace std;
void showInfo()
{
// Insert your codes to display your personal particulars here
}
// Insert your function, class (if any) for Q1() here
void display(int n) {
cout << "This is appendix\n"; cout << "Display a number: " << setw(5) << n; } void Q1() { // Insert your codes for Question 1 here int number = 1234; display(number); } // ... the rest of the template file ... 1. The header files included in your program should also be included in the template file. 2. The user-defined function / class for a question should be copied before the question. 3. The program main body, except “return 0”, should be copied to the function body of the corresponding question. SEHH2042 1920s2 Additional Assignment Page 7 of 7