1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#include <iostream>
#include <ostream>
#include <string>
#include <vector>
#include <iterator>
#include <fstream>
#include <cstdio>
#include "player.h"
using namespace std;
class database
{
private:
player get_datam;
vector<player>playersave;
public:
void save (player);
void display (player);
void list ();
void removep ();
};
void database::save(player get_datam)
{
playersave.push_back(get_datam);
ofstream outf("tttt.txt",fstream::app);
outf << playersave.size() <<' '; // Notice the space, it's important
for(long i=0;i<playersave.size();i++)
{
outf << playersave[i]<<endl;
outf << " ";
}
void database::display(player get_datam)
{
vector<player>::iterator it;
for(it = playersave.begin(); it != playersave.end(); ++it)
{
it -> player_();
}
}
//*** option one "1-select a player"***//
void database::list()
{
string ps;
string user;
cout << "Select one from the following players by choosing his number" << endl;
ifstream in("playerlist.txt");
string temp;
while(getline(in, temp))
cout << temp << endl;
in.close();
cin>> ps;
if (ps== "1")
{
user= "George";
cout << "the player has been selected" << endl;
cout << "You have been redirected to the main menu" << endl;
}
else if (ps== "2")
{
user= "Katherine";
cout << "the player has been selected" << endl;
cout << "You have been redirected to the main menu" << endl;
}
else if (ps== "3")
{
user= "Hang";
cout << "the player has been selected" << endl;
cout << "You have been redirected to the main menu" << endl;
}
else if (ps== "4")
{
user= "Cindy";
cout << "the player has been selected" << endl;
cout << "You have been redirected to the main menu" << endl;
}
else
{
cout <<"Error:Invalid option."<<endl;
}
}
//*****************************************************//
void database::removep()
{
string pr;
string line;
cout << "Remove one from the following players by choosing his number" << endl;
ifstream in("playerlist.txt");
ofstream out("outfile.txt");
string temp;
while(getline(in, temp))
cout << temp << endl;
in.close();
cin>> pr;
if (pr== "1")
{
while( getline(in,line) )
{
if(line != "George")
out << line << "\n";
}
in.close();
out.close();
remove("playerlist.txt");
rename("outfile.txt","playerlist.txt");
cout << "the player has been removed" << endl;
cout << "You have been redirected to the main menu" << endl;
}
else if (pr== "2")
{
while( getline(in,line) )
{
if(line != "Katherine")
out << line << "\n";
}
in.close();
out.close();
remove("playerlist.txt");
rename("outfile.txt","playerlist2.txt");
cout << "the player has been removed" << endl;
cout << "You have been redirected to the main menu" << endl;
}
else if (pr== "3")
{
while( getline(in,line) )
{
if(line != "Hang")
out << line << "\n";
}
in.close();
out.close();
remove("playerlist.txt");
rename("outfile.txt","playerlist2.txt");
cout << "the player has been removed" << endl;
cout << "You have been redirected to the main menu" << endl;
}
else if (pr== "4")
{
while( getline(in,line) )
{
if(line != "Cindy")
out << line << "\n";
}
in.close();
out.close();
remove("playerlist.txt");
rename("outfile.txt","playerlist2.txt");
cout << "the player has been removed" << endl;
cout << "You have been redirected to the main menu" << endl;
}
else
{
cout <<"Error:Invalid option."<<endl;
}
}
|