程序代写代做 c++ SEHH2042 Computer Programming

SEHH2042 Computer Programming
Mid-term Assignment
Submission deadline: 3 April, 2020 (Week 8, Friday) 18:00
Expected Learning Outcomes
• Familiarise themselves with at least one high level language programming environment.
• Develop a structured and documented computer program.
• Apply the computer programming techniques to solve practical problems.
Introduction
This is an individual assignment. You are given a C++ program template file called MidTemplate.cpp. You are required to insert C++ codes into the template file according to the given instructions. The final program should be able to satisfy all the requirements in this specification.
Instruction
• To answer the questions, you are allowed to insert codes into the functions as specified in the template file.
• You may, and are expected to, write user-defined functions to solve the questions in this assignment. For example, you may write a user-defined function for solving question 1, and call it in the given function Q1( ).
• You can include more header files in the template file if necessary.
• Apart from inserting codes as mentioned above, you are NOT allowed to modify any codes
in the given template file.
• You may assume that user always provides valid input. NO error checking is required.
• You need to follow EXACTLY the requirement and sample output format as stated in the corresponding question. NO extra display text is required.
• There should be NO BLANK LINE in your output, except those near the program selection menu as given in main( ) of the template file.
• IMPORTANT: You will get ZERO mark if your file CANNOT be opened, or your program CANNOT be compiled.
• IMPORTANT: Do not display unnecessary message to ask for user input. This will cause you to fail in all test cases. The format of your program output should be identical to that of the sample display.
SEHH2042 19-20 Semester 2 – Mid-term Assignment 1

ShowInfo
Insert your code in the showInfo function so that your personal particulars are displayed in the following format when the program executes:
Sample display:
Name : XXX YYY ZZZ
Student ID: 19xxxxxxA
Class : 201A
Question 1 (25%)
Write a program to accept a weekday and a time (composed of hour and minute) in 24-hour format. The user further inputs a number of minutes to be added to (or subtracted from) the time. Then it outputs the resulted day and time in 2-digit 24-hour format.
User inputs:
1. day (a string, abbreviation of weekdays: Sun, Mon, Tue, Wed, Thu, Fri, Sat)
2. hour (an integer from 0 to 23, inclusive)
3. minute (an integer from 0 to 59, inclusive)
4. number of minutes (a non-negative integer)
3rd digit of your student ID
Number of minutes to be …
Odd
Added
Even
Subtracted
Program outputs:
1. day and time in 2-digit 24-hour format
Sample display (for odd)
Mon 12 34 2468
Wed 05 42
Remark:
Sample display (for even)
Mon 12 34 2468
Sat 19 26
• 2468 minutes = 1 day 17 hours 8 minutes.
• The number of minutes to add (or subtract) can be any non-negative integer. The
result may be many weeks later (or before).
• The output time is displayed in 2-digit 24-hour format.
SEHH2042 19-20 Semester 2 – Mid-term Assignment 2

Question 2 (25%)
Consider the definition below of a good integer:
A k-digit non-negative integer is said to be good if its value equals to the sum of its own digits each raised to the power of k. Examples of good integers are 0, 1, 5, 153, 1634:
Write a program that accepts a range (two non-negative integers a and b) from user. Then it displays two numbers, one at a line. The first number is the number of good integers in the range (from a to b, or from b to a, depending on whether a or b is smaller), inclusively. The second number is the sum of …
User inputs:
1. Two non-negative integers specifying the range
Program outputs:
1. Number of good integers in the range
2. The sum of two selected good integers according to the table above
Sample display (for odd)
1 1000
13 409
Sample display (for even)
1 1000
13 372
0=01 1
1=1
5=51
153=13 +53 +33 1634=14 +64 +34 +44
4th digit of your student ID
The sum of …
Odd
the largest good integer and the second smallest good integer in the range
Even
the second largest good integer and the smallest good integer in the range
Assumption: The user always inputs a range that contains at least two good integers. Remark: If there are just two good integers only, then second smallest is the same as largest
and second largest is the same as smallest.
SEHH2042 19-20 Semester 2 – Mid-term Assignment 3

Question 3 (25%)
Suppose that there are n integer numbers x1 , x2 ,, xn , whose values are determined by the following table.
From the n numbers above, we want to select (without replacement) three numbers to be the sides of a triangle. The three numbers can form a triangle only if the sum of every two numbers is larger than the value of the remaining number. We say that these three numbers are in a triangular group.
Write a program that accepts an input n , which is a positive integer at least 3. It then outputs the number of triangular groups that can be formed among the n numbers x1 , x2 ,, xn .
User inputs:
1. An integer n (at least 3)
Program outputs:
1. Number of triangular groups can be formed
5th digit of your student ID
Values of the n numbers
Odd
x =20i2 +10i−20, forall i=1,2,,n. i
Even
x =15i2 +11i−3, forall i=1,2,,n. i
Sample display (for odd)
10
16
Sample display (for even)
10
34
Remark: The ordering of the numbers in a group does not matter. For example, 3,4,5 and 5,4,3 are considered the same group.
SEHH2042 19-20 Semester 2 – Mid-term Assignment 4

Question 4 (25%)
Write a program to accept user inputs of some integers, until the user inputs 0 to indicate the end of input. Then, according to the given inputs (excluding the final 0, which is used to indicate the end of input only), calculate the value of the following expression:

• • •
xi is the i -th input integer from user (excluding the final 0), and | xi | is the absolute value of xi
 is the mean (i.e., average) of the input integers (excluding the final 0) xmax is the maximum among the input integers (excluding the final 0) xmin is the minimum among the input integers (excluding the final 0)
log |x|−2 10 i
i
xmax −xmin +1
, where
User inputs:
1. Some integers, ends with 0
Program outputs:
2. Value of expression calculated using input integers (except 0)
Sample display
123
45
-67
8
-9
0 -2.07997
Assumption: The user will enter at least one non-zero integer before entering 0.
Remark:
• As indicated above, the final input value 0 is not used in the calculation.
• The calculation result (floating point value) is displayed in the default format.
• you may use the log10(x) function in the library to calculate log10 (x) , and
use other functions whenever appropriate.
• recall that the notation  is the summation sign. For example, if we have n inputs
x1 , x2 ,, xn , then  xi = x1 + x2 + + xn i
.
SEHH2042 19-20 Semester 2 – Mid-term Assignment 5

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.
Late submission: 100% deduction. No late submission is allowed. Submit your work to Moodle some time ahead of the deadline. Late submissions due to slow internet speed will not be accepted.
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.
Ensure the originality of your work. Plagiarism in any form is highly prohibited.
– End –
SEHH2042 19-20 Semester 2 – Mid-term Assignment 6

Appendix
If you implement the questions in separated source files, you need to copy the corresponding 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
#include
#include
using namespace std;
int main() {
int number = 1234;
cout << "This is appendix\n"; cout << "Display a number: " << setw(5) << number; return 0; } 2 MidTemplate.cpp // Insert more header files when necessary #include
#include
using namespace std;
void showInfo()
{
// Insert
void Q1() {
// Insert
your codes to display your personal particulars here
your codes for Question 1 here
}
int number = 1234;
cout << "This is appendix\n"; cout << "Display a number: " << setw(5) << number; } void Q2() { // Insert your codes for Question 2 here } // ... the rest of the template file ... 1. The header files included in your program should also be included in the template file. 2. The program main body, except “return 0”, should be copied to the function body of the corresponding question. SEHH2042 19-20 Semester 2 – Mid-term Assignment 7