Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 2, 2013, 02:36 PM   #1
Azrak
macrumors newbie
 
Join Date: Apr 2013
Create a simple quiz program

I have a history exam and for preparation i wanted to create a quiz (not a multiple answer one). I searched on many websites for an easy way to create a quiz but none of them corresponded to what i really want.

What I want is a quiz with questions in a random order (I prefer the order to vary each time i take the quiz) and I have to answer the questions by typing my result, not by clicking on it (i don't want the quiz to be a multiple answer quiz). Right after typing my result i want the quiz to display the correct answer (whether my result is correct or false).

Can anyone of you help me create a program that could do just that? I have done some programming before so I do know how it works but I'm not good enough to create my own program by myself. If not, does anyone know of a site that lets you create your own quiz but this type of quiz explained above (I want the quiz to work this way)?

All your help will appreciated
Azrak

Last edited by Azrak; Apr 3, 2013 at 03:08 AM.
Azrak is offline   0 Reply With Quote
Old Apr 2, 2013, 04:39 PM   #2
Hans Kamp
macrumors member
 
Join Date: Mar 2013
Location: Enschede, Netherlands
I think it helps if you write down for yourself, what this program is supposed to do.

To start with, your quiz is a collection of questions, objects. And each question has multiple answers to pick, and the correct andwer.

How are these answers stored? How do you want the quiz to appear on screen?

These are things to tuink about.
Hans Kamp is offline   0 Reply With Quote
Old Apr 2, 2013, 04:50 PM   #3
ArtOfWarfare
macrumors 601
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
If its console based, I think the quickest and easiest way to do this would be:

Make a text file with your Questions and Answers. Have it follow a simple pattern like:

"Question? Answer.
Another question? Another answer."

with one question? Answer pair per line.

Read the lines into a container (IE, a vector in C++), then shuffle the container. A simple shuffle algorithm I've used is:

Seed a random number generator.
For the amount of items (n) in the container, generate a random number between 0 and n-i-2, where i is how many iterations already completed. Then swap the item at index n-i-1 with the item at the index randomly generated.

Now loop with:
Get the substring up to and including the question mark and print it.
Wait for the user input.
Get the substring past the question mark and print it.
ArtOfWarfare is offline   0 Reply With Quote
Old Apr 3, 2013, 03:22 AM   #4
Azrak
Thread Starter
macrumors newbie
 
Join Date: Apr 2013
What do you mean by
Quote:
Originally Posted by Hans Kamp View Post
How are these answers stored? How do you want the quiz to appear on screen?
I will create all my questions and associate an answer to each question.
I want the program to ask me those questions in a random order and prompt me to type the answer. After i type my answer i want the program to show me the correct answer whether or not my answer is correct.
Azrak is offline   0 Reply With Quote
Old Apr 3, 2013, 04:04 AM   #5
Azrak
Thread Starter
macrumors newbie
 
Join Date: Apr 2013
I know i can find a site where i can create my own quiz but none of those sites work the way i want them to. What I want, that is different from all websites that offer me to create a quiz, is the quiz to display the correct answer after answering each question. This is the important part for me and that is why im trying to create my own program.
Azrak is offline   0 Reply With Quote
Old Apr 3, 2013, 05:49 AM   #6
AtariMac
macrumors regular
 
Join Date: Mar 2004
Location: Southeastern, PA
Send a message via AIM to AtariMac
Use Scratch. It's easy to learn and free. http://scratch.mit.edu

Have at it!
__________________
The world is my oyster
AtariMac is offline   0 Reply With Quote
Old Apr 3, 2013, 12:26 PM   #7
ytk
macrumors regular
 
Join Date: Jul 2010
What language are you trying to do this in?

Here's a program that will do it in Ruby:
Code:
#!/usr/bin/ruby -w

quiz_data = File.read( ARGV[0] ).split "\n"
questions = []
questions << [quiz_data.shift, quiz_data.shift] while quiz_data.size > 0
questions.shuffle!
questions.each do |q|
  print q[0] + " "
  STDIN.gets
  puts q[1]
  puts
end
Save your questions in a text file, one question per line followed by the answer on a separate line. Then invoke the program with ./quiz.rb <filename>
ytk is offline   0 Reply With Quote
Old Apr 3, 2013, 12:46 PM   #8
ArtOfWarfare
macrumors 601
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by ytk View Post
What language are you trying to do this in?

Here's a program that will do it in Ruby:
Code:
#!/usr/bin/ruby -w

quiz_data = File.read( ARGV[0] ).split "\n"
questions = []
questions << [quiz_data.shift, quiz_data.shift] while quiz_data.size > 0
questions.shuffle!
questions.each do |q|
  print q[0] + " "
  STDIN.gets
  puts q[1]
  puts
end
Save your questions in a text file, one question per line followed by the answer on a separate line. Then invoke the program with ./quiz.rb <filename>
Ruby is the language for which my knowledge is weakest (of all languages I know at all) - what is the << operator doing and how do you end up shuffling while keeping the questions and answers matching up?
ArtOfWarfare is offline   0 Reply With Quote
Old Apr 3, 2013, 02:21 PM   #9
Azrak
Thread Starter
macrumors newbie
 
Join Date: Apr 2013
I am on a mac. Is it possible for me to use Ruby? How can i do that?
And Ytk what do you mean exactly by "Then invoke the program with ./quiz.rb <filename> "?

Thanks a lot
Azrak is offline   0 Reply With Quote
Old Apr 3, 2013, 04:08 PM   #10
ArtOfWarfare
macrumors 601
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by Azrak View Post
I am on a mac. Is it possible for me to use Ruby? How can i do that?
And Ytk what do you mean exactly by "Then invoke the program with ./quiz.rb <filename> "?

Thanks a lot
... I'm coming to the conclusion you have virtually no programming experience given you don't know C++, Ruby, or how to use Terminal.

I suggest reading this free ebook and doing the exercises if you're interested in learning how to program with Ruby. I haven't read it, but I've read other books in the series by the same author:

http://ruby.learncodethehardway.org/book/
ArtOfWarfare is offline   0 Reply With Quote
Old Apr 3, 2013, 04:28 PM   #11
ytk
macrumors regular
 
Join Date: Jul 2010
Quote:
Originally Posted by ArtOfWarfare View Post
Ruby is the language for which my knowledge is weakest (of all languages I know at all) - what is the << operator doing and how do you end up shuffling while keeping the questions and answers matching up?
In this context, << appends to an array. Note that I am appending an array to the main array, with each subarray containing a question/answer pair. So the call to shuffle! (the ! is a Ruby convention that signifies an in-place operation) only shuffles a bunch of arrays, but doesn't break out each individual array. So the question and answer pairs stay synchronized.
ytk is offline   0 Reply With Quote
Old Apr 3, 2013, 06:39 PM   #12
chown33
macrumors 603
 
Join Date: Aug 2009
When is the history exam? That date will determine the deadline date for making the quiz program. Having a program too close to, or even after, the exam date is worthless. One needs sufficient time to actually use the program to learn the material.

If the deadline is anything less than maybe a month away, you should probably forget about writing a program. It seems like writing a program would be a significant diversion from the actual goal, which is studying history. In particular, all the time spent getting the program to work does nothing to help you memorize any history material.

Instead of a quiz program, maybe make "flashcards" with the question on one side and the answer on the reverse. This is fairly easy to do in a word-processor, where you layout the questions on one page, and put the answers opposite the question on the next page. Print it on card stock (visit an office-supply store) using a double-sided (duplexing) printer, and the answers will end up on the reverse sides of the questions. I recommend printing a trial run on plain paper first, to confirm that print settings, layout, etc. are correct. Then cut apart with scissors or a paper cutter, shuffle, and use.

The page layout of questions and answers can be reused fairly easily with any number of new questions and answers. There may even be specialized apps that let you make your own flashcards, either printed or entirely computerized. If you insist on having a program to do this, I'd start by looking for apps with those keywords: flash card or flashcard.

http://en.wikipedia.org/wiki/Flashcard
chown33 is offline   1 Reply With Quote
Old Apr 3, 2013, 07:11 PM   #13
ChrisA
macrumors G4
 
Join Date: Jan 2006
Location: Redondo Beach, California
Quote:
Originally Posted by Azrak View Post
What do you mean by

I will create all my questions and associate an answer to each question.
I want the program to ask me those questions in a random order and prompt me to type the answer. After i type my answer i want the program to show me the correct answer whether or not my answer is correct.
Just a minute. If it ignores what you type this is TRIVIAL Here is the logic.

1) Set N to (random number) * 2 - 1

2) Display text number "N"

3) accept any input and discard it with no processing

4) display text number N+1

5) go to #1

Set up the data file so that odd numbered records are questions and even numbers are answers.

----------

Quote:
Originally Posted by Azrak View Post
I am on a mac. Is it possible for me to use Ruby? How can i do that?
And Ytk what do you mean exactly by "Then invoke the program with ./quiz.rb <filename> "?

Thanks a lot
Hate to say but if you have to ask about what is "./quiz.rb" then you are NOT going to be able to write a program of any kind. That question is as basic as it gets. You will have some months of study before you can do this yourself.

Why not buy a pack of 200 index cards at the dollar store and be done with this?
ChrisA is offline   0 Reply With Quote
Old Apr 4, 2013, 01:05 AM   #14
ytk
macrumors regular
 
Join Date: Jul 2010
Aaaand here's the same code as a one-liner, just for fun:

Code:
#!/usr/bin/ruby -w

File.read( ARGV[0] ).split("\n").each_slice(2).to_a.shuffle.each{ |x| puts x[1] if STDIN.gets unless print x[0] + " "  }
ytk is offline   0 Reply With Quote
Old Apr 4, 2013, 07:52 AM   #15
AtariMac
macrumors regular
 
Join Date: Mar 2004
Location: Southeastern, PA
Send a message via AIM to AtariMac
You really ought to do it in Scratch. It is very powerful for those with no programming experience.

My 12 year old son won a regional programming contest making a game in Scratch.

If he can do it, so can you.
__________________
The world is my oyster
AtariMac is offline   0 Reply With Quote
Old Apr 4, 2013, 10:18 AM   #16
ArtOfWarfare
macrumors 601
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by AtariMac View Post
You really ought to do it in Scratch. It is very powerful for those with no programming experience.

My 12 year old son won a regional programming contest making a game in Scratch.

If he can do it, so can you.
I dislike things like Scratch. They have their limitations, and once you hit them, you're back to square 1: needing to know an actual programming language.

That or you end up doing convoluted things just to work around the limitations. You're better off learning some actual programming languages.

At 12, I was learning C. I taught myself C before I learned Algebra (and it helped immensely with understanding variables and functions.)
ArtOfWarfare is offline   2 Reply With Quote
Old Apr 4, 2013, 11:53 AM   #17
AtariMac
macrumors regular
 
Join Date: Mar 2004
Location: Southeastern, PA
Send a message via AIM to AtariMac
Quote:
Originally Posted by ArtOfWarfare View Post
I dislike things like Scratch. They have their limitations, and once you hit them, you're back to square 1: needing to know an actual programming language.

That or you end up doing convoluted things just to work around the limitations. You're better off learning some actual programming languages.

At 12, I was learning C. I taught myself C before I learned Algebra (and it helped immensely with understanding variables and functions.)
I do not disagree with your thinking, but I'm not sure the OP is really interested in programming as a career choice. I think he/she just wants to make a quiz.

Scratch is very well suited for making a quiz.

And as for variables, Scratch has great support.
__________________
The world is my oyster
AtariMac is offline   0 Reply With Quote
Old Apr 4, 2013, 03:34 PM   #18
Azrak
Thread Starter
macrumors newbie
 
Join Date: Apr 2013
I'm sorry guys I didn't think it would be that complicated to create a program with a bit of your help.

Quote:
I'm not sure the OP is really interested in programming as a career choice.
I actually am interested in programming, i'm thinking of applying for software engineering for college. I also do have a bit of experience in programming, but not enough to create my own program, I guess. I've learned a bit of xcode, visual basic and java u but only the basics. My priority now is actually my quiz, so i did try out Scratch. It worked pretty well, i finally create my quiz and it's up and working. The only thing that is missing for my quiz is that I can't make the questions asked in a random order, it is always asked in the same order from a to z. It's not a big deal though, I'm fine with my quiz.

Thanks a lot.
Azrak is offline   0 Reply With Quote
Old Apr 4, 2013, 09:07 PM   #19
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by Azrak View Post
... I also do have a bit of experience in programming, but not enough to create my own program, I guess. ... so i did try out Scratch. It worked pretty well, i finally create my quiz and it's up and working.
I don't understand this: "not enough to create my own program, I guess." You apparently wrote a program, and it's working, so based on that, you do have enough experience to create your own program. It may not do everything you wanted (yet), but the fact that you were able to learn a new language (Scratch) and write a program with it says a lot.


Quote:
The only thing that is missing for my quiz is that I can't make the questions asked in a random order, it is always asked in the same order from a to z. It's not a big deal though, I'm fine with my quiz.
Read this:
http://www.mikeash.com/getting_answers.html

Points 1-3 are especially relevant.
chown33 is offline   0 Reply With Quote
Old Apr 5, 2013, 07:50 AM   #20
AtariMac
macrumors regular
 
Join Date: Mar 2004
Location: Southeastern, PA
Send a message via AIM to AtariMac
Quote:
Originally Posted by Azrak View Post
My priority now is actually my quiz, so i did try out Scratch. It worked pretty well, i finally create my quiz and it's up and working. The only thing that is missing for my quiz is that I can't make the questions asked in a random order, it is always asked in the same order from a to z. It's not a big deal though, I'm fine with my quiz.

Thanks a lot.
You can randomize using a script like the attached image.
Attached Images
 
__________________
The world is my oyster
AtariMac is offline   0 Reply With Quote
Old Apr 5, 2013, 07:59 AM   #21
Hans Kamp
macrumors member
 
Join Date: Mar 2013
Location: Enschede, Netherlands
It is an interesting program. The screenshot shows, that you can program it, although there is no programming language, nor with a syntax and grammar and so on.

Quartz Composer is something similar.

Azrak,

I think you have to dive into the possibilities of Scratch.
Hans Kamp is offline   1 Reply With Quote
Old Apr 5, 2013, 09:10 AM   #22
Azrak
Thread Starter
macrumors newbie
 
Join Date: Apr 2013
Quote:
Originally Posted by AtariMac View Post
You can randomize using a script like the attached image.
Wow! That's exactly what i needed! Thanks a lot!
Azrak is offline   1 Reply With Quote
Old Apr 5, 2013, 09:59 AM   #23
AtariMac
macrumors regular
 
Join Date: Mar 2004
Location: Southeastern, PA
Send a message via AIM to AtariMac
Quote:
Originally Posted by Azrak View Post
Wow! That's exactly what i needed! Thanks a lot!
Glad to help. If you need any more advice let me know.
__________________
The world is my oyster
AtariMac is offline   0 Reply With Quote
Old Apr 6, 2013, 09:53 AM   #24
Azrak
Thread Starter
macrumors newbie
 
Join Date: Apr 2013
Actually there is more to my scratch quiz than i thought.
I have 18 questions and every time i start the program it asks me questions in a random order. How do I make it so it asks me the questions without repeating one? I mean if it already asked me question 4 i don't want it to ask me that question again.

I set my variable "random" to pick a random number from 1 to 18 (I have 18 questions. How do it so next time "random" picks a random number from 1 to 18, it doesn't pick the last(s) number(s) previously picked?
Azrak is offline   0 Reply With Quote
Old Apr 6, 2013, 10:13 AM   #25
ArtOfWarfare
macrumors 601
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by Azrak View Post
Actually there is more to my scratch quiz than i thought.
I have 18 questions and every time i start the program it asks me questions in a random order. How do I make it so it asks me the questions without repeating one? I mean if it already asked me question 4 i don't want it to ask me that question again.

I set my variable "random" to pick a random number from 1 to 18 (I have 18 questions. How do it so next time "random" picks a random number from 1 to 18, it doesn't pick the last(s) number(s) previously picked?
Keep an array of previously picked numbers and make sure the new number isn't on the list. Or do what I suggested and actually shuffle the cards. These may not be possible or unnecessarily difficult on account of the fact you've chosen Scratch.
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed.
Including the ones paired with other Macs on your network.
ArtOfWarfare is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 07:44 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC