For my upcoming project in my computer science class, we have to make a star wars quiz game. Here is the project description:
The file star_wars.txt contains characters' names and the episode they first appeared in (this is chronological based on the release date - 4,5,6,1,2,3). You will populate a vector called cast with the contents of star_wars.txt. The cast vector is of type Character. The class Character has attributes matching the star_wars.txt file: first name, last name, episode. The program will ask the user what episode the character first appeared in. Tell the user if they are correct or incorrect. Keep track of how many they get correct, and give them a ranking based on their score.
Example of star_wars.txt:
Admiral Ackbar 6
Lando Calrissian 5
etc...
Can anyone help me with how I would put this file into a vector and display only the first and last name when asking the question? Any help would be GREATLY appreciated.
#include<iostream>
#include<vector>
#include<string>
#include<fstream>
usingnamespace std;
class Character
{
private:
int score;
int episode;
int guess;
public:
void readIn(vector<Character>&cast);
void readOut();
string first;
string last;
};
int main()
{
Character ch;
vector<Character> cast;
cout<<"Welcome to the star wars quiz! I will tell you a character and you have to tell me what episode they first appeared in. Lets play!"<<endl;
ch.readIn(cast);
cout<<ch.first<<endl;
return 0;
}
void Character::readIn(vector<Character>&cast)
{
ifstream myFile("star_wars.txt");
while ( !myFile.eof() )
{
myFile>>first;
}
}