C++代写:SEHH2042 Additional Assignment

完成关于C++入门的6个小程序。

Requirement

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.

Question 1

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

Sample display 2

12345678912345
11.23TB

Question 2

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

5
|     |
|     |
|*****|
 \***/
  ---
   |
   |
   |
  ---

Sample display 2

7
|       |
|       |
|       |
|*******|
 \*****/
  \***/
   ---
    |
    |
    |
    |
   ---

Question 3

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.

3rd digit of Student ID Find
Odd The most and largest appeared digit
Even The least and smallest appeared digit

Sample display (for odd)

12342234 34
2
123402345
4

Sample display (for even)

12342234 34
2
123402345 
0

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

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

Question 5

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:

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.

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)

7
2
48 70
73 55
48 71
30 80
63 79
70 30
27 50
3
55.3333

Sample display (for even)

7
2
48 70
73 55
48 71
30 80
63 79
70 30
27 50
3
30

Question 6

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.

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

Assumptions:

  • User will input at most 1000 records.
  • No duplicate of student ID with the same course code.

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)

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.