SkyBlade16359
Badges: 8
Rep:
?
#1
Report Thread starter 5 years ago
#1
So this is what we are required to do as our coursework for GCSE computing:

"Arithmetic quiz
Task 1
A primary school teacher wants a computer program to test the basic arithmetic skills of her students.
The program should generate a quiz consisting of a series of random questions, using in each case
any two numbers and addition, subtraction and multiplication. The system should ask the student’s
name, then ask 10 questions, output if the answer to each question is correct or not and produce a final
score out of 10.
Analyse the requirements in detail and design, code, test and evaluate a program to meet these
requirements.
Task 2
The teacher wants to keep track of the scores each member of the class obtains in the quiz. There are
three classes in the school and the data should be kept separately for each class.
Analyse the requirements in detail for this program and design, code, test and evaluate a program that
will record and store the data for three separate classes of students using the arithmetic quiz.
Task 3
The teacher wants to use the results from students taking these quizzes to log their performance. The
system should store the last three scores for each student. The teacher would like to be able to output
the results of the quiz for a particular class, sorted:
• in alphabetical order with each student’s highest score for the tests
• by the highest score, highest to lowest
• by the average score, highest to lowest.
Analyse the requirements in detail for this program and design, code, test and evaluate a program that
will allow the teacher to select which class group to look at and which field to use when sorting the
output data."

I have done task 1 and 2 but have no idea on what to do on task 3 I tried using python to export to a .csv file but it only appears in the same cell, the '\n' command will put the data on separate lines but even then I have no idea how I could sort the data. Anyone have any ideas?
0
reply
Simes
Badges: 16
Rep:
?
#2
Report 5 years ago
#2
Would list.sort() help?
0
reply
SkyBlade16359
Badges: 8
Rep:
?
#3
Report Thread starter 5 years ago
#3
I don't have any lists in my code- should I?
0
reply
jayjunior01
Badges: 0
Rep:
?
#4
Report 5 years ago
#4
Hi SkyBalde, have just completed task 1. Not too sure about task 2 yet. Any chance of any help. jayjunior
0
reply
Async
Badges: 19
Rep:
?
#5
Report 5 years ago
#5
Task 2 is really easy. Thing is I don't know python. I could easily do this in VB.NET. You might also need a database for this. Or just use JSON to save the data.
0
reply
elohssa
Badges: 3
Rep:
?
#6
Report 5 years ago
#6
Just use a database (or at least file storage) to store the results. You can store only the last 3, or just store them all but with a timestamp (and then fetch only the 3 most recent). Sorting is dead easy in any programming language; but it depends which one you use e.g.

1. In c++ I'd use a struct/class (call it c_score) with the attributes being name/score/class. I'd then have a sort function that takes a function pointer and a vector<c_score>. There'd be three function pointer, each describing how to sort a vector<c_score> by a particular attribute e.g. name, score, class.
2. In most other languages there is a sorted-set data structure, that can be used to efficiently store the results in whatever order you like.
3. If you use a database then you can just use "select * from table order by score/class/name". Not efficient but will work.
4. In .NET2.0+ (C#/VB) you can do option 3 but in memory (LINQ); so faster.
0
reply
Async
Badges: 19
Rep:
?
#7
Report 5 years ago
#7
(Original post by elohssa)
Just use a database (or at least file storage) to store the results. You can store only the last 3, or just store them all but with a timestamp (and then fetch only the 3 most recent). Sorting is dead easy in any programming language; but it depends which one you use e.g.

1. In c++ I'd use a struct/class (call it c_score) with the attributes being name/score/class. I'd then have a sort function that takes a function pointer and a vector<c_score>. There'd be three function pointer, each describing how to sort a vector<c_score> by a particular attribute e.g. name, score, class.
2. In most other languages there is a sorted-set data structure, that can be used to efficiently store the results in whatever order you like.
3. If you use a database then you can just use "select * from table order by score/class/name". Not efficient but will work.
4. In .NET2.0+ (C#/VB) you can do option 3 but in memory (LINQ); so faster.
3. If you use a database then you can just use "select * from table order by score/class/name". Not efficient but will work.
You mean to tell me SQL is not efficient? I beg to differ. SQL is efficient, that's why so many people use it as a primary method for data storage. And Linq is fast, but not that fast when compared to using something like the quick sort algorithm.
Quick sort is superior for sorting. I'm sure the SQL [order by] clause uses quick sort or something similar to order the items.
0
reply
elohssa
Badges: 3
Rep:
?
#8
Report 5 years ago
#8
(Original post by Async)
You mean to tell me SQL is not efficient? I beg to differ. SQL is efficient, that's why so many people use it as a primary method for data storage. And Linq is fast, but not that fast when compared to using something like the quick sort algorithm.
Quick sort is superior for sorting. I'm sure the SQL [order by] clause uses quick sort or something similar to order the items.
I was referring to reading from the hard-drive, not what algorithm the SQL interpreter (SQL is just a language; it's neither fast nor slow) uses internally. LINQ is in-memory and probably uses some kind of generic quick-sort internally.
0
reply
Async
Badges: 19
Rep:
?
#9
Report 5 years ago
#9
(Original post by elohssa)
I was referring to reading from the hard-drive, not what algorithm the SQL interpreter (SQL is just a language; it's neither fast nor slow) uses internally. LINQ is in-memory and probably uses some kind of generic quick-sort internally.
You didn't use the word hard drive once in that post so...
0
reply
Planto
Badges: 16
Rep:
?
#10
Report 5 years ago
#10
(Original post by Async)
You mean to tell me SQL is not efficient? I beg to differ. SQL is efficient, that's why so many people use it as a primary method for data storage. And Linq is fast, but not that fast when compared to using something like the quick sort algorithm.
Quick sort is superior for sorting. I'm sure the SQL [order by] clause uses quick sort or something similar to order the items.
Linq to objects uses quick sort under the hood anyway, so it is exactly as fast as something like the quick sort algorithm. Other forms of Linq will just execute whatever form of sort the underlying provider provides - and that could be SQL.

Also, relational databases are incredibly prone to inefficiency. Many tasks are better off performed in-memory. SQL is typically preferred when data integrity is a priority, rather than for its performance
1
reply
Async
Badges: 19
Rep:
?
#11
Report 5 years ago
#11
(Original post by Planto)
Linq to objects uses quick sort under the hood anyway, so it is exactly as fast as something like the quick sort algorithm. Other forms of Linq will just execute whatever form of sort the underlying provider provides - and that could be SQL.

Also, relational databases are incredibly prone to inefficiency. Many tasks are better off performed in-memory. SQL is typically preferred when data integrity is a priority, rather than for its performance
I once did an Order By Linq statement to order a group of objects. And timed it both, the average I got using Linq was 13 milliseconds. I then tried the same exact thing, but with a Quick Sort algorithm made for sorting objects. And I got 1 milliseconds. The same exact object too. Nothing different. Why do you think Linq was slower in that scenario.
0
reply
Planto
Badges: 16
Rep:
?
#12
Report 5 years ago
#12
(Original post by Async)
I once did an Order By Linq statement to order a group of objects. And timed it both, the average I got using Linq was 13 milliseconds. I then tried the same exact thing, but with a Quick Sort algorithm made for sorting objects. And I got 1 milliseconds. The same exact object too. Nothing different. Why do you think Linq was slower in that scenario.
That would be dependent on your implementation (which I would be interested in seeing in a different thread).

There are two things to note though:

- That difference is negligible and the absolute difference is fairly meaningless. Try gradually scaling the size of the input and you will likely see that both scale at similar rates, i.e. they both have the same computational complexity (because they are using the same algorithm).
- Enumerable has other overheads that your code doesn't that are not directly related to the sorting algorithm. For example, Enumerable.OrderBy is sorting an arbitrary (generic) IEnumerable. An enumerable can't be sorted like an array can because it is effectively just a definition of a series - i.e., Enumerable can't assume that your IEnumerable is an array, or a list or any other concrete type, so it has to defer to the enumerable itself in order to traverse the series. For the framework to do this for an arbitrary enumerable, it is not just sorting the elements - it has to first enumerate it to an array of keys, sort the keys and then lazily yield the original collection again, according to the sorted array of keys. This sort of thing adds overhead that will appear more significant when measuring sorting of small enumerables but - as they grow - will become increasingly insignificant.

Another important distinction is that Enumerable performs a stable sort, i.e. Elements that are ordinally equal retain their original order.
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

University open days

  • University of East Anglia
    PGCE Open day Postgraduate
    Tue, 3 Mar '20
  • University of Bradford
    Postgraduate Open day/Evening Postgraduate
    Tue, 3 Mar '20
  • Queen's University Belfast
    Postgraduate LIVE Masters & PhD Study Fair Postgraduate
    Wed, 4 Mar '20

Do you get study leave?

Yes- I like it (500)
59.81%
Yes- I don't like it (43)
5.14%
No- I want it (237)
28.35%
No- I don't want it (56)
6.7%

Watched Threads

View All