Comment on Tutorial - Sorting an integer array in C By Ignatius
Comment Added by : Lauren
Comment Added at : 2013-04-18 14:45:25
Comment on Tutorial : Sorting an integer array in C By Ignatius
Can someone help me please?
Imagine that some students each sit 4 examinations, receiving a mark for each exam expressed as a
positive whole number (nothing to the right of the decimal point) as a percentage (i.e somewhere in the
range 0 to 100%).
Your customer would like to study such examination results by using a program that determines,
for each exam, how many students scored a mark between 0-9, how many between 10-19, how
many between 20-29 and so on.
Also the customer would like to be able to write to a computer file a list of all students and marks
awarded for any one particular exam, this list being arranged in mark order (i.e. the person with
the highest mark being listed first, the person with the next highest listed second and so on.)
1) To read in all candidates' results from a file called “datafile.txt” which your program should
expect to find in your drive U: in the root (outer most) folder (that is location U:\datafile.txt). This
file will consist of each candidate's results listed on a separate line, in a file using comma separated
format. An individual candidate's results will be made up as follows: first that candidate’s 6-digit
registration number (in other words identification number) then a set of four integer numbers
representing the mark which that candidate achieved in each of the four exams. Each line in the file
will therefore consist of a candidate's Registration Number (expressed as a 6 digit ASCII decimal
number) followed by a comma character "," then that candidate's mark in exam 1 (expressed as a
whole number as a decimal in the range 0 to 100), and then another comma character "," followed
by their mark in exam 2, another comma, followed by their mark in exam 3, another comma,
followed by their mark in exam 4 and finally an end of line character ('\n'). And so on for each
An example of the contents of 'datafile.txt' might be:
So candidate “105286” scored 23 in exam one, 45 in exam two, 15 in exam three and 86 in exam
four. (Some example data files have been created for you and saved on the internet. To download the
example files go onto the internet to the following page and download them from there:
And look for section Examples for Assessed Exercise 2 in 2013 near the bottom.
You could copy these files into your own U: drive’s root folder \ so that you can use them to test
your program). You can read and edit (or indeed create your own) such files using the Dev-C editor
or even Windows' Notebook application, as these data files are simply ASCII text readable files.
2) The program should be designed to accept result files with any number of candidates within the range
1 to 40 students (inclusive). Having read in the results file, it should determine and display, for each
particular exam, how many candidates scored a mark in the range 0-9, 10-19, 20-29, 30-39, 40-49,
50-59, 60-69, 70-79, 80-89, 90-100. So, for the example datafile.txt shown above, your
program would display:
An example of what the computer screen might display might show:
Exam1 Exam2 Exam3 Exam4
0-9 0 0 2 0
10-19 0 1 1 0
20-29 3 0 0 0
30-39 0 0 1 0
40-49 0 1 0 0
50-59 0 0 0 1
60-69 0 1 0 1
70-79 0 1 0 0
80-89 0 0 0 1
90-100 1 0 0 1
C:\Users\Peter\Desktop\C-stuff\assess-2-2013.doc 3 ( Peter Judd/University of Sheffield 1999-2013) 06/03/2013
Don't forget to allow the user to be able to view all the data presented on the screen (assume the user
can only see 25 lines at a time) before continuing.
3) Next the program should create a new output file and write the results for just one of the four exams
into this file (after first asking the user to choose which set of exam results to place in the file). These
results should be sorted in descending order of mark magnitude (i.e. highest first).
The program will first need to ask the user to choose which of the four exams is to have its results
written to this new file.
The new file must be named "dataout.txt" and should reside in the same place as the input
file "datafile.txt" used earlier (i.e. in the U: drive root folder U:\datafile.txt)
Each candidate's result must appear on its own line, beginning with the candidate's Registration
Number (expressed as a 6 digit ASCII decimal integer number) just as it appeared in the input
file, then a comma (to act as a separator) and then the candidate's mark in the chosen exam.
There should be no padding spaces (or other) characters in this file.
Let's consider this program processing an example input file such as the "datafile.txt"
mentioned earlier and lets assume the user selected exam number 3 to have its results copied to the
output file, that file should now contain:
An example of what 'dataout.txt' might contain if user selected exam number 3:
- Data Science
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews
Subscribe to Tutorials
7. @pooja: this method should work, although i'm sure
View Tutorial By: Anush at 2012-07-16 08:30:58