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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
#include <iostream>
#include <cstdlib>
#include <string.h>
#include <fstream>
#include <limits>
#include <string>
#include <array>
using namespace std;
struct RecAbbo{
std::string name;
std::string surname;
int games;
int won;
int same;
int lost;
int money;
}Abbo[100];
template<class It>
void addp();
void sort();
void sear();
void stat();
void game();
void play(int pl1,int pl2);
void menu();
template<class It>
int safe(It begin, It end);
template<class It>
int writetostruct(It begin, It end);
int main(){
fstream in,out;
in.open("data.txt", ios::in);
out.open("data.txt", ios::out);
menu();
in.close();
out.close();
}
void menu(){
bool exit=false;
int choise;
cout<<"welcome \n";
while (exit == false){
cout<<"==================================================== \n";
cout<<"please choose \n";
cout<<"1. add person \n";
cout<<"2. sort all accounts\n";
cout<<"3. search a certain person \n";
cout<<"4. see the avarage games and statics \n";
cout<<"5. create random game \n";
cout<<"0. exit program \n";
cout<<"==================================================== \n";
cin>>choise;
cout<<"==================================================== \n";
switch (choise){
case 1:
addp();
break;
case 2:
sort();
break;
case 3:
sear();
break;
case 4:
stat();
break;
case 5:
game();
break;
case 0:
exit=true;
break;
default:
cout<<"please choose one of the numbers given \n";
break;
}
}
}
void addp(){
int i,s;
while(Abbo[i].name.empty() != 0 )
i++;
cout<<"name: ";
cin>>Abbo[i].name;
cout<<"surname: ";
cin>>Abbo[i].surname;
Abbo[i].games = 0;
Abbo[i].won = 0;
Abbo[i].same = 0;
Abbo[i].lost = 0;
Abbo[i].money = 0;
s = safe(Abbo[0],Abbo[100]);
}
void sort(){
}
void sear(){
}
void stat(){
int avaragew,avarages,avaragel,avarageg,i=0;
while (i < 0){
avaragew = avaragew + Abbo[i].won;
i++;
}
i = 0;
while (i < 0){
avarages = avarages + Abbo[i].same;
i++;
}
i = 0;
while (i < 0){
avaragel = avaragel + Abbo[i].lost;
i++;
}
i = 0;
while (i < 0){
avarageg = avarageg + Abbo[i].games;
i++;
}
avaragew = avaragew/100;
avarages = avarages/100;
avaragel = avaragel/100;
i = 0;
cout<<"avarage games won :"<<avaragew<<"%\n";
cout<<"avarage games with same points :"<<avarages<<"%\n";
cout<<"avarage games lost :"<<avaragel<<"%\n";;
cout<<"total games played :"<<avarageg<<" games \n";
}
void game(){
char name1[20],name2[20],surname1[20],surname2[20];
int i1, i2, i = 0;
bool check = false, check2 = false ;
while (check == false){
i1 = rand() % 100;
i2 = rand() % 100;
while (check2 == false)
if (i1 == i2){
i2 = (i2 + rand() % 100) - 100;
} else {
if (Abbo[i1].name.empty() == 0 || Abbo[i2].name.empty() == 0){
check2 = false;
} else {
check2 = true;
check = true;
}
}
}
while (i < 20){
name1[i] = Abbo[i1].name[i];
name2[i] = Abbo[i2].name[i];
surname1[i] = Abbo[i1].surname[i];
surname2[i] = Abbo[i2].surname[i];
i++;
}
Abbo[i1].games++;
Abbo[i2].games++;
cout<<" player 1: player 2: \n";
cout<<"game: "<<name1<<surname1<<" VS :"<<name2<<surname2<<endl;
play(i1,i2);
}
template<class It>
int safe(It begin, It end){
fstream out;
out.open("data.txt", ios::out);
for (It = begin; It != end; ++It){
out << (*It).name << " \n";
out << (*It).surname << " \n";
out << (*It).games << " " << (*It).won << " " << (*It).same << " " <<
(*It).lost << " "<< (*It).money << "\n";
}
out.close();
return 0;
}
template<class It>
int writetostruct(It begin, It end){
fstream in;
in.open("data.txt", ios::in);
for (int i=0;i<100; i++){
in >> std::skipws;
getline( in, Abbo[i].surname);
getline( in, Abbo[i].name);
in >> Abbo[i].games >> Abbo[i].won >> Abbo[i].same >>
Abbo[i].lost >> Abbo[i].money;
}
in.close();
return 0;
}
void play(int pl1, int pl2){
int i, p1,p2,mode,p1money = 50, p2money = 50;
bool x = true,z = true;
while (x){
cout<<"for easy mode press 1 "<<endl;
cout<<"for normal mode press 2 "<<endl;
cout<<"for hard mode press 3 "<<endl;
cout<<"for beast mode press 4 "<<endl;
cout<<"choise: ";
cin>>mode;
switch (mode)
{
case 1:
i = rand() %100;
cout<<"number between 1 and 100"<<endl;
x=false;
break;
case 2:
i = rand() %500;
cout<<"number between 1 and 500"<<endl;
x=false;
break;
case 3:
i = rand() %2500;
cout<<"number between 1 and 2500"<<endl;
x=false;
break;
case 4:
i = rand() %10000;
cout<<"number between 1 and 10000"<<endl;
x=false;
break;
default:
cout<<"please choose again"<<endl;
break;
}
while(z){
cout<<"player 1: ";
cin>>p1;
if(p1 < i)
cout<<"number is higher"<<endl;
if(p1 > i)
cout<<"number is lower"<<endl;
cout<<"player 2: ";
cin>>p2;
if(p2 < i)
cout<<"number is higher"<<endl;
if(p2 > i)
cout<<"number is lower"<<endl;
if (p1 == i){
cout<<"player 1 has won!!"<<endl;
Abbo[pl1].won++;
Abbo[pl2].lost++;
Abbo[pl1].money = Abbo[pl1].money + p1money;
z = false;
} else {
p1money=p1money-5;
}
if (p2 == i){
cout<<"player 2 has won!!"<<endl;
Abbo[pl2].won++;
Abbo[pl1].lost++;
Abbo[pl2].money = Abbo[pl2].money + p2money;
z = false;
} else {
p2money=p2money-5;
}
if (p1money == 0 || p2money == 0){
Abbo[pl1].same++;
Abbo[pl2].same++;
}
}
}
}
|