SEHH2042 Computer Programming
Assignment 2Individual assignment Submission deadline: 18:00, 2 December 2019 Monday
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 A2Template.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. See Appendix
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 text is required.
There should be NO BLANK LINE in the output, except those given in the main function of the template file.
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 : 101
Tutorial: A
SEHH2042 1920 Semester 1Individual assignment 2 1
Question 1
Write a program to accept user input of nonzero integers, until user inputs 0 to indicate the end of input. Then the program removes all duplicate numbers and displays the remaining numbers in ascending or descending order. You should display the numbers in a row separated by a space. The last input 0 is not included. You may assume that user inputs at most 1000 integers.
3rd digit of Student ID
Display in
Odd
Ascending order
Even
Descending order
Sample display for even
123
20
123
5
3
20
20
666
5
3
00
666 5 3 20 123 123 20 3 5 666
Question 2
Write a program to calculate addition or subtraction of two very large positive integers. The size of input integer is larger than C can handle, e.g. more than 30 digits. Therefore you may need consider user input as string. You may assume that the first input is not less than the second input, and all integers involved including answer are less than 1000 digits.
Sample display for odd
12345678901234567890123456789012345678901234567890 13579135791357913579135791357913579 12345678901234581469259248146925924814692592481469
Sample display for even
12345678901234567890123456789012345678901234567890 13579135791357913579135791357913579 12345678901234554310987665431098766543109876654311
Hint: Dont miss the fact that answer may have more or less digits than user input. e.g. 9999991998 not 998, and 9999990 not 000.
Sample display for odd
123
20
123
5
3
20
20
666
5
3
4th digit of Student ID
Calculate
Odd
Addition
Even
Subtraction
SEHH2042 1920 Semester 1Individual assignment 2 2
Question 3
Write a program to accept user input of a long string with spaces that ends with n, and then displays how many capital or small letters are there. You may assume the input string is less than 1000 characters.
Sample display for odd
SEHH2042 Computer Programming is EASY!!!
10
Sample display for even
SEHH2042 Computer Programming is EASY!!!
19
Question 4
Write a program to accept user input of a long string with spaces that ends with n, and then calculate the sum of all odd or even numbers in the string. You may assume the input string is less than 1000 characters, and all numbers are integers.
Sample display for odd
I take SEHH2041 and SEHH2042 in HKCC, with the overall scores 88 and 91, respectively.
2132
Sample display for even
I take SEHH2041 and SEHH2042 in HKCC, with the overall scores 88 and 91, respectively.
2130
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: StudentNameID.cpp. Remove all spaces, hyphens and other nonletter characters in the filename. A correct filename should look like: ChanTaiMan12345678A.cpp.
5th digit of Student ID
Count
Odd
Capital letters
Even
Small letters
6th digit of Student ID
Sum
Odd
Odd numbers
Even
Even numbers
SEHH2042 1920 Semester 1Individual assignment 2 3
Grading Criteria
Your program will be executed by script with different test cases in Microsoft Visual Studio 2017. 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.
Criteria
Marks allocation out of 100 marks
ShowInfo
10
Program Correctness of Questions 14 According to test case result
90
Important Notes
Late submission: No late submission is allowed. You will get 0 mark if you submit late. Syntax error: You will get 0 mark if your program fails to be compiled.
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 extra text, or incorrectly decide the oddeven version, etc.
Ensure the originality of your work. Plagiarism in any form is highly prohibited.
End
SEHH2042 1920 Semester 1Individual assignment 2 4
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 template file in Microsoft Visual Studio 2017 before submission.
myQuestion1.cpp
1
include iostream
include iomanip
using namespace std;
int main
int number1234;
2
coutThis is appendixn;
coutDisplay a number: setw5number; return 0;
A2Template.cpp
Insert more header files when necessary
include iostream
include iomanip
using namespace std;
void showInfo
Insert
void Q1
your codes to display your personal particulars here
your codes for Question 1 here
Insert
int number1234;
coutThis is appendixn;
coutDisplay a number: setw5number;
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 1920 Semester 1Individual assignment 2 5
Reviews
There are no reviews yet.