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
|
class highScore
{
int scor;
char name[50];
public:
void tempStore(int &score);
void entername(int score)
{
setcolor(BLUE);
bar(130,100,530,380);
setcolor(RED);
settextstyle(0,0,0);
gotoxy(20,12);
cout<<"Score : ";
cout<<score;
gotoxy(20,14);
cout<<"Enter your name : ";
gets(name);
}
void display(int scor)
{
char prtsco[100];
setcolor(BLUE);
bar(100,100,630,470);
setcolor(GREEN);
settextstyle(0,0,1);
outtextxy(100,100,name);
sprintf(prtsco,"%d",scor);
outtextxy(100,130,prtsco);
}
}P;
void highScore::tempStore(int &score)
{
fstream hi;
hi.open("SCORE.dat",ios::app|ios::in|ios::binary|ios::out);
int temp[3],i=0,sc[3];
hi.read((char *)&P, sizeof(P));
while(!hi.eof())
{
temp[i]=scor;
i++;
hi.read((char *)&P, sizeof(P));
}
hi.close();
hi.open("SCORE.dat",ios::binary|ios::out);
while(!hi.eof())
{
if(score>=temp[2])
{
if(score>=temp[1])
{
if(score>=temp[0])
{
sc[2]=score;
entername(score);
}
else
{
sc[1]=score;
entername(score);
}
}
else
{
sc[0]=score;
entername(score);
}
}
hi.write((char *)&P, sizeof(P));
}
i=2;
hi.close();
hi.open("SCORE.dat",ios::in|ios::binary|ios::out);
while(!hi.eof())
{
scor=sc[i];
i--;
hi.write((char *)&P, sizeof(P));
}
hi.close();
hi.open("SCORE.dat",ios::in|ios::binary|ios::out);
hi.read((char *)&P, sizeof(P));
while(!hi.eof())
{
display(scor);
hi.read((char *)&P, sizeof(P));
}
}
|