Commit 56235ca7 authored by Kyle Malaguit's avatar Kyle Malaguit
Browse files

autosave

parent 80228ed1
......@@ -8,10 +8,9 @@ void SL2048::LoadContainers(){
exit(0);
}
string blank;
string name,date;
string name;
int score;
fin >> blank;
fin >> blank;
fin >> blank;
......@@ -19,14 +18,11 @@ void SL2048::LoadContainers(){
while(fin >> name){
//prep variables to store
fin >> score;
fin >> date;
//put into vector
Scores newScore(name, score, date);
Scores newScore(name, score);
scores.push_back(newScore);
}
cout << endl << scores.size() << endl;
fin.close();
}
......@@ -34,9 +30,9 @@ void SL2048::updateFile(){
ofstream fout;
fout.open("2048Data.txt", ofstream::out | ofstream::trunc);
//delete file contents
fout << "NAME" << "\t" << "SCORE" << "\t" << "DATE\n";
fout << "NAME" << "\t" << "SCORE" << endl;
for(auto scoresFull : scores){
fout << scoresFull.getName() << "\t" << scoresFull.getScore() << "\t" << scoresFull.getDate() << endl;
fout << scoresFull.getName() << "\t" << scoresFull.getScore() << endl;
}
fout.close();
......
......@@ -8,18 +8,16 @@ void SLSnake::LoadContainers(){
exit(0);
}
string blank;
string name,date;
string name;
int score;
fin >> blank;
fin >> blank;
fin >> blank;
//read from file intil it isempty
while(fin >> name){
fin >> score;
fin >> date;
//put into vector
Scores newScore(name, score, date);
Scores newScore(name, score);
scores.push_back(newScore);
}
......@@ -33,9 +31,9 @@ void SLSnake::updateFile(){
fout.open("snakedata.txt", ofstream::out | ofstream::trunc);
//update
fout << "NAME" << "\t" << "SCORE" << "\t" << "DATE\n";
fout << "NAME" << "\t" << "SCORE" << endl;
for(auto scoresFull : scores){
fout << scoresFull.getName() << "\t" << scoresFull.getScore() << "\t" << scoresFull.getDate() << endl;
fout << scoresFull.getName() << "\t" << scoresFull.getScore() << endl;
}
fout.close();
}
\ No newline at end of file
......@@ -14,11 +14,11 @@ void SaveLoad::pushBackNewScoreAndSort(Scores Score){
}
void SaveLoad::displayScores(){
cout << "Rank Name Score Date\n";
cout << "Rank Name Score" << endl;
int i = 1;
for (auto score : scores){
cout << i++ << "\t" << score.getName() << "\t" << score.getScore() << "\t" << score.getDate() << endl;
cout << i++ << "\t" << score.getName() << "\t" << score.getScore() << endl;
}
}
\ No newline at end of file
......@@ -7,19 +7,17 @@ using namespace std;
class Scores{
public:
Scores(string name, int score, string date){
Scores(string name, int score){
this-> name = name;
this-> score = score;
this-> date = date;
}
//accessors
string getName(){return name;}
int getScore(){return score;}
string getDate(){return date;}
private:
string name,date;
string name;
int score;
};
......
......@@ -23,12 +23,7 @@ int main(){
cin >> score;
cout << endl;
//enter date
char date[8];
cout << "Enter date in --/--/-- format.\nie. 3/9/19\n";
cin >> date;
Scores score1(userName, score, date);
Scores score1(userName, score);
second.pushBackNewScoreAndSort(score1);
second.updateFile();
......
NAME SCORE DATE
cdn 2147483647 ðR@
nge 654346 3/10/19
vfd 45365 4/6/19
vfd 4636 4/12/19
DVS 3423 3/12/19
dew 343 4/5/19
NAME SCORE
nge 654346
vfd 45365
cdn 21474
vfd 4636
vev 4536
DVS 3423
dew 343
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment