Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program should be easy to follow for beginners and should be commented. Should meet all the requirements listed below and should be WRITTEN IN C++.

Program should be easy to follow for beginners and should be commented. Should meet all the requirements listed below and should be WRITTEN IN C++.

We have talked about two sorting algorithms, Bubble Sort and Selection Sort. This one is slightly different and involves several concepts we have discussed. Here is the method:

  1. You can use a statically-allocated one-dimensional array of doubles for this with length 100. You will never have more than 100 things to sort, but you may have fewer. Your program will have to keep track of how many elements you actually use.
  2. Ask the user for the name of a file containing data. If it does not exist, the program should display an error, then ask for a new file name. Entering an asterisk (*) as the first and only character on a line should terminate the program.
  3. Insert each number as you read it. Do not read everything in, then sort, as this will require twice as much memory.
  4. The way linear insertion works is this:
  1. If the list is empty, the number goes in the first array element.
  2. If the list is not empty, search to find the two elements where the top one is smaller than the one you have and the bottom one is larger (assuming an ascending-order sort.) This is your insertion point. Then move everything below and including the insertion point down in the array. Put the new element in.
  3. Increment the count of elements in the array
  1. When you hit the end of the file, all of the numbers should be in the sorted array. Print the entire array.
  2. Go back to step 2 and ask for another file name.

For example, if the file contains 6, 3, 7, and 2 your array would look like this at each step:

Step 1: Array is empty, so insert the 6.

6

Step 2: Move the 6 down, insert the 3

3

6

Step 3: Put the 7 at the end; nothing moves

3

6

7

Step 4: Move the 3, 6, and 7 down, then insert the 2.

2

3

6

7

Yes, this is terribly inefficient because of moving elements around, but it illustrates several important concepts, including sorting, functions with parameters and return values, file I/O, and array handling.

There are two test data sets attached to this document that you should use to test your program with. You can assume that the files do not contain bad data. They contain only valid floating-point numbers. Make no other assumptions about the data.

Grading Criteria

Program behaves according to the specification, sorting correctly, requesting file names, and catching file not found errors.

60%

Program is structured well, with functions to do most of the work rather than everything in the main loop.

30%

Program documentation

10%

Grading Rubric:

Bad output (not sorted, missing values, etc.): -30

Using a different algorithm from the one described above: -30

Missing internal comments: -5

Program does not use functions: -20

Program does input or output in the same function that does the sorting: -20

Program sorts only one file and stops: -10

Asg3Data1.txt

6

3

7

2

Asg3Data2.txt

134.9
-21.4
78.0
161.9
4.0
0
3.11
-9.99
43.0
42.0
41.0
7.3
3.14159
2.71828
-42
777
-100.1
86
868
11
13
1000000
-999
451.21
-273.33

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases In Networked Information Systems 6th International Workshop Dnis 2010 Aizu Wakamatsu Japan March 2010 Proceedings Lncs 5999

Authors: Shinji Kikuchi ,Shelly Sachdeva ,Subhash Bhalla

2010th Edition

3642120377, 978-3642120374

Students also viewed these Databases questions

Question

Define turnover and turnover intent.

Answered: 1 week ago

Question

What do you mean by underwriting of shares ?

Answered: 1 week ago

Question

Define "Rights Issue".

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Explain the procedure for valuation of shares.

Answered: 1 week ago

Question

3. An overview of the key behaviors is presented.

Answered: 1 week ago

Question

2. The model is credible to the trainees.

Answered: 1 week ago