0% found this document useful (0 votes)
18 views15 pages

C Project

This document is a computer science project submitted by Ravinder Singh, which includes programs for Tic-Tac-Toe and Typing Speed, along with runtime screenshots and a bibliography. The project acknowledges the support of teachers, parents, and the CBSE board. It contains source code for both programs and details on how they function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views15 pages

C Project

This document is a computer science project submitted by Ravinder Singh, which includes programs for Tic-Tac-Toe and Typing Speed, along with runtime screenshots and a bibliography. The project acknowledges the support of teachers, parents, and the CBSE board. It contains source code for both programs and details on how they function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Computer

Science
Project
Submitted To:
Deepak Sir
Submitted By:
Ravinder Singh
12 TH
–A
Board Roll No.- 9690683

INDEX
1
S.No. Description
Page No.
1. Acknowledgement
03
2. Program for Tic-Tac-Toe
04
3. Program Run Time
Screenshots 07
4. Program for Typing Speed
09
5. Program Run Time
Screenshots 13
6. Bibliography
14

2
ACKNOWLEDGEM
ENT
I would like to express my special
thanks of gratitude to my
Computer Science teacher, Mr.
Deepak as well as our Principal
Mr.C.P.S. Kedia who gave me this
opportunity to do this project. ‘It
helped me in doing a lot of
research and through it I came to
know about so many new things. I
am really thankful to them.

Secondly I would like to thank my


Parents and Friends who helped me

3
a lot in finishing this project within
the limited time.

I would also like to thank the CBSE


board for giving me this
opportunity to explore beyond the
regular NCERT textbook.

1. PROGRAM FOR TIC-TAC-


TOE
/**********************************
SOURCE CODE
**********************************/
#include <iostream.h>
#include <string.h>
#include <conio.h>

char square[10] = {'o','1','2','3','4','5','6','7','8','9'};


int checkwin();
void board();

int main()
{
int player = 1,i,choice;
char mark;
clrscr();
do
{
board();

4
player=(player%2)?1:2;
cout << "Player " << player << ", enter a number: ";
cin >> choice;
mark=(player == 1) ? 'X' : 'O';
if (choice == 1 && square[1] == '1')
square[1] = mark;
else if (choice == 2 && square[2] == '2')
square[2] = mark;
else if (choice == 3 && square[3] == '3')
square[3] = mark;
else if (choice == 4 && square[4] == '4')
square[4] = mark;
else if (choice == 5 && square[5] == '5')
square[5] = mark;
else if (choice == 6 && square[6] == '6')
square[6] = mark;
else if (choice == 7 && square[7] == '7')
square[7] = mark;
else if (choice == 8 && square[8] == '8')
square[8] = mark;
else if (choice == 9 && square[9] == '9')
square[9] = mark;
else
{
cout<<"Invalid move ";
player--;
getch();
}
i=checkwin();
player++;
}while(i==-1);
board();
if(i==1)
cout<<"==>\aPlayer "<<--player<<" win ";
else
cout<<"==>\aGame draw";
getch();
return 0;
}
/*********************************************
FUNCTION TO RETURN GAME STATUS
1 FOR GAME IS OVER WITH RESULT
-1 FOR GAME IS IN PROGRESS
O GAME IS OVER AND NO RESULT

5
**********************************************/

int checkwin()
{
if (square[1] == square[2] && square[2] == square[3])
return 1;
else if (square[4] == square[5] && square[5] == square[6])
return 1;
else if (square[7] == square[8] && square[8] == square[9])
return 1;
else if (square[1] == square[4] && square[4] == square[7])
return 1;
else if (square[2] == square[5] && square[5] == square[8])
return 1;
else if (square[3] == square[6] && square[6] == square[9])
return 1;
else if (square[1] == square[5] && square[5] == square[9])
return 1;
else if (square[3] == square[5] && square[5] == square[7])
return 1;
else if (square[1] != '1' && square[2] != '2' && square[3] != '3' &&
square[4] != '4' && square[5] != '5' && square[6] != '6' && square[7] != '7' &&
square[8] != '8' && square[9] != '9')
return 0;
else
return -1;
}

/*******************************************************************
FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK
********************************************************************/

void board()
{
clrscr();
cout << "\n\n\tTic Tac Toe\n\n";
cout << "Player 1 (X) - Player 2 (O)" << endl << endl;
cout << endl;
cout << " | | " << endl;
cout << " " << square[1] << " | " << square[2] << " | " << square[3] <<
endl;
cout << "_____|_____|_____" << endl;

6
cout << " | | " << endl;
cout << " " << square[4] << " | " << square[5] << " | " << square[6] <<
endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << square[7] << " | " << square[8] << " | " << square[9] <<
endl;
cout << " | | " << endl << endl;
}

/*******************************************************************
END OF PROJECT
********************************************************************

PROGRAM RUN TIME


SCREENSHOTS

7
8
2. PROGRAM FOR TYPING
SPEED
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define ESC 0x1b
#define BSPACE 0x08

const unsigned long far * const dosTime = (const unsigned long far * const)MK_FP( 0x40, 0x6C );

class Timer
{

public:

Timer();
void start();

9
void stop();
void reset();
int status();
double time();
static double resolution();
private:

static unsigned adjust;


static unsigned calibrate();
int running;
struct TIME
{
unsigned long dosCount;
unsigned timerCount;
};
TIME startTime;
double time_;
};

inline double Timer::time()


{
return time_/1.E6;
}

inline double Timer::resolution()


{
return 839/1.E9;
}

unsigned Timer::adjust = calibrate();

Timer::Timer() : time_(0), running(0)


{
}

void Timer::start()
{
if( !running )
{
outportb( 0x43, 0x34 );
asm jmp __1;
__1:
outportb( 0x40, 0 );
asm jmp __2;

10
__2:
outportb( 0x40, 0 );
startTime.dosCount = *dosTime;
startTime.timerCount = 0;
running = 1;
}
}

void Timer::stop()
{
outportb( 0x43, 0 );
unsigned char temp = inportb( 0x40 );

TIME stopTime;
stopTime.timerCount = (inportb( 0x40 ) << 8) + temp;
stopTime.dosCount = *dosTime;

TIME elapsedTime;
elapsedTime.dosCount = stopTime.dosCount - startTime.dosCount;
elapsedTime.timerCount = -( stopTime.timerCount - adjust );

const double fudge = 83810.0/100000.0;


time_ += ((elapsedTime.dosCount << 16) +
elapsedTime.timerCount)*fudge;

running = 0;

void Timer::reset()
{
time_ = 0;
if( running )
start();
}

unsigned Timer::calibrate()
{
adjust = 0;
unsigned long sum = 0;
Timer w;
for( int i = 0; i < 100; i++ )
{
w.start();

11
w.stop();
sum += w.time();
w.reset();
}
return (unsigned)((sum+5)/100);
}

void main()
{
clrscr();
Timer t;
char text[1000];
int i = 0, space_count = 0, letter_count = 0;
float duration;
printf("PROGRAM TO TEST TYPING SPEED\n");
printf("Hit any key to start timer..\n");
if(getch())
{
printf("Your time has started. Start typing. Hit Esc when done.\n");
t.start();
}
while(1)
{
text[i] = getche();
letter_count++;
if(text[i] == ' ')
space_count++;
if(text[i] == ' ')
printf("");
if(text[i] == BSPACE)
printf(" "); // to erase previous character instead of cursoring over
if(text[i] == ESC)
{
printf(" ");
// to eliminate a special character that is printed for Esc
// A Backspace followed by Space erases previous character.
break;
}
}

t.stop();
duration = t.time();
printf("\nYour typing speed is :");

12
printf("\n%6.2f characters per minute",60*letter_count/duration);
printf("\n%6.2f words per minute (Actual)",60*space_count/duration);
printf("\n%6.2f words per minute (Average)",60*letter_count/duration/5);

getch();
}

PROGRAM RUN TIME


SCREENSHOTS

13
14
Bibliography:
 Computer Science Book by Sumita Arora
 www.google.com
 www.scribd.com
 www.slideshare.com

THANK YOU

15

You might also like