Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE DO IT IN THE SIMPLE WAY AND TRY DON\'T DO WITH THE VECTOR AS IT COMPLICAT

ID: 665669 • Letter: P

Question

PLEASE DO IT IN THE SIMPLE WAY AND TRY DON'T DO WITH THE VECTOR AS IT COMPLICATE TO UNDERSTAND THE CODE.

This is a C++ question, in this question you need to create HightScoreManager and User class.

HighScoreManager class should have a function to create a record and save it to a file organized descending based on the score and to print the top 10 High Scores to the screen. The class should look like the following. The High score structure should be stored in a binary file called highScore.dat file.

Class HighScoreManager

Private: Structure (username, score, date)

Public: CreateHighScore, UpdateHighScore, PrintHighScore

The user class will have the user login with his username if the username does not exist it will be added to a list of records. Once logged in the user will be able to update his info, set a high score, delete his information, or print all the high scores in a table format. The users will be stored in a text file called user.txt

The user class will contain the following:

Class User

Private: Structure (username, user info(between 1-4 fields)

Public: Login, CheckIfUserExist, UpdateUserList, DeleteUser, SetHighScore

           

In the main, the user will first login and then be shown a menu with the options to update his info, set a high score, delete his information, print all the high scores, exit.

Explanation / Answer

#include <bits/stdc++.h>
using namespace std;

class User{
   private:
       string username;
       string password;
};

class Wet{
   public:
       string name;
       int score;
       string date;
       Wet(string n,int s,string d){
           name = n;
           score = s;
           date = d;
       }
};

class HighScoreManager{
   private:
       int score;
       string date;
   public:
       string username;
       void CreateHighScore(){
           cout << "Enter the Score : ";
           cin >> score;
           ofstream infile;
           infile.open("highScore.dat",std::ios_base::app);
           string date;
           cout << "Enter the date : ";
           cin >> date;
           infile << username << " " << score << " " << date << endl;
           infile.close();
       }
       void UpdateHighScore(){
           ifstream infile;
           infile.open("highScore.dat");
           string s;
           vector<string> Token;
           vector<Wet*> v;
           while (!infile.eof()){
               getline(infile,s);
               Token.clear();
               stringstream line(s);
               while (line >> temp){                            // Split the a string with spaces and store in a vector Token.
                   Token.push_back(temp);          
               }
               Wet *w = new Wet(Token[0],atoi(Token[1].c_str()),Token[2]);
               v.push_back(w);
           }
           cout << "Enter the Score : ";
           cin >> score;
           ofstream outfile;
           outfile.open("highScore.dat",std::ios_base::app);
           string date;
           cout << "Enter the date : ";
           for (int i = 0; i < v.size(); i++){
               if (v[i]->name == username && v[i]->date == date){
                   v[i]->score = score;
                   break;
               }
           }
           outfile.close();
       }
       void PrintHighScore(){
           ifstream infile;
           infile.open("highScore.dat");
           string s;
           vector<string> Token;
           vector<Wet*> v;
           while (!infile.eof()){
               getline(infile,s);
               Token.clear();
               stringstream line(s);
               while (line >> temp){                            // Split the a string with spaces and store in a vector Token.
                   Token.push_back(temp);          
               }
               Wet *w = new Wet(Token[0],atoi(Token[1].c_str()),Token[2]);
               v.push_back(w);
           }
           for (int i = 0; i < v.size(); i++){
               for (int j = i+1; j < v.size(); j++){
                   if (v[i]->score > v[j]->score){
                       Wet *w = v[j];
                       v[j] = v[i];
                       v[i] = w;
                   }
               }
           }
           for (int i = 0; i < 10; i++){
               cout << v[i]->name << " " v[i]->score << " " << v[i]->date;
           }
       }
};      

int main(){
   string username;
   string password;
   ifstream infile;
   infile.open("user.txt");
   map<string,string> mymap;
   string s;
   vector<string> Token;
   while (!infile.eof()){
       getline(infile,s);
       Token.clear();
       stringstream line(s);
       while (line >> temp){
           Token.push_back(temp);          
       }
       mymap[Token[0]] = Token[1];
   }
   while (true){
       cout << "Enter User Name : ";
       cin >> username;
       cout << "Enter Password : ";
       cin >> password;
       if (mymap.find(username) == mymap.end()){
           cout << "No such user is there " << endl;
           mymap[username] = password;
           cout << " New Account created with username " << username << " ans Password is " << password << endl;
           break;
       }
       if (mymap.find(username)->second == password){
           cout << "Successfully Login " << endl;
           break;
       }
       else{
           cout << "Either password or username is wrong" << endl;
       }
   }
   int ch;
   while (true){
       cout << "Set a high score : 1" << endl;
       cout << "Print HighScore : 2" << endl;
       cout << "exit : 3" << endl;
       cin >> ch;
       if (ch == 1){
           HighScore *h = new HighScore();
           h->username = username;
           h->UpdateHighScore();
       }
       else if (ch == 2){
           HighScore *h = new HighScore();
           h->PrintHighScore();
       }
       else {
           break;
       }
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote