Hi,
Basically I'm trying to tie in 3 different classes by using definitions in one class (reference) in another class(library), and then use the function that uses that object in another class(menu). I realize that I could just dump it all in any one of them and be done with it, but my instructor wants it done like this. Can anyone help?
#include <iostream>
#include <fstream>
#include <string>
#include "Reference.h"
using namespace std;
void reference::viewWord()
{
for(i = 0; i < 5; i++)
cout << i + 1 << ". " << word[i] << endl;
cout << " " << endl;
}
string reference::getWord()
{
ifstream inData;
inData.open("Words.txt"); // Opens quotes txt.
for(i = 0; i < 5; i++) // A for statement that will be used to house the lines of quotes.txt.
{
getline(inData, word[i]);
}
inData.close();
return word[5];
}
string reference::placeWord()
{
ofstream outData;
outData.open("Words.txt"); // Creates the text document addedQuotes.
cout << " " << endl;
cout << "To replace a word with your own word." << endl;
cin >> newWord;
cout << " " << endl;
cout << "Please enter the number of the felling that you would like to change then press ENTER." << endl;
cout << " " << endl;
cin >> overideWord;
word[overideWord - 1] = newWord;
for(i = 0; i < 5; i++)
{
outData << word[i] << endl;
}
cout << "To view your word, please check the file called userWord.txt." << endl;
cout << " " << endl;
outData.close();
return word[5];
}
reference::reference()
{
}
#include <iostream>
#include <string>
#include "Library.h"
#include "Color.h"
#include "Reference.h"
using namespace std;
string library::chooseReference()
{
cout << "Do you wish to replace a word?" << endl;
cout << " " << endl;
cout << "Please enter y then the ENTER button." << endl;
cout << "If not please press any key and enter to continue with the game." << endl;
cout << " " << endl;
cin >> chooseWord;
cout << " " << endl;
switch (chooseWord)
{
case 'Y':
case 'y':
say.getWord();
cout << "These are all the word." << endl;
cout << " " << endl;
say.viewWord();
cout << " " << endl;
cout << "Please enter your own word." << endl;
// The function below is going to allow the user to change one of the quotes.
cout << " " << endl;
say.placeWord();
cout << " " << endl;
cout << "This is the new list of quotes." << endl;
cout << "" << endl;
say.viewWord();
cout << " " << endl;
cout << "You now have the option of redoing your word." << endl;
chooseReference();
cout << " " << endl;
default:
return "goodbye";
}
}
library::library()
{
}
#include <iostream>
#include <string>
#include "Menu.h"
#include "Color.h"
#include "FirstColor.h"
#include "Library.h"
#include "Reference.h"
using namespace std;
string menu::holdGame()
{
color name;
color line;
firstColor line1;
library place;
reference hey;
color *secondLine;
color *anotherLine;
secondLine = new color("The average of your");
anotherLine = new firstColor(" numbers and color is ");
do
{
cout << " " << endl;
cout << "To play the game, please enter A then ENTER." << endl;
cout << " " << endl;
cout << "If not enter another key and press ENTER and the game will close." << endl;
cout << " " << endl;
cin >> answer;
cout << " " << endl;
switch (answer)
{
case 'A':
case 'a':
place.chooseReference();
findFirstNum();
findSecondNum();
average = (firstNum + secondNum + getNumOfColor()) / 3; // Finds the average of the 3 numbers and stores it.
printLine(secondLine);
printLine(anotherLine);
// I kept the average in a whole number range becuase it was easier to manage.
cout << average << "." << endl; // Displays the rounded average of the numbers for the user to see.
cout << " " << endl;
hey.getWord();
cout << "You will be " << hey.word[average - 2] << " today" << endl;
break;
default:
return "Please play again.";
break;
}
}
while(choice = 'Y' | 'y');
{
cout << "Do you wish to play again?" << endl;
cout << " " << endl;
cout << "Please press y then ENTER to play again." << endl;
cout << " " << endl;
cout << "If not press any key then ENTER to exit." << endl;
cout << " " << endl;
cin >> choice;
}
return "Please play again";
}
void menu::printLine(color *p)
{
p->print();
}
string menu::changeName()
{
cout << "There are 5 colors to choose from" << endl;
cout << " " << endl;
cout << "1. Green" << endl;
cout << "2. Red" << endl;
cout << "3. Black" << endl;
cout << "4. Blue" << endl;
cout << "5. Yellow" << endl;
cout << " " << endl;
cout << "Please choose 1 through 5 for the color you want." << endl;
cout << " " << endl;
cin >> num;
cout << " " << endl;
switch (num)
{
case 1:
return color1;
break;
case 2:
return color2;
break;
case 3:
return color3;
break;
case 4:
return color4;
break;
case 5:
return color5;
break;
default:
return "Good-bye";
}
}
int menu::getNumOfColor()
{
s = changeName();
n = s.size();
return n;
}
int menu::findFirstNum() throw(int)
{
try
{
cout << "Please enter a number between 2 and 6 as your first number." << endl;
cout << " " << endl;
cin >> firstNum;
cout << " " << endl;
if (firstNum > 6)
throw firstNum;
else if(firstNum < 2)
throw firstNum;
}
catch (int firstNum)
{
cout << "The number you have entered is not between 2 and 6." << endl;
cout << " " << endl;
findFirstNum();
}
return firstNum;
}
int menu::findSecondNum() throw (int)
{
try
{
cout << "Please enter a number between 2 and 6 as your second number." << endl;
cout << " " << endl;
cin >> secondNum;
cout << " " << endl;
if (secondNum > 6)
throw secondNum;
else if(secondNum < 2)
throw secondNum;
}
catch ( int secondNum)
{
cout << "Your second number is not between 2 and 6." << endl;
cout << " " << endl;
findSecondNum();
}
return secondNum;
}
menu::menu()
{
color1 = "Green";
color2 = "Red";
color3 = "Black";
color4 = "Blue";
color5 = "Yellow";
}