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

C++ ( tic tac toe game) implement all the following methods in a separate file t

ID: 3915807 • Letter: C

Question

C++ ( tic tac toe game)

implement all the following methods in a separate file ticTacToe.cpp where 2 human beings play against each other

the main is given

//Header file TITTTTTTTTTTTIHI111111UTTITT1111 #ifndef ticTacToe H #define ticTacToe H class tisTactoe private: chac A[3][3]; int result; //result of the game. We have 3 possibilities: win, lose, draw int player; // keeps track of the player to make a move (e.g. playerl or player2) int plies; //keeps track of the number of half-moves made so far int winner; // (Optional variable) announces the final winner of the game (if not //a draw) bool gameOvec I/ tests to see if the game is over bool checkMove (int, int);// checks to see if the values entered by the player are //consistent bool testndGam); // tests to see if the game has ended l isFull// tests to see if all the table is full (i.e. no more moves can be // made) public: tisTacToe); void startGame); /I called once the game starts. vaid print(); //prints the game //It calls several functions (e.g.checkMove) #end if

Explanation / Answer

#include<iostream.h>
#include<process.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>

void openwindow();
void closewindow();

static int bcnt=0,mcnt=0;
int i,j;

class book
{
protected:
int bno[5];
char bname[5][20];
char aname[5][20];
int flag[5];
public:
void add_book();

void mod_book();
void del_book();
void show_book();
int retbno(int a);
};

struct dat
{
int dd;
int mm;
int yr;
};

class member:book
{
long regno[5];
int fn[5];
char mname[5][20];
int mbno[5];
dat di[5],dr[5];
public:
void add_mem();
void mod_mem();
void del_mem();
void show_mem();
void b_issue(book bk);
void b_return(book bk);
void greater(dat,dat);
int fine(dat,dat);
dat dt();
};

void book::add_book()
{
clrscr();
cout<<" NEW BOOK ENTRY... ";
cout<<" Enter the book no.:";
cin>>(bno[bcnt]);
cout<<" Enter the Name of the Book:";
gets(bname[bcnt]);
cout<<" Enter the Author's Name:";
gets(aname[bcnt]);
cout<<" Book Created..";
flag[bcnt]=0;
bcnt++;
}

void book::show_book()
{
clrscr();
for(i=0;i<bcnt;i++)
{
cout<<" Book no. : "<<bno[i];
cout<<" Book Name : ";
puts(bname[i]);
cout<<"Author Name : ";
puts(aname[i]);
if(flag[i]==1)
cout<<"The book is issued. ";
else
cout<<"The book is not issued. ";
}
if(i==0)
cout<<" No book is found.";
}

void book::mod_book()
{
clrscr();
int b_no;
cout<<" Enter book no.:";
cin>>b_no;
for(i=0;i<bcnt;i++)
if(b_no==bno[i])
{
cout<<" Enter the name of the book:";
gets(bname[i]);
cout<<" Enter the name of the author:";
gets(aname[i]);
break;
}
if(i==bcnt)
cout<<"No such book is found.";
}

void book::del_book()
{
clrscr();
int b_no;
cout<<" Enter the book no. of the book to be deleted:";
cin>>b_no;
for(i=0;i<bcnt;i++)
if(b_no==bno[i])
{
for(j=i;j<bcnt;j++)
{
flag[j]=flag[j+1];
bno[j]=bno[j+1];
strcpy(bname[j],bname[j+1]);
strcpy(aname[j],aname[j+1]);
}
bcnt-=1;
cout<<" Book record deleted...";
break;
}
if(i==bcnt)
cout<<" No such book is found.";
}

int book::retbno(int a)
{
return bno[a];
}

void member::add_mem()
{
clrscr();
cout<<" NEW MEMBER ENTRY... ";
cout<<" Enter the registration no.:";
cin>>regno[mcnt];
cout<<" Enter the Name of the member:";
gets(mname[mcnt]);
cout<<" Member Created..";
fn[i]=0;
mbno[i]=0;
mcnt++;
}

void member::show_mem()
{
clrscr();
for(i=0;i<mcnt;i++)
{
cout<<" Registration no. : "<<regno[i];
cout<<" Member Name : ";
puts(mname[i]);
if(mbno[i]!=0)
{
cout<<" Book code of the issued book:"<<mbno[i];
cout<<" ";
}
cout<<"Fine:"<<fn[i]<<" ";
}
if(i==0)
cout<<" No member is found.";
}
void member::mod_mem()
{
clrscr();
long reg_no;
cout<<" Enter registration no.:";
cin>>reg_no;
for(i=0;i<mcnt;i++)
if(reg_no==regno[i])
{
cout<<" Enter the name of the member:";
gets(mname[i]);
break;
}
if(i==mcnt)
cout<<"No such member is found.";
}

void member::del_mem()
{
clrscr();
long reg_no;
cout<<" Enter the registration no. of the member to be deleted:";
cin>>reg_no;
for(i=0;i<mcnt;i++)
if(reg_no==regno[i])
{
for(j=i;j<mcnt;j++)
{
regno[j]=regno[j+1];
fn[j]=fn[j+1];
mbno[j]=mbno[j+1];
strcpy(mname[j],mname[j+1]);
}
mcnt-=1;
cout<<" Member details deleted...";
break;
}
if(i==mcnt)
cout<<" No such member is found.";
}

dat member::dt()
{
int chk=0;
dat d;
cin>>d.dd>>d.mm>>d.yr;
if((d.yr<1000)||(d.yr>9999))
{
cout<<" Year must be in range 1000-9999 ! ";
chk=1;
}
if((d.mm>12)||(d.mm<=0)||(d.dd<=0)||(d.yr<=0))
chk=1;
if(d.mm==2)
{
if((d.yr%400==0)||((d.yr%4==0)&&(d.yr%100!=0)))
{
if(d.dd>29)
chk=1;
}
else if(d.dd>28)
chk=1;
}
else if((d.mm==4)||(d.mm==6)||(d.mm==9)||(d.mm==11))
{
if(d.dd>30)
chk=1;
}
else if(d.dd>31)
chk=1;
if(chk==1)
{
cout<<" Invalid date! Enter again : ";
dt();
}
return d;
}

void member::greater(dat d1,dat d2)
{
int chk=0;
if(d2.yr>d1.yr);
else if(d2.yr==d1.yr)
{
if(d2.mm>d1.mm);
else if(d2.mm==d1.mm)
{
if(d2.dd>d1.dd);
else
{
chk=1;
}
}
else
{
chk=1;
}
}
else
{
chk=1;
}
if(chk==0);
else
{
cout<<" Invalid returning date.";
getch();
}
}

int member::fine(dat d1,dat d2)
{
int c,rs,a=0,b=0,y,j;
if(d2.yr<d1.yr)
{
y=d2.yr;
for(j=y;j<d1.yr;j++)
{
if((j%400==0)||((j%4==0)&&(j%100!=0)))
a+=366;
else
a+=365;
}
for(j=1;j<d1.mm;j++)
{
if(j==1||j==3||j==5||j==7||j==8||j==10||j==12)
a+=31;
else if(j==4||j==6||j==9||j==11)
a+=30;
else if((j==2)&&(d1.yr%400==0)||((d1.yr%4==0)&&(d1.yr%100!=0)))
a+=29;
else
a+=28;
}
a+=d1.dd;
for(j=1;j<d2.mm;j++)
{
if(j==1||j==3||j==5||j==7||j==8||j==10||j==12)
b+=31;
else if(j==4||j==6||j==9||j==11)
b+=30;
else if((j==2)&&(d2.yr%400==0)||((d2.yr%4==0)&&(d2.yr%100!=0)))
b+=29;
else
b+=28;
}
b+=d2.dd;
}
else if(d1.yr<d2.yr)
{
y=d1.yr;
for(j=y;j<d2.yr;j++)
{
if((j%400==0)||((j%4==0)&&(j%100!=0)))
b+=366;
else
b+=365;
}
for(j=1;j<d1.mm;j++)
{
if(j==1||j==3||j==5||j==7||j==8||j==10||j==12)
a+=31;
else if(j==4||j==6||j==9||j==11)
a+=30;
else if((j==2)&&(d1.yr%400==0)||((d1.yr%4==0)&&(d1.yr%100!=0)))
a+=29;
else
a+=28;
}
a+=d1.dd;
for(j=1;j<d2.mm;j++)
{
if(j==1||j==3||j==5||j==7||j==8||j==10||j==12)
b+=31;
else if(j==4||j==6||j==9||j==11)
b+=30;
else if((j==2)&&(d2.yr%400==0)||((d2.yr%4==0)&&(d2.yr%100!=0)))
b+=29;
else
b+=28;
}
b+=d2.dd;
}
else
{
for(j=1;j<d1.mm;j++)
{
if(j==1||j==3||j==5||j==7||j==8||j==10||j==12)
a+=31;
else if(j==4||j==6||j==9||j==11)
a+=30;
else if((j==2)&&(d1.yr%400==0)||((d1.yr%4==0)&&(d1.yr%100!=0)))
a+=29;
else
a+=28;
}
a+=d1.dd;
for(j=1;j<d2.mm;j++)
{
if(j==1||j==3||j==5||j==7||j==8||j==10||j==12)
b+=31;
else if(j==4||j==6||j==9||j==11)
b+=30;
else if((j==2)&&(d2.yr%400==0)||((d2.yr%4==0)&&(d2.yr%100!=0)))
b+=29;
else
b+=28;
}
b+=d2.dd;
}
c=b-a;
if(c<8)
{
rs=0;
cout<<" Book returned on time.";
}
else if(c>7 && c<22)
{
rs=2*(c-7);
cout<<" Book is returned after "<<c-7<<" days. So fine =Rs. "<<rs;
}
else
{
rs=5*(c-7);
cout<<" Book is returned after "<<c-7<<" days of returning date. So fine =Rs. "<<rs;
}
return rs;
}

void member::b_issue(book bk)
{
clrscr();
long reg_no;
int b_no;
cout<<" Enter the registration no. of the member:";
cin>>reg_no;
for(i=0;i<mcnt;i++)
if(reg_no==regno[i])
{
cout<<" Enter the book no., you want to issue:";
cin>>b_no;
for(j=0;j<bcnt;j++)
{
if(b_no==bk.retbno(j))
{
mbno[i]=b_no;
cout<<" Enter date of issueing the book:";
di[i]=dt();
flag[j]=1;
cout<<" You have to return the book within 7 days.";
break;
}
}
if(j==bcnt)
cout<<" No such book is found.";
break;
}
if(i==mcnt)
cout<<" No such member is found.";
}

void member::b_return(book bk)
{
clrscr();
long reg_no;
cout<<" Enter the registration no. of the member:";
cin>>reg_no;
for(i=0;i<mcnt;i++)
if(reg_no==regno[i])
{
cout<<" Book no. of the book issued to the member:"<<mbno[i];
for(j=0;j<bcnt;j++)
{
int b_no2;
b_no2=bk.retbno(j);
if(mbno[i]==b_no2)
{
cout<<" Enter date of returning the book:";
dr[i]=dt();
greater(di[i],dr[i]);
fn[i]=fine(di[i],dr[i]);
flag[j]=0;
break;
}
}
if(j==bcnt)
cout<<" No such book is issued.";
break;
}
if(i==mcnt)
cout<<" No such member is found.";
}

void intro()
{
clrscr() ;
gotoxy(31,5) ;
cout <<"Welcome to Project" ;
textcolor(BLACK+BLINK) ;
textbackground(WHITE) ;
gotoxy(26,7) ;
cprintf(" LIBRARY MANAGEMENT SYSTEM ") ;
textcolor(LIGHTGRAY) ;
textbackground(BLACK) ;
gotoxy(15,10) ;
cout <<"This project has facility of maintaining records" ;
gotoxy(15,11) ;
cout <<"of BOOKS and MEMBERS." ;
gotoxy(15,14) ;
cout <<"One member can issue one book at a time. If he/she" ;
gotoxy(55,17) ;
cout <<"Designed By::" ;
gotoxy(55,18) ;
cout <<"Prshant" ;

gotoxy(55,19) ;
cout <<"Parveen Kumar" ;
gotoxy(55,20) ;
cout <<"Kapil Sharma" ;
gotoxy(55,21) ;
cout <<"Manish Kumar" ;
gotoxy(55,22) ;
cout <<"Prshant Kumar" ;
textcolor(LIGHTGRAY+BLINK) ;
gotoxy(27,25) ;
cprintf("Press any key to continue") ;
textcolor(LIGHTGRAY) ;
}

void openwindow()
{

int aa,bb,cc,dd,maxx,maxy,i=10;

maxx=getmaxx();

maxy=getmaxy();

rectangle(0,0,maxx,maxy);//border

aa=250;

bb=400;

cc=260;

for(dd=250;dd<350;dd+=20)

{

setfillstyle(1,GREEN);

bar(dd,bb,cc,bb+10);

cc+=20; //space between rectangles

}

aa=250;

bb=400;

cc=260;

while(!kbhit())

{

setcolor(i);
settextstyle( TRIPLEX_FONT,HORIZ_DIR,4);
outtextxy(250,getmaxy()/2-200,"WELCOME");


outtextxy(300,getmaxy()/2-160,"IN");
outtextxy(75,getmaxy()/2-120,"HOSTEL MANAGEMENT SYSTEM");

setcolor(i);
outtextxy(300,getmaxy()/2-160,"IN");
settextstyle( TRIPLEX_FONT,HORIZ_DIR,2);
outtextxy(400,getmaxy()/2-40,"Designed By:");
settextstyle( TRIPLEX_FONT,HORIZ_DIR,1);
outtextxy(450,getmaxy()/2,"Kapil Kumar");
outtextxy(450,getmaxy()/2+20,"Ravindra Saini");
outtextxy(450,getmaxy()/2+40,"Jaan Mohammad");
outtextxy(450,getmaxy()/2+60,"Dheerendra Kumar");
outtextxy(450,getmaxy()/2+80,"Ankit Kumar");


if((aa==350)&&(cc==360))

{

aa=250;

cc=260;

continue;

}

else

{

setcolor(10);

rectangle(aa,bb,cc,bb+10);

rectangle(aa-1,bb-1,cc+1,bb+11);

}

delay(300);

setcolor(BLACK);

rectangle(aa,bb,cc,bb+10);

rectangle(aa-1,bb-1,cc+1,bb+11);

aa+=20;

cc+=20;

}

}

void closewindow()

{

int i,j,k;

cleardevice();

rectangle(0,0,638,478);

k=0;

while(!kbhit())

{

setcolor(k);

settextstyle(5,0,8);

outtextxy(100,200,"THANK YOU");

line(90,300,600,300);

delay(200);

k++;
}
}


void main()
{

//openwindow();
int choice;
clrscr();
intro();
getch();
int ch,ch1,ch2;
char ans='y';
book bk;
member mr;
do
{
clrscr();
cout<<" Main Menu";
cout<<" ~~~~~~~~~";
cout<<" 1. Books options";
cout<<" 2. Members options";
cout<<" 3. Exit";
cout<<" Enter your choice:";
cin>>ch;
switch(ch)
{
case 1:clrscr();
cout<<" Books Option";
cout<<" ~~~~~~~~~~~~";
cout<<" 1. Add a book";
cout<<" 2. Show all books";
cout<<" 3. Modify a book";
cout<<" 4. Delete a book";
cout<<" 5. Back to main menu";
cout<<" Enter your choice:";
cin>>ch1;
switch(ch1)
{
case 1:bk.add_book();
break;
case 2:bk.show_book();
break;
case 3:bk.mod_book();
break;
case 4:bk.del_book();
break;
case 5:break;
default:cout<<" Wrong input.Enter again!!!";
break;
}
break;
case 2:clrscr();
cout<<" Members Option";
cout<<" ~~~~~~~~~~~~~~";
cout<<" 1. Add a member";
cout<<" 2. Show all members";
cout<<" 3. Modify a member";
cout<<" 4. Delete a member";
cout<<" 5. Issue a book";
cout<<" 6. Return a book";
cout<<" 7. Back to main menu";
cout<<" Enter your choice:";
cin>>ch2;
switch(ch2)
{
case 1:mr.add_mem();
break;
case 2:mr.show_mem();
break;
case 3:mr.mod_mem();
break;
case 4:mr.del_mem();
break;
case 5:mr.b_issue(bk);
break;
case 6:mr.b_return(bk);
break;
case 7:break;
default:cout<<" Wrong input.Enter again!!!";
break;
}
break;
case 3:exit(0);
default:cout<<" Wrong input.";
}
cout<<" Do you want to continue(Y/N)";
cin>>ans;
}while(ans=='y'||ans=='Y');
}