Department of Electronic and Information Engineering
Computer Programming (ENG236) Homework 1
(Note: the format of Programming Test 1 is very similar to this homework.)
A. Background
Sorting is one of the most common operations in computing. There are many studies on the methods of sorting and many fast algorithms have been devised. Nevertheless, if the number of items to be sorted is not that many, some simple approaches can also be very effective. The following is one of them. Assume that A, B, C, D, E are 5 variables storing
5 numbers respectively; and we would like to show the numbers on the screen in descending order. It can be done using the procedure as follows.
1.
2.
3.
4.
5.
Initialize a variable number F that keeps a very large value (must be larger than those values of A, B, C, D, E)
Search among the batch for the biggest number, which is smaller than the value of F
Show that number on the screen
Save that number’s value to F and replace the value that number variable in the batch with a very small value
Repeat steps 2, 3, and 4 until all the 5 numbers in the batch are shown on the screen.
B. The Programming Task
By using C++ and the Visual Studio 2010 development environment, implement a simple sorting application program with details as follows.
Q1.
Start a new project with name “partQ1” to do this question. The project MUST be stored in the folder e:\temp\a\. It should be a console application that shows the following main menu:
1. Input data
2. Select operation
3. Quit
Please enter your choice (1, 2, or 3 to quit):
Users are expected to enter an integer of value 1, 2 or 3 only. When any other numbers (i.e. not characters) are entered, the program will display “Invalid input..... Please enter again!” and the main menu will be shown again. Note: It is assumed that the user must enter an integer; the program need not handle non-integer input.
If the user selects 3, the program