Ask C/C++ Expert


Home >> C/C++

Your task for this assignment is to create, in C89, a stand-alone sorting program.

1 Documentation

You must thoroughly document your code using C comments (/*....*/).

For each function you define and each datatype you declare (e.g. using struct or typedef), place a comment immediately above it explaining its purpose, how it works, and how it relates to other functions and types. Collectively, these comments should explain your design. (They are worth substantial marks - see Section 7.)

2 Program Outline

Your program will deal with one input file: a .csv text file to sort (the "user file"). and a single output file containing the sorted text.
Your program must do the following:

a) Take two command-line parameters - the names of the input and output files. these can be in either order. so you will also need command line switches ( i and ,c,)

Examples:

sortingAssignment i infile o outfile

sortingAssignment o outfile i infile

Invalid command line arguments should cause the program to output a usage message, and exit.

b) Read the input file and store its contents in a (generic) linked list. The format of the input file is specified in section 2.1

c) Output a menu to the user requesting how the user would like the contents of the file sorted. The user must be able to sort on any of the columns. in ascending or descending order

d) Sort the rows of the input file using a generic insertion sort (in-place). Your insertion sort function MUST be generic - that is it must import a generic linked list and a compare function, export the sorted linked list, and return an integer specifying if anything went wrong 0 for success. or a negative value for any specific errors.
Note. Insertion sort is fully described in appendix a

e) Write the sorted data to the specified output file using the same format as the input file.

4 Testing (or "How to Actually Get Marks, part 2")

Your program must work on either:

 The lab machines in building 314, and/or One of the saeshell0Xp.curtin.edu.au machines (where "X" is 1. 2, 3 or 4).

To begin with, construct a small-scale test file containing only a few columns and lines. As you begin to fix bugs, try larger test files.
All user input must be "sanity" checked. Invalid user input should not cause the program to stop (other than invalid command line arguments).

Ensure there are no memory leaks - you must not rely on the program closing to free your memory. You will lose marks for any memory issues.

5 README.txt

Prepare a text file called README.txt (not using Word or any other word processor), that contains the following:
A list of all files you're submitting and their purpose.
A statement of how much of the assignment you completed; specifically:
- How much of the required functionality you attempted to get working, and
- How much actually does work, to the best of your knowledge.
A list of any bugs or defects you know about. if any.
A statement of which computer you tested your code on. This must be either
- One of the four saeshell0Xp machines, or
- One of the building-314 lab machines. In this case, specify the room number (e.g. 314.220) and the "Service Tag" - a unique 7-character ID found on a black sticker on the top of the each machine.

6 Submission

You must keep a copy of all required files in your $HOME/UCP/assignment directory, including files that you used for testing. These must not be touched after the due date and time for the assignment. You must also submit the following electronically, via the assignment area on Blackboard, inside a single .tar.gz file (not .rar or other formats):
- Your makefile and README.txt.
- All .c and .h files (everything needed for the make command to work).
- a completed "Declaration of Originality' (appendix b)

You are responsible for ensuring that your submission is correct and not corrupted (download and check it!). You may make multiple submissions. but only your newest submission will be marked. The late submission policy (see the Unit Outline) will be strictly enforced. A submission 1 second late, according to Blackboard, will be considered 1 day late. A submission 24 hours and 1 second late will be considered 2 days late. and so on.

2.1 The input file

The input file will be in .csv format, with the column names specified on the first line, and its data type (string or integer) specified after the name in brackets. There could be any number of columns, and any number of rows.

This is an example of a valid input file:
name (string) , age (integer) mark, 21, at home
jordan, 19, his place
etc
Sorted on age, ascending: address (string)

name (string), age (integer), address (string) jordan, 19, his place
mark, 21, at home
etc
and another
The (string), desc (string) , in (integer), long (integer) shark bay, nice and warm, 12593, 39216
esperance, cold and windy, 4287
etc
Sorted on loc, ascending:
lac (string), desc (string), lat (integer), long (integer) esperance, cold and windy, 9287
shark bay, nice and warm, 12593, 34216
etc

Note: You must state any valid assumptions you make about the input file.

If a value is missing from the file, the sorting algorithm must place it last in the sorted list.

If there is an unrecognised datatype name, or the file is otherwise not in the expected format, your program must issue an error message detailing the problem. When this happens, your program must not attempt to sort anything.

3 Makefile (or "How to Actually Get Marks, part 1")

You must create a makefile, and it must actually work. That is, the marker will type: (user@dirl$ make

This is the only way the marker will attempt to compile your code. If your makefile does not work, then. according to the marking guide, your code does not compile or run. (The marker will delete all existing .o files and executable files beforehand.)

Your Makefile must be written by you, and not automatically generated. It must be structured properly in accordance with the lecture notes.

Appendix a - insertion sort

Inspired from the idea of adding items to a list in sorted order. Every time a new item is added, insert it in sorted position.

Can also be applied to sorting an existing list.

Maintain a marker and insertion-sort the element at the marker into the items to the left of the marker.
ie: take the next item and insert it in sorted order into the sub-list that precedes the item.

Start the marker at the front of the list and move it up by one after each inserted item. Then items before marker will be sorted.

Searches for the insert position backwards so that we can take advantage of semi-sorted lists.

Pseudo-code for insertion sort using integers in an array.

METHOD InsertionSort IMPORT array EXPORT array

FOR nn < 1 TO array.length-1 DO                               < Start inserting at element 1 (0 is pointless)

ii <- nn                                                                                    <- Start from the last item and go backwards

temp e- array[ii]

WHILE (ii > 0) AND (array[ii-1] > temp) DO                 Insert into sub-array to left of nn

Use > to keep the sort stable

array[ii] < array[ii-1]                                              < Shuffle until correct location

ii<- - 1

ENDWHILE

array[ii] <- temp

ENDFOR

Note carefully - this algorithm is for integer arrays - you will need to convert it to sort LinkedLists of strings/integers. Remember that a LinkedList is of unknown length, so you should NOT use a for loop.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91991899
  • Price:- $80

Guranteed 48 Hours Delivery, In Price:- $80

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As