By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,650 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,650 IT Pros & Developers. It's quick & easy.

How can read from file.txt & where can save this file(file.txt) to start reading

P: 2
Hi
everybody I am a beginner with C++ programming. And I need some help.

How can I start with this program
***********

The program is using a text file of information as
the source of the questions. The program starts by outputting a simple text information
screen:
Question Master
This program tests your knowledge in your chosen category.
Use the load command to load up your set of questions. Type
help if you wish to see the available commands.
The program then enters a loop asking the user to:
Enter a command:
and processes the following set of commands:
FINISH
end the program
LOAD <filename>
e.g. load capitals.txt
The program then opens that files, reads in the information and stores it in arrays
of string, and displays the text from the first line of the file which will describe
the category of questions and numbers of entries read in, e.g.
Category of questions: countries and their capitals
Number of entries: 193
If the file cannot be loaded then output an error message; so, if I tried to load a
file called wibble.txt and it didn't exist then the program would respond with:
"*** ERROR: Unable to open file wibble.txt ***"
NOTE: remember to use the clear() function after you have read in a file to
EOF (end-of-file) see lab notes.
PLAY
The program displays the category of questions e.g.
Enter a command: play
Category of questions: countries and their capitals
then enters a loop asking questions based on the information loaded. The question
asked is made up from line 2 of the file (see below) and the entry from the name
array chosen at random. If the correct answer is given, then output "Well done"
followed by the number of correct answers so far - for example:
What is the capital of Denmark?
answer:copenhagen
Well done. Correct answers: 1
Continue (yes/no)? yes
If an incorrect answer is given then correct them as follows:
What is the capital of Federated States of Micronesia?
answer:wibble
Wrong: Federated States of Micronesia is linked with: Palikir
Continue (yes/no)? yes
After each attempt, ask them if they wish to continue (yes/no). If they
answer "no", then output the total of correct and incorrect answers, for
example:
What is the capital of Croatia?
answer:zagreb
Well done. Correct answers: 2
Continue (yes/no)? no
Correct answers: 2
Incorrect answers: 1
Enter a command:
LIST
List the names and attributes stored in the array to the console screen preceded by
the category, the question, and the number of entries.
HELP
Simple text output describing these command options.

Format of the question files
There are two example files:
capitals.txt
animals.txt
They both have the following format:
Line 1: the category e.g. countries and their capitals
Line 2: the question, e.g. what is the capital of
Lines: name, e.g. Australia
attribute, e.g. Canberra
each on its own line, repeated.
So the first block of the capitals file looks like this:
countries and their capitals
what is the capital of
Afghanistan
Kabul
Albania
Tirane
Algeria
Algiers
Andorra
Andorra la Vella
Angola
Luanda

************
Jan 11 '07 #1
Share this Question
Share on Google+
2 Replies


Ganon11
Expert 2.5K+
P: 3,652
What work have you done so far? What ideas do you have? What functions will you need?

To start writing a program, outline the bare minimum of what you need (like saying, I'll need a function to do this. I don't know how that'll work yet, but it'll do this.). Then start working on it one piece at a time. If you have specific questions that you can't solve on your own, come to us at TSDN and we'll do our best to help guide you to the answer.
Jan 12 '07 #2

P: 2
What work have you done so far? What ideas do you have? What functions will you need?

To start writing a program, outline the bare minimum of what you need (like saying, I'll need a function to do this. I don't know how that'll work yet, but it'll do this.). Then start working on it one piece at a time. If you have specific questions that you can't solve on your own, come to us at TSDN and we'll do our best to help guide you to the answer.
Thanks alot for your reply
Jan 12 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.