473,320 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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
2 2088
Ganon11
3,652 Expert 2GB
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
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

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

Similar topics

4
by: domtam | last post by:
Suppose I have one of those USB storage devices (like a mp3 player, USB thumbdrive, or even digital camera) connected to my computer. I'd like to write a C# program that can - detect that the...
40
by: Abby | last post by:
My .dat file will contain information like below. /////////// First 0x04 0x05 0x06 Second 0x07
0
by: Alfonso | last post by:
Hello , I have a problem writing and reading images (jpeg, bmp) from a my Web Service. I developed a client and a WebService, I host the webservice on IIS5.1 I send an image as a byte...
2
by: somequestion | last post by:
During copying file , wanna read file Size like this string CheckFileSize(string fileName) { if( fileName == null ) return; FileInfo fi = new FileInfo(fileName); return fi.Length.ToString();...
1
by: potluri040 | last post by:
hi, could any one let me know how to read file thru VB script. Scenerio is like this: i am keeping a personal details such as name, age, sex, company, location in a text file called user details...
1
by: samira | last post by:
hi all, i built aproject to my client he need that the visitors to the site can read file from his computer, how can i do this , we uuse asp.net over c#
2
by: peter.vanna | last post by:
I would like to write a program to read a text file (data.txt) on Windows and Linux machines. data.txt is formated as follows: 1 10 100 1000 2 20 (a new but empty line)
3
by: =?Utf-8?B?Sm9obiBXYWxrZXI=?= | last post by:
Hi, Is there anything wrong with the code below in sending my browser page to Excel? Before my page opens in Excel there's a message "Problems came up in the following areas during load:" and it...
2
by: xplode144 | last post by:
I have a Web application. i need to read a file once during the startup and preserve the read data throughout the life of the application. i will to access the data often during the page_load of...
2
by: danimian | last post by:
Hello, first i am creating xml file if file does not exist. String myFile = "C:\myxmlfile.xml"; if (!File.Exists(myFile)) { using (FileStream conStream = new FileStream(myFile,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.