sequential files for Hangman using C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Deltafox777
    New Member
    • May 2013
    • 1

    #1

    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.


    Code:
    #ifndef HANGMAN_H
    #define HANGMAN_H
    
    #include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <ctime>
    #include <cctype>
    #include <fstream>
    
    using namespace std;
    
    class Hangman
    {
    private:
    	int attempts;
    	vector<string>wordList;
    	string secretWord;
    	int wordLength;
    public:
    	Hangman();
    	void playGame();
    	void enterNewWords();
    	bool isWin(string word);
    	void convertToUpper();
    	void readFromFile();
    	void setSecretWord(string word);
    	string getSecretWord();
    	void setWordLength(int length);
    	int getWordLength();
    	void displayMenu();
    };
    #endif
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    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

    Comment

    Working...