Laboratory 03: Fallout 3 Hacking


Download the following files:


Frequently different programmers use the same name for a class. This potential problem is addressed by C++ namespaces. Unzip Lab03Files.zip into a subdirectory called CSC2110. Take a look at a few of the unzipped header files. Notice the namespace braces around the class definition. Each of these classes is in the CSC2110 namespace making it possible to distinguish these classes from those of another programmer that happens to have the same class name (and a different namespace name). Add the CSC2110 namespace to ReadFile and WriteFile. You may need to use (in a few places):

using CSC2110::String; //indicates that you will be using a particular class in a particular namespace
This is the safest way (although it can be more cumbersome than using namespace CSC2110;) to indicate the classes that you wish to use in your program.

Note that there is a file called Text.h. This is a header file for the CSC2110::String class. Unfortunately, this is necessary as using String.h as the header file creates an import conflict with the string.h that cannot be solved with namespaces (C++ is not case sensitive). This conflict appears when the String class is not located in the working directory.

Run the unzipped build.bat in the CSC2110 directory. This compiles all of the unzipped files as usual and places the (compressed) .o files into a library called libCSC2110.a. To create the library, the last line of build.bat is: ar -r libCSC2110.a *.o (ar stands for archive). Now all that another programmer needs to use the classes in the CSC2110 folder is the library file you just created and the header files. They do not need the .cpp or the .o files.

Take a look at build.bat for your working directory (the directory above CSC2110). Note how the compile steps specify the include directory (CSC2110) using the -I option. Further, note how the link step specifies the library directory (also CSC2110) using the -L option and the library to use is specified as -lCSC2110.

Using a ListArray

In Fallout 3, sometimes it is necessary to hack computers. When hacking is attempted (assuming your science skill is high enough to attempt the hack), you are given a list of possible passwords. Each time you try a password from the list, either it is the correct password and you are granted access to the computer, or you are told how many characters in the attempted word match characters in the actual password. The character and its position in the actual password must match to be counted as a character match. By a process of elimination, it is then possible to determine the actual password.

Allow the user to specify possible passwords (Strings) from an inpute file (fallout.txt). Next, they will enter which word that they tried as the password, and the number of character matches reported by Fallout 3 (this information is provided external to your program). This information will eliminate several words as possible passwords. The updated list of possible passwords is displayed, and the user is then able to guess another password from the original list. If only one password remains, the program terminates. If no passwords remain, the program also terminates, but this indicates there was a user input error at some point.

Your task is to write a Password class that stores the current list of possible passwords in a ListArray. You will need to store the list of original words, the list of possible passwords, and the length of the first word added to the original list to check for input errors.

Note that the program also tells you the best word in the original list to guess! The result when guessing this word (if it is not the password) will eliminate the most passwords from the possible passwords list. This has been done for you.

Include the following methods in Password:

Write Password.h and Password.cpp using the following specification:

  • Password() //constructor
  • ~Password() //destructor (there is work to do here, delete the individual words)
  • void addWord(String* word) //add a word to the list of possible passwords
  • void guess(int try_password, int num_matches) //index of guessed word in the list of all words (1-based), number of matches reported by fallout 3, update viable passwords list
  • int getNumberOfPasswordsLeft() //returns the number of possible passwords remaining
  • void displayViableWords() //display the current list of possible passwords
  • int bestGuess() //the best word in the original list to guess next (done for you)
  • String* getOriginalWord(int index) //get a word from the original list of all passwords, 1-based

Your public guess method should call at least one private helper method to count the number of character matches between two Strings. You should use theListArrayIterator rather than a for loop wherever appropriate.



Eventually compiling everything every time a change is made will become too time consuming. You will use the make utility that is smart enough to recompile only those files that have been updated since the last compile. Now your build batch file (named build_make.bat in this lab) only sets the path and tells the make utility what the drive letter is. Most of the work is done in Makefile.

Open Makefile. The FILES = line requests you to list the .o files that make needs to generate for linking. You need to compile Password.cpp and PasswordDriver.cpp, so complete this line with Password.o and PasswordDriver.o. In general, each .cpp file you have will need to be compiled into a .o file. Sometimes you will have only a .h file. Do not list these files.

Fill in the EXECUTABLE = line with the name of your executable, including the .exe. PROJECT_PATH is the path to your working directory including the drive letter. This variable is obtained from the build_make batch file, so you don’t need to change it. Fill in the INC_DIRS = with the path to your CSC2110 folder -I$(PROJECT_PATH)/CSC2110/. This is where make will look for header files (i.e. files that you will #include) not in your working directory. Fill in theLIB_DIRS = with the path to your CSC2110 folder 
-L$(PROJECT_PATH)/CSC2110/. This is where make will look for archived .o files (libraries). Fill in the LIBS = with the name of your libraries (-lCSC2110 for libCSC2110.a). The COMPILE, LINK, and Project lines use previously defined text variables, so they will not need to change.

Now you need to tell make how to create the .o files that you listed at the top. At the bottom of your file, type:

Password.o:		Password.h Password.cpp
			$(COMPILE) Password.cpp

These lines tell make that if either Password.h or Password.cpp have been changed since the last make, the Password.cpp should be recompiled, creating Password.o. Note: tabs rather than spaces must be used to align the text! Repeat this for PasswordDriver.o.

Use build_make.bat to compile your program (you still need to specify the drive letter as before). Make a small change (i.e. add a comment) to PasswordDriver.cpp. Recompile with build_make.bat. Notice that only PasswordDriver is recompiled.


The below class interfaces are defined in the namespace CSC2110.


  • String methods
    • String(const char* text) //constructor
    • void displayString()
    • int length()
    • const char* getText()
    • int a_to_i()
    • float a_to_f()
    • String* i_to_a(int number) //static method
    • String* f_to_a(float number) //static method
    • int find(char delimiter, int start) //find the index of a particular character
    • String* substr(int start, int end)
    • int compare(String* other)
    • char charAt(int index) //0-based
  • Tokens methods
    • Tokens(String* str, char delimiter) //destructor does not delete the individual tokens
    • String* getToken(int index)
    • int getNumTokens()
    • void displayTokens()
  • ReadFile methods
    • ReadFile(const char* file_name)
    • String* readLine()
    • bool eof()
    • void close()
  • WriteFile methods
    • WriteLine(String* file_name)
    • void writeLine(String* line)
    • void close()
  • Random methods (use getRandom first)
    • static Random* getRandom()
    • int getRandomInt(int lower, int upper)
    • float getRandomFloat(float lower, float upper)
  • Keyboard methods (use getKeyboard first)
    • static Keyboard* getKeyboard() //call this first
    • int readInt(string prompt)
    • int getValidatedInt(string prompt, int min, int max)
    • double readDouble(string prompt)
    • double getValidatedDouble(string prompt, double min, double max)
    • String* readString(string prompt)
  • Integer/Double methods
    • Integer(int val)/Double(double val)
    • int getValue()/double getValue()
  • CD methods
    • CD(String* artist, String* title, int year, int rating, int num_tracks)
    • void displayCD() //display the current state of the CD
    • String* getKey()
    • void addSong(String* title, String* length)
    • static int compare_items(CD* one, CD* two) //define how to compare CDs (in this case, by title)
    • static int compare_keys(String* sk, CD* cd)
    • static ListArray* readCDs(const char* file_name) //read in all of the CDs from a text file
  • Song methods
    • Song(String* title, String* length)
    • void displaySong()

In case you have a similar question and need it answered for you just say write my essay. At Academized we have all the most qualified academic writers and tutors, for all your assignments, essays, cases studies, discussion posts, project proposals, research papers, discussion posts, nursing assignments, admission essays, blog articles, and other forms of academic work.

If you don’t want a custom paper, just buy a pre-written essay from Buy College Essay.