473,399 Members | 3,038 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,399 software developers and data experts.

sequential files for Hangman using C++

How to write and read from a sequential file into the game Hangman using fstream? Here are the instructions.

Functions enterNewWords() and readFromFile() [ correspond to the example code for writing to sequential files and reading from sequential files from the text book. ]. Instead of displaying the contents of the file, the function inserts the contents into the vector named wordlist. The readFromFile() also selects a random word from the vector wordlist which is stored in the variable secretWord.


Expand|Select|Wrap|Line Numbers
  1. #ifndef HANGMAN_H
  2. #define HANGMAN_H
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <ctime>
  9. #include <cctype>
  10. #include <fstream>
  11.  
  12. using namespace std;
  13.  
  14. class Hangman
  15. {
  16. private:
  17.     int attempts;
  18.     vector<string>wordList;
  19.     string secretWord;
  20.     int wordLength;
  21. public:
  22.     Hangman();
  23.     void playGame();
  24.     void enterNewWords();
  25.     bool isWin(string word);
  26.     void convertToUpper();
  27.     void readFromFile();
  28.     void setSecretWord(string word);
  29.     string getSecretWord();
  30.     void setWordLength(int length);
  31.     int getWordLength();
  32.     void displayMenu();
  33. };
  34. #endif
  35.  
  36.  
  37.  
  38.  
May 15 '13 #1
1 1613
weaknessforcats
9,208 Expert Mod 8TB
First, write a small program that can read and write a sequential file using fstream.

Get this program running. What you learn with this can be applied to your project.

You will need functions to open file, read the file, close the file, write the file, and write an end of file.

Read: http://bytes.com/topic/c/insights/92...ad-text-file-c

http://bytes.com/topic/c/insights/92...te-text-file-c
May 15 '13 #2

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

Similar topics

1
by: Alexander Hoffmann | last post by:
Hello, I have a project with a number of python modules, which means there are several *.py files all in the same folder /usr/local/myproject/*.py . I ran the program to test it and of course as...
0
by: Jens Nilson | last post by:
My company has a web application for downloading and uploading of reports in MS Office formats. The application has been working fine until we added certificate for secure transfer. Now, when the...
1
by: Xiangliang Meng | last post by:
Hi, all. Recently, I find there is a way in our project to maintain a global set in many files by using preprocessing directives. I'm wondering if we could find a better method for this. Many...
2
by: amit | last post by:
hi, I have a web application using forms based authentication. I want to restrcit even the non asp.net files from forms authentication i.e I do not want that my clients should be able to access...
1
by: Geoff | last post by:
I have a sequential text file, Clients.txt, and when my form loads I would like the first record only to be displayed - that's if it exists! Initially Clients.txt is blank. Well I 'm getting...
1
by: TonyJ | last post by:
Hello! I use this static method GetFiles from the Directory class and I hope to get only those files that have file extension ini but I get all files that begin with ini as the file extension...
1
by: kumarboston | last post by:
Hi all, I am trying to copy couple of directories and their files to another place. Each directory have 25-30 files and numbered accordingly, the problem I am facing is, I have to copy files...
6
by: haneeshkb | last post by:
I am using the function FindFirstFile to pick files from a folder to process. But the files selecting is based on name ,I need to get the files selected based on datetime( means frst come firstout )....
2
mageswar005
by: mageswar005 | last post by:
How can i open doc,xls,html,swf files directly using php (without asking open,save,close options)? Regards, M.Mageswaran
0
by: kumar215 | last post by:
Hi All, How can we attach a file in VBA application using access. I have a form1 with button placed on it. On click of button I need to call another form2 from where I need to attach 10 files....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.