C Projects
C Projects
3: TIC-TAC-TOE GAME.
Project Description: Voting System 2024
PARVEZ_M
“P_M”
//Voting
Author:2024 BY: PARVEZ_M.
PARVEZ_M.
#include<stdio.h>
V
#define CANDIDATE_COUNT
It is the basic console based voting software intended for 2024
#define CANDIDATE1 "PARVEZ_M"
elections.
#define It enables users
CANDIDATE2 "IMRANto KHAN"
vote for their candidates of choice
and check
#define the number"MARIYAM
CANDIDATE3 of votes each candidate has received and
NAWAS"
who is CANDIDATE4
#define the most voted"SHAHBAZ
candidate. SHARIF"
intFeatures:
votesCount1=0, votesCount2=0,
votesCount3=0, votesCount4=0,
O
spoiledtvotes=0;
Vote Allocation: Four candidates are available for users to choose
from:
void castVote(){
int choice;
1. Parvez M.### Please choose
printf("\n\n your
Candidate ####\n\n");
printf("\n
2. Imran1. %s", CANDIDATE1);
Khan
TI
printf("\n 2. %s", CANDIDATE2);
printf("\n 3. %s", CANDIDATE3);
3. Mariyam
printf("\n Nawaz
4. %s", CANDIDATE4);
printf("\n 5. %s", "None of These");
3. Shahbaz Sharif
printf("\n\n Input your choice (1 - 4) : ");
scanf("%d",&choice);
Users also have the option to select ‘None of These’ for spoiled
N
votes.
switch(choice){
case 1: votesCount1++; break;
Vote
caseCasting: The input from
2: votesCount2++; the user is captured towards voting
break;
incase
favor of the said candidate.
3: votesCount3++; break; It ensures invalid choices are
handled
case 4: correctly and the user
votesCount4++; is advised to make the right choice.
break;
case 5: spoiledtvotes++; break;
default:
Vote printf("\n
Counting: The Error:
systemWrong Choice
enables users !!to check how many
G
Please
votes retry");
each candidate was able to garner alongside how many
//hold the screen
spoilt votes there were.
getchar();
}
Leading thanks
printf("\n Candidate Identification:
for vote !!"); The software analyzes and
} shows the most voted candidate. In case of a draw, it will notify
the user that there is no winner.
void votesCount(){
printf("\n\n ##### Voting Statics ####");
User-Friendly Interface: There is a clear and easy to understand
printf("\n %s - %d ", CANDIDATE1,
menu through which users are guided in voting without any SYSTEM
votesCount1);
difficulty. %s - %d ", CANDIDATE1,
printf("\n 2024
Execution
votesCount2);
For executing
printf("\n %s a program,
- %d one ", can use a C compiler to compile C
CANDIDATE1,
votesCount3);
code, run the application, and process the instructions to vote or
printf("\n %s - %d ", CANDIDATE1,
check for results.
votesCount4);
CODE:
void getLeadingCandidate(){
PARVEZ_M printf("\n\n #### Leading Candiate
####\n\n");
if(votesCount1>votesCount2 &&
“P_M”
OUTPUT:
PARVEZ_M
“P_M”
PARVEZ_M
“P_M”
S
{ char name[30]; printf("\nfather name : %s", temp->fathername);
Author:
char dob[11];PARVEZ_M
char fathername[30];
char contactnumber[20];
printf("\nContact no : %s", temp->contactnumber);
printf("\nAddress : %s", temp->address);
temp = temp->NEXT;
M
This
char project is a rudimentary console based Student
address[50];
struct stdudent *NEXT;
}; System developed with C programming language.
Management
if(temp!=NULL){
This system
printf("\
n-----------------------------------------");
A
offers the capabilities of inserting student’s data, showing the printf("\nPress enter key for the
M
T
struct student *head = NULL; next record..");
details
struct studentof*tail
all =students
NULL; and removing all records as a linked list for getchar();
better management of the students’ data.
A
}
void addStudent() }
{ }
Features:
G
getchar(); }
struct student *temp = malloc(sizeof(struct
student)); void deleteAllStudent()
U E
printf("\nEnter
Addscanf("%[^\n]s", name
Student: Various of the
details of any student may{if(head
student : "); be filled by the
temp->name); == NULL)
Users, those include:
getchar(); printf("\nLinked list empty..");
M
else
printf("\nEnter DOB (MM/DD/YYYY) : "); {
Name scanf("%s", temp->dob); unsigned long int count = 0;
getchar(); struct student *temp = head;
E
D
printf("\nEnter father name : "); while(temp != NULL)
Datescanf("%[^\n]s",
of Birth (DOB) temp->fathername); { struct stduent * var = temp->NEXT;
getchar(); free(temp);
printf("\nEnter contact no : ");
Father Name temp->contactnumber);
scanf("%s",
getchar(); }
temp = var;
count++; N
printf("\nEnter address : ");
Contact Number temp->address);
scanf("%[^\n]s", count); T
printf("\n*** Number of nodes deleted : %ld***\n",
E
getchar(); }
temp->NEXT = NULL;
Address
if(head == NULL) /* it means linked list is empty:
}
int main()
S
no record */
Display
{ All Students:
head = temp;
Every student present in
{
the
int linked
choice =list
1; will Y
be displayed tail =in details by the system. If no records
temp; exist,!=0it ){so
while(choice
S
N
}
informs the users. printf("\n***** Main Menu *****");
else printf("\n\tPress 1 to add stdudent");
{
tail->NEXT = temp;
Delete AlltailStudents:
= temp;
There is an option for the user to lose all the
printf("\nEnter you choice : ");
T
printf("\n\tPress 2 to display add stduents");
printf("\n\tPress 0 to exit..");
student records
}
with a return of the space space that was
getchar();
and a number of records lost.
reserved
scanf("%d",&choice);
switch(choice)
E
T
} void displayAllStudents()
{ User-Friendly Interface: There is a menu based application so that
struct student *temp = head;
{
case 1: addStudent(); break; M
case 2: displayAllStudents(); break;
the user can select the required option from adding the student case 0: deleteAllStudent(); exit(1);
default : printf("\nInvalid choice..Please
record,
if(head displaying or deleting the student information.
== NULL)
input a valid no");
printf("\nNo record: Linked list empty!!");
getchar();
else
}}
{
return 0;
}
CODE:
PARVEZ_M
“P_M”
OUTPUT
PARVEZ_M
“P_M”
PARVEZ_M
“P_M”
Project Description: Tic-Tac-Toe Game
#include <stdio.h> int checkDraw(char board[SIZE][SIZE]) {
#define SIZE 3 int i;
void printBoard(char board[SIZE][SIZE]) { for (i = 0; i < SIZE; i++) {
printf("\n");
Project Description: Tic-Tac-Toe Game int j;
int i; for (j = 0; j < SIZE; j++) {
for (i = 0; i < SIZE; i++) { if (board[i][j] == ' ') {
Author:
int j;PARVEZ_M return 0; // Empty space found
for (j = 0; j < SIZE; j++) { }
printf(" %c ", board[i][j]); }
TIC
if (j < SIZE - 1) printf("|");
This is a commonplace and uncomplicated project involving the }
}
implementation of Tic-Tac-Toe with a computer console return 1;in// C No empty spaces, it's a draw
printf("\n");
programming language. It employs two players to execute the }
if (i < SIZE - 1) { int main() {
traditional game on a 3 by 3 cell board where the players
printf("---+---+---\n");
alternate
char board[SIZE][SIZE] = { {' ', ' ', ' '}, {'
to mark
} their markers (X and o) until one player’s', marks' ', ' '},wins
{' ', or
' ', ' '} };
all
} the cells are filled hence ending in a tie. int row, col;
TAC
printf("\n"); char player = 'X';
} while (1) {
Features: printBoard(board);
int checkWin(char board[SIZE][SIZE]) { printf("Player %c, enter row and
// Check rows and columns column (0-2): ", player);
int i; scanf("%d %d", &row, &col);
Game Board Display: The game is capable of displaying the Tic
TOE
for (i = 0; i < SIZE; i++) { // Check for valid input
Tac Toeifgame in the graphic
((board[i][0] mode and each
== board[i][1] && player’s progress
if (row < at 0 || row >= SIZE || col < 0 ||
every stage==
board[i][1] of the game. && board[i][0] !=
board[i][2] col >= SIZE || board[row][col] != ' ') {
' ') || printf("Invalid move! Try again.\n");
(board[0][i] == board[1][i] && continue;
board[1][i] == board[2][i] && board[0][i] != }
Player Input: Players each take a turn to input their move
' ')) {
in terms
board[row][col] = player;
of the return
row and 1;column coordinates where they wish to // place
Check their
for a win
icon.} Again, input validation is employed to ensure that a player
if (checkWin(board)) {
does
} not make illegal moves. printBoard(board);
// Check diagonals printf("Player %c wins!\n", player);
if ((board[0][0] == board[1][1] && break;
board[1][1]
Win and Draw == board[2][2]
Detection: The&& game
board[0][0] ! a method
contains } to check
= ' ') || // Check for a draw
for winning conditions after each
(board[0][2] == board[1][1] &&
move has been made. A player
if (checkDraw(board)) {
wins if the==
board[1][1] player has created
board[2][0] &&aboard[0][2]
row, column, ! or diagonalprintBoard(board);
with 3
= markers
' ')) { of their type. If no match has been achieved printf("It's and the a draw!\n");
usable
returnarea1;is full, the result is no winner. break;
} }
return 0; // Switch player
} player = (player == 'X') ? 'O' : 'X';
User-Friendly Interface: The console provides narration of the
}
actions that the players are expected to make along with a clear
presentation of the game status. return 0;
}
CODE:
PARVEZ_M
“P_M”
OUTPUT:
PARVEZ_M
“P_M”
THAT’S ALL.
PARVEZ_M