Preview

C++ HW1 ANSWER

Good Essays
Open Document
Open Document
993 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
C++ HW1 ANSWER
THE HONG KONG POLYTECHNIC UNIVERSITY
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

You May Also Find These Documents Helpful

  • Satisfactory Essays

    a1 script win213

    • 380 Words
    • 2 Pages

    If the user does not enter a numeric value the program should prompt for a numeric value…

    • 380 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Week 1 Lab_ CIS_115

    • 439 Words
    • 2 Pages

    Describe your solution using pseudocode. Use the same valid variable names you selected in Step 1.…

    • 439 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    PT1420 Unit 8 Lab 8

    • 365 Words
    • 2 Pages

    Incrementing by Values Other than 1, page 190): Display numbers starting at 0 through 10 by increments of 2. 0,2,4,6,8,10…

    • 365 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    ECET 370 Week 5 Lab 5

    • 650 Words
    • 3 Pages

    Exercise 1: Review of the Lecture Content Create a project using the ArrayList class and the Main class provided in DocSharing. The ArrayList class contains implementations of the first three search methods explained in this week's lecture: sequential, sorted, and binary search. The Main class uses these three methods. These programs test the code discussed in the lecture. Compile the project, run it, and review the code that is given carefully.…

    • 650 Words
    • 3 Pages
    Good Essays
  • Good Essays

    It210 Week 4 Psuedocode

    • 584 Words
    • 3 Pages

    As Int Declare GIV as Float Declare DRInput As String Declare aa As String Set Rate1 = 1.4680 Set Rate2 = 9.5085 Set Rate3 = 1.6433 Set Rate4 = 104.9200 Set Rate5 = 6.2561 Call Display_Menu Module Call Get_Int_Value Module Call Convert_Currency Module Call Display_Results Module End Currency_Convertor Main Module Quit_Program…

    • 584 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    CEIS100 W5 ILab Report

    • 320 Words
    • 2 Pages

    Code—copy and paste (or type) your code below. You can also post a screenshot of the program working if you would like.…

    • 320 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    it238 r6 appendix c

    • 243 Words
    • 2 Pages

    1. Write JavaScript® code that anticipates and handles an error for an expected numeric field. This code is executed on keypress, and the entered value is saved for you in a variable called enteredChar. Include the try block of JavaScript® statements needed to check if the character is not a number or a nonalphanumeric character, or if you throw an error message.…

    • 243 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Nt1310 Unit 8 Study Guide

    • 546 Words
    • 3 Pages

    13. Writing a program in a language such as C++ or Java is known as _____ the program.…

    • 546 Words
    • 3 Pages
    Powerful Essays
  • Satisfactory Essays

    Now go Alt+Ctrl+Del and click on the tab "Processes" Find Explorer.exe in that list and click end process.…

    • 338 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Pt1420 Assignment

    • 1058 Words
    • 5 Pages

    2) Design a Do-While loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user if he or she wishes to perform the operation again. If so, the loop should repeat, otherwise it should terminate…

    • 1058 Words
    • 5 Pages
    Satisfactory Essays
  • Powerful Essays

    Searching and Sorting Streams and Files Graphics GUI Components and Events Mouse, Keyboard, Sounds, and Images Big-O Analysis of Algorithms The Java Collections Framework Lists and Iterators Stacks and Queues Recursion Revisited Binary Trees Lookup Tables and Hashing Heaps and Priority Queues Design Patterns…

    • 3908 Words
    • 16 Pages
    Powerful Essays
  • Powerful Essays

    EAS230Syllabus

    • 1748 Words
    • 8 Pages

    C++ programming: editing, compiling, user I/O, variables (ints, doubles, char, strings, booleans), loops, decisions, functions, pointers, arrays, tables, databases, sorting.…

    • 1748 Words
    • 8 Pages
    Powerful Essays
  • Satisfactory Essays

    Javascript Error Handling

    • 255 Words
    • 2 Pages

    Read the directions carefully and write JavaScript code that addresses the requirements. Copy your code directly into the Appendix document and then post to your Individual forum.…

    • 255 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    This Is a Paper

    • 469 Words
    • 2 Pages

    * The design is not robust as there are no statements for error handling and handling exceptions. To make this code more robust I would add error handling statements like the user can only enter numbers that are between 0 and 100. Also the user cannot enter any strings like winding and other data types, for other numbers and data types the system will display "invalid input. Please enter a number between 0 and 100." Also notice that it doesn't handle the case of entering 49. You need <= 49, as it is now, when you enter 49 all it will say is "how did u do?" same thing with entering 100 and for anything over 100.…

    • 469 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    3) A description of at least two methods of sorting records and the benefits of each:…

    • 1173 Words
    • 6 Pages
    Good Essays