Hang Man Game Code: Github
Hang Man Game Code: Github
It is a simple project just to provide a Hang Man game concept.In this project I haven’t
draw a man for a wrong choice so,try to draw a simple man by using “|” pattern in your
project which make your project better .
Here is the source code ,copy and compile it in Code::blocks gcc compiler or Download
project from GitHub.
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <cstring>
using namespace std;
inline void type_of_word(char f);
int main()
{ char c,h,ch,ch1,ch2;
char word[25];
char word2[25];
int l,i,ng,n,k,x;
do{
do{
c='\0';
cout<<"\n\t\t *********** HANGMAN IN C++ ***********\n\n";
cout<<"(E) Enter a word\n\n(C) Computer chooses word\n\n(A)"
cout<<"Add new word to list\n\n(Q) Quit\n\n\nEnter your choice (E - C - Q): ";
cin>>ch2;
}while (ch2!='C' && ch2!='c' && ch2!='E' && ch2!= 'e' &&
ch2!='Q' && ch2!= 'q'&& ch2!='A' && ch2!= 'a');
if (ch2 == 'Q' || ch2=='q') exit (0);
if (ch2 == 'C' || ch2=='c')
{
ifstream fin("hangword.txt");
if(!fin) {
cout<<"File missing, aborting.\n\nYou are missing a file of name"
cout<<"**hangword.txt**\n\nLocate it, then place it next to the"
"program file.\n\n"; system("pause"); return 0;}
for (i=0;!fin.eof();i++) fin.getline(word,25);
fin.close();
do {
x=rand();
}while(x>i || x<0);
ifstream finn("hangword.txt");
for (i=0;!finn.eof();i++)
{finn>>c; finn.getline(word,25); if (x==i) break;}
finn.close();
}
if (ch2 == 'A' || ch2=='a')
{
ofstream fout("hangword.txt",ios::app);
if(!fout) {//clrscr();
cout<<"File missing, aborting.\n\nYou are missing a file of name"
" **hangword.txt**\n\nLocate it, then place it next to the program"
" file.\n\n"; system("pause"); return 0;}
cin.get();
cout<<"Choose the topic of your word\n\n(M) Movie\n\n(A) Animal\n\n(P)"
" Sport\n\n(S) Song\n\nEnter your choice (A-P-S-M) : ";
cin>>h;
cin.get();
//clrscr();
cout<<"\n\nThe word should not exceed 25 letters\n\nEnter the word : ";
cin.getline(word,25);
fout<<h<<word<<endl;
fout.close();
}
if (ch2 == 'E' || ch2=='e')
{// clrscr();
cin.get();
cout<<"\t\t\t Type the word : ";
cin.getline (word, 25);
}
if (ch2 == 'E' || ch2=='e' || ch2 == 'C' || ch2=='c')
{
l=strlen(word);
char choosen[25]="\0";
n=0;k=0;
for(i=0;i<=24;i++)
{
if (word[i]=='\0') {word2[i]='\0';break;}
if (word[i]==' ') {word2[i]=' '; n++;}
if (word[i]!=' ') word2[i]='-';
}
ng=l+2-n; //only 2 guesses extra
do{
there: type_of_word(c);
if (k!=0) cout<<"\n\n\t\t\tChoosen letters : "<<choosen<<"\n";
cout<<"\n\n\n\t\t\t "<<word2<<"\n\n\nYou have "<<ng
<< " guesses left, choose a letter : ";
cin>>ch; cin.get();
for (i=0;i<25;i++) if (choosen[i]==ch) {//clrscr();
cout<<"\a\t\t !!You have choosen "<<ch<<" already!!\n";goto there;}
ng--; choosen [k]=ch; choosen [k+1]=',';k+=2;
for (i=0;i<=24;i++)
if (word[i]==ch || word[i]==ch+32 || word[i]==ch-32) word2[i]=ch;
if (!strcmpi (word2,word)) {cout<<"\n\t\t\t "<<strupr(word)
<<"\n\n\t\t\tCongratulations :-()\n"; break;}
}while(ng>0 || !strcmpi (word2,word));
if (strcmpi (word2,word)) cout<<"\nSorry, maybe next time.\n\nThe word was : "
<<strupr(word)<<endl;
}
cout<<"\nWould you like to play again??? (Y - N) : ";
cin>>ch1; cin.get();
}while (ch1=='y' || ch1=='Y');
system("PAUSE");
return 0;
}
inline void type_of_word(char f)
{ if (f=='m') cout<<"\t\t\t\tMOVIE";
if (f=='a') cout<<"\t\t\t\tANIMAL";
if (f=='p') cout<<"\t\t\t\tSPORT";
if (f=='s') cout<<"\t\t\t\tSONG";
}
SNAKE GAME
Mini project in C many Student do management project like library management ,Hotel
management etc.But Snake Game is mini project of first semester build by my friend
which is very different.It is console application without graphic library that's why it is
more interesting.This game is perfect without any error and better user interface.It is
complied in code::block using c language.Here goes a source code you can copy and
compiled it in code::block.I hope it can help and become a reference for your
project. Download Project from Github.
?
1 #include <stdio.h>
2 #include <time.h>
#include <stdlib.h>
3 #include <conio.h>
4 #include<time.h>
5 #include<ctype.h>
6 #include <time.h>
#include <windows.h>
7 #include <process.h>
8
9 #define UP 72
10 #define DOWN 80
11 #define LEFT 75
12 #define RIGHT 77
13
int length;
14 int bend_no;
15 int len;
16 char key;
17 void record();
18 void load();
int life;
19 void Delay(long double);
20 void Move();
21 void Food();
22 int Score();
void Print();
23 void gotoxy(int x, int y);
24 void GotoXY(int x,int y);
25 void Bend();
26 void Boarder();
27 void Down();
void Left();
28 void Up();
29 void Right();
30 void ExitGame();
31 int Scoreonly();
32
33 struct coordinate{
int x;
34 int y;
35 int direction;
36 };
37
38 typedef struct coordinate coordinate;
39
coordinate head, bend[500],food,body[30];
40
41
42 int main()
43 {
44
char key;
45
46 Print();
47
48 system("cls");
49
50 load();
51
52 length=5;
53
head.x=25;
54
55 head.y=20;
56
57 head.direction=RIGHT;
58
59 Boarder();
60
61 Food(); //to generate food coordinates initially
62
63 life=3; //number of extra lives
64
bend[0]=head;
65
66 Move(); //initialing initial bend coordinate
67
68 return 0;
69
70 }
71
72 void Move()
73 { int a,i;
74
75 do{
76
77 Food();
78 fflush(stdin);
79
80 len=0;
81
for(i=0;i<30;i++)
82
83 {
84
85 body[i].x=0;
86
87 body[i].y=0;
88
89 if(i==length)
90
91 break;
92
93 }
94
Delay(length);
95
96 Boarder();
97
98 if(head.direction==RIGHT)
99
10 Right();
0
10 else if(head.direction==LEFT)
1
Left();
10
2 else if(head.direction==DOWN)
10
3 Down();
10
4 else if(head.direction==UP)
10
5 Up();
10
6 ExitGame();
10
}while(!kbhit());
7
10 a=getch();
8
10 if(a==27)
9
11 {
0
11 system("cls");
1
11 exit(0);
2 }
11 key=getch();
3
11 if((key==RIGHT&&head.direction!=LEFT&&head.direction!=RIGHT)||(key==LEFT&&head.di
4 (key==DOWN&&head.direction!=UP&&head.direction!=DOWN))
11
5 {
11
bend_no++;
6
11 bend[bend_no]=head;
7
11 head.direction=key;
8
11 if(key==UP)
9
12 head.y--;
0
12 if(key==DOWN)
1
12 head.y++;
2
if(key==RIGHT)
12
3 head.x++;
12
4 if(key==LEFT)
12
5 head.x--;
12
6 Move();
12
}
7
12 else if(key==27)
8
12 {
9
13 system("cls");
0
13 exit(0);
1
13 }
2
else
13
3 {
13
4 printf("\a");
13
5 Move();
13
6 }
13 }
7 void gotoxy(int x, int y)
13 {
8
13 COORD coord;
9
14 coord.X = x;
0
14 coord.Y = y;
1
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
14
2 }
14 void GotoXY(int x, int y)
3 {
14 HANDLE a;
4 COORD b;
fflush(stdout);
14 b.X = x;
5 b.Y = y;
14 a = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(a,b);
6 }
14 void load(){
7 int row,col,r,c,q;
14 gotoxy(36,14);
printf("loading...");
8 gotoxy(30,15);
14 for(r=1;r<=20;r++){
9 for(q=0;q<=100000000;q++);//to display the character slowly
15 printf("%c",177);}
0 getch();
}
15 void Down()
1 {
15 int i;
2 for(i=0;i<=(head.y-bend[bend_no].y)&&len<length;i++)
15 {
GotoXY(head.x,head.y-i);
3 {
15 if(len==0)
4 printf("v");
15 else
printf("*");
5 }
15 body[len].x=head.x;
6 body[len].y=head.y-i;
15 len++;
7 }
Bend();
15 if(!kbhit())
8 head.y++;
15 }
9 void Delay(long double k)
16 { Score();
0 long double i;
16 for(i=0;i<=(10000000);i++);
1 }
16 void ExitGame()
{
2 int i,check=0;
16 for(i=4;i<length;i++) //starts with 4 because it needs minimum 4 element to tou
3 {
16 if(body[0].x==body[i].x&&body[0].y==body[i].y)
4 {
check++; //check's value increases as the coordinates of head is equal
16 }
5 if(i==length||check!=0)
16 break;
6 }
16 if(head.x<=10||head.x>=70||head.y<=10||head.y>=30||check!=0)
{
7 life--;
16 if(life>=0)
8 {
16 head.x=25;
head.y=20;
9 bend_no=0;
17 head.direction=RIGHT;
0 Move();
17 }
else
1 {
17 system("cls");
2 printf("All lives completed\nBetter Luck Next Time!!!\nPress any key to q
17 record();
exit(0);
3 }
17 }
4 }
17 void Food()
5 {
if(head.x==food.x&&head.y==food.y)
17 {
6 length++;
17 time_t a;
7 a=time(0);
17 srand(a);
food.x=rand()%70;
8 if(food.x<=10)
17 food.x+=11;
9 food.y=rand()%30;
18 if(food.y<=10)
0
food.y+=11;
18 }
1 else if(food.x==0)/*to create food for the first time coz global variable are init
18 {
2 food.x=rand()%70;
18 if(food.x<=10)
food.x+=11;
3 food.y=rand()%30;
18 if(food.y<=10)
4 food.y+=11;
18 }
5 }void Left()
18 {
6 int i;
18 for(i=0;i<=(bend[bend_no].x-head.x)&&len<length;i++)
7 {
GotoXY((head.x+i),head.y);
18 {
8 if(len==0)
18 printf("<");
9 else
19 printf("*");
}
0 body[len].x=head.x+i;
19 body[len].y=head.y;
1 len++;
19 }
2 Bend();
if(!kbhit())
19 head.x--;
3
19 }
4 void Right()
19 {
int i;
5 for(i=0;i<=(head.x-bend[bend_no].x)&&len<length;i++)
19 {
//GotoXY((head.x-i),head.y);
6 body[len].x=head.x-i;
19 body[len].y=head.y;
7 GotoXY(body[len].x,body[len].y);
19 {
if(len==0)
8 printf(">");
19 else
9 printf("*");
20 }
0 /*body[len].x=head.x-i;
body[len].y=head.y;*/
20 len++;
1 }
20 Bend();
2 if(!kbhit())
20
}
head.x++;
3 void Bend()
20 {
4 int i,j,diff;
20 for(i=bend_no;i>=0&&len<length;i--)
{
5 if(bend[i].x==bend[i-1].x)
20 {
6 diff=bend[i].y-bend[i-1].y;
20 if(diff<0)
7 for(j=1;j<=(-diff);j++)
{
20 body[len].x=bend[i].x;
8 body[len].y=bend[i].y+j;
20 GotoXY(body[len].x,body[len].y);
9 printf("*");
21 len++;
if(len==length)
0 break;
21 }
1 else if(diff>0)
21 for(j=1;j<=diff;j++)
{
2 /*GotoXY(bend[i].x,(bend[i].y-j));
21 printf("*");*/
3 body[len].x=bend[i].x;
21 body[len].y=bend[i].y-j;
4 GotoXY(body[len].x,body[len].y);
printf("*");
21 len++;
5 if(len==length)
21 break;
6 }
21 }
else if(bend[i].y==bend[i-1].y)
7 {
21 diff=bend[i].x-bend[i-1].x;
8 if(diff<0)
21 for(j=1;j<=(-diff)&&len<length;j++)
{
9 /*GotoXY((bend[i].x+j),bend[i].y);
22 printf("*");*/
0 body[len].x=bend[i].x+j;
22 body[len].y=bend[i].y;
GotoXY(body[len].x,body[len].y);
1 printf("*");
22 len++;
2 if(len==length)
22 break;
}
3 else if(diff>0)
22 for(j=1;j<=diff&&len<length;j++)
4 {
22 /*GotoXY((bend[i].x-j),bend[i].y);
5 printf("*");*/
body[len].x=bend[i].x-j;
22 body[len].y=bend[i].y;
6 GotoXY(body[len].x,body[len].y);
22 printf("*");
7 len++;
22 if(len==length)
break;
8 }
22 }
9 }
23 }
void Boarder()
0 {
23 system("cls");
1 int i;
23 GotoXY(food.x,food.y); /*displaying food*/
2 printf("F");
for(i=10;i<71;i++)
23 {
3 GotoXY(i,10);
23 printf("!");
4 GotoXY(i,30);
23 printf("!");
}
5 for(i=10;i<31;i++)
23 {
6 GotoXY(10,i);
23 printf("!");
GotoXY(70,i);
7 printf("!");
23 }
8 }
23 void Print()
9 {
//GotoXY(10,12);
24 printf("\tWelcome to the mini Snake game.(press any key to continue)\n");
0 getch();
24 system("cls");
1 printf("\tGame instructions:\n");
24 printf("\n-> Use arrow keys to move the snake.\n\n-> You will be provided foods at
length of the snake will be increased by 1 element and thus the score.\n\n-> Here you
2 body.\n\n-> YOu can pause the game in its middle by pressing any key. To continue the
24 printf("\n\nPress any key to play game...");
3 if(getch()==27)
24 exit(0);
}
4 void record(){
24 char plname[20],nplname[20],cha,c;
5 int i,j,px;
24 FILE *info;
info=fopen("record.txt","a+");
6 getch();
24 system("cls");
7 printf("Enter your name\n");
24 scanf("%[^\n]",plname);
//************************
8 for(j=0;plname[j]!='\0';j++){ //to convert the first letter after space to capital
24 nplname[0]=toupper(plname[0]);
9 if(plname[j-1]==' '){
25 nplname[j]=toupper(plname[j]);
0 nplname[j-1]=plname[j-1];}
else nplname[j]=plname[j];
25 }
1 nplname[j]='\0';
25 //*****************************
2 //sdfprintf(info,"\t\t\tPlayers List\n");
25 fprintf(info,"Player Name :%s\n",nplname);
//for date and time
3
25 time_t mytime;
4 mytime = time(NULL);
25 fprintf(info,"Played Date:%s",ctime(&mytime));
5 //**************************
fprintf(info,"Score:%d\n",px=Scoreonly());//call score to display score
25 //fprintf(info,"\nLevel:%d\n",10);//call level to display level
6 for(i=0;i<=50;i++)
25 fprintf(info,"%c",'_');
7 fprintf(info,"\n");
25 fclose(info);
printf("wanna see past records press 'y'\n");
8 cha=getch();
25 system("cls");
9 if(cha=='y'){
26 info=fopen("record.txt","r");
0 do{
putchar(c=getc(info));
26 }while(c!=EOF);}
1 fclose(info);
26 }
2 int Score()
{
26 int score;
3 GotoXY(20,8);
26 score=length-5;
4 printf("SCORE : %d",(length-5));
26 score=length-5;
GotoXY(50,8);
5 printf("Life : %d",life);
26 return score;
6 }
26 int Scoreonly()
7 {int score=Score();
26 system("cls");
8 return score;
26 }
9 void Up()
{
27 int i;
0 for(i=0;i<=(bend[bend_no].y-head.y)&&len<length;i++)
27 {
GotoXY(head.x,head.y+i);
1 {
27 if(len==0)
2 printf("^");
27 else
printf("*");
3 }
27 body[len].x=head.x;
4 body[len].y=head.y+i;
27 len++;
5 }
Bend();
27 if(!kbhit())
6 head.y--;
27 }
7
27
8
27
9
28
0
28
1
28
2
28
3
28
4
28
5
28
6
28
7
28
8
28
9
29
0
29
1
29
2
29
3
29
4
29
5
29
6
29
7
29
8
29
9
30
0
30
1
30
2
30
3
30
4
30
5
30
6
30
7
30
8
30
9
31
0
31
1
31
2
31
3
31
4
31
5
31
6
31
7
31
8
31
9
32
0
32
1
32
2
32
3
32
4
32
5
32
6
32
7
32
8
32
9
33
0
33
1
33
2
33
3
33
4
33
5
33
6
33
7
33
8
33
9
34
0
34
1
34
2
34
3
34
4
34
5
34
6
34
7
34
8
34
9
35
0
35
1
35
2
35
3
35
4
35
5
35
6
35
7
35
8
35
9
36
0
36
1
36
2
36
3
36
4
36
5
36
6
36
7
36
8
36
9
37
0
37
1
37
2
37
3
37
4
37
5
37
6
37
7
37
8
37
9
38
0
38
1
38
2
38
3
38
4
38
5
38
6
38
7
38
8
38
9
39
0
39
1
39
2
39
3
39
4
39
5
39
6
39
7
39
8
39
9
40
0
40
1
40
2
40
3
40
4
40
5
40
6
40
7
40
8
40
9
41
0
41
1
41
2
41
3
41
4
41
5
41
6
41
7
41
8
41
9
42
0
42
1
42
2
42
3
42
4
42
5
42
6
42
7
42
8
42
9
43
0
43
1
43
2
43
3
43
4
43
5
43
6
43
7
43
8
43
9
44
0
44
1
44
2
44
3
44
4
44
5
44
6
44
7
44
8
44
9
45
0
45
1
45
2
45
3
45
4
45
5
45
6
45
7
45
8
45
9
46
0
46
1
46
2
46
3
46
4
46
5
46
6
46
7
46
8
46
9
47
0
47
1
47
2
47
3
47
4
47
5
47
6
47
7
47
8
47
9
48
0
48
1
48
2
48
3
48
4
48
5
48
6
48
7
48
8
48
9
49
0
49
1
49
2
49
3
49
4
49
5
49
6
49
7
49
8
49
9
50
0
50
1
50
2
50
3
50
4
50
5
50
6
50
7
50
8
50
9
51
0
51
1
51
2
51
3
51
4
51
5
51
6
51
7
51
8
51
9
52
0
52
1
52
2
52
3
52
4
52
5
52
6
52
7
52
8
52
9
53
0
53
1
53
2
QUIZ GAME
In this mini project I didn't use file handling for storing and reading question .I have
used file only for storing score won by players so it is not good Idea. Anyway this project
may guide you to create Quiz game by using file handling for storing and reading
question . Download Project from Github
#include<stdio.h>
#include<conio.h>
#include <windows.h>
#include<ctype.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>
void displayscore()
{
char name[20];
float s;
FILE *f;
system("cls");
f=fopen("score.txt","r");
fscanf(f,"%s%f",&name,&s);
printf("\n\n\t\t ");
printf("\n\n\t\t %s has secured the Highest Score %.2f",name,s);
printf("\n\n\t\t ");
fclose(f);
getch();
}
void help()
{
system("cls");
printf("\n\n\n\tThis game is very easy to play. You'll be asked some general");
printf("\n\n\tknowledge questions and the right answer is to be chosen among");
printf("\n\n\tthe four options provided. Your score will be calculated at the");
printf("\n\n\tend. Remember that the more quicker you give answer the more");
printf("\n\n\tscore you will secure. Your score will be calculated and displayed");
printf("\n\n\tat the end and displayed. If you secure highest score, your score");
printf("\n\n\twill be recorded. So BEST OF LUCK.");
}
void writescore(float score, char plnm[20])
{
float sc;
char nm[20];
FILE *f;
system("cls");
f=fopen("score.txt","r");
fscanf(f,"%s%f",&nm,&sc);
if (score>=sc)
{ sc=score;
fclose(f);
f=fopen("score.txt","w");
fprintf(f,"%s\n%.2f",plnm,sc);
fclose(f);
}
}
int main()
{
int countq,countr;
int r,i;
int pa;int nq[6];int w;
float score;
char choice;
char playername[20];
time_t initialtime,finaltime;
system("cls");
//randomize();
mainhome:
system("cls");
puts("\n\t\t WELCOME TO I.Q. TEST PROGRAM\n\n") ;
puts("\n\t\t-------------------------------");
puts("\n\t\t Enter 'S' to start game ");
puts("\n\t\t Enter 'V' to view high score ");
puts("\n\t\t Enter 'H' for help ");
puts("\n\t\t Enter 'Q' to quit ");
printf("\n\t\t-------------------------------\n\n\t\t ");
choice=toupper(getch());
if (choice=='V')
{
displayscore();
goto mainhome;
}
else if (choice=='Q')
exit(1);
else if (choice=='H')
{
help();
getch();
goto mainhome;
}
else if(choice=='S'){
system("cls");
home:
system("cls");
initialtime=time(NULL);
countq=countr=0;
i=1;
start:
srand ( time(NULL) );
r=rand()%23+1;
nq[i]=r;
for (w=0;w<i;w++)
if (nq[w]==r) goto start;
switch(r)
{
case 1:
printf("\n\nWhat is the maximum no. of asymptotes of the curve x^4+2x+6=0?");
printf("\n\nA.4\tB.3\n\nC.none\tD.infinite\n\n");
countq++;
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is A.4");break;}
case 2:
printf("\n\n\nHow many points are possible in a compound pendulum about which");
printf("time period is same?");
printf("\n\nA.4\tB.2\n\nC.none\tD.infinite\n\n");
countq++;
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; break;}
else
printf("\n\nWrong!!! The correct answer is A.4");
break;
case 3:
printf("\n\n\nWho was the first US President?");
printf("\n\nA.Richard Nikson\tB.Abraham Linkon\n\nC.John F. Kennedy\tD.George
Washington\n\n");
countq++;
if (toupper(getch())=='D')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is D.George Washington");break;}
case 4:
printf("\n\n\nWho was awarded the 'Man of the Tournament' of ICC WORLD CUP
2007?");
printf("\n\nA.Glen Magrath\tB.Mahela Jawardan\n\nC.Mathew Hayden\tD.Sachin
Tendulkar\n\n");
countq++;
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is A.Glen Magrath");break;}
case 5:
printf("\n\n\nWhich country won the Fifa World Cup 1998?");
printf("\n\nA.France\tB.Brazil\n\nC.Italy\tD.England\n\n");
countq++;
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is A.France");break;}
case 6:
printf("\n\n\nWhich syllabe is stressed in the word 'democracy'?");
printf("\n\nA.1st\tB.2nd\n\nC.3rd\tD.4th\n\n");
countq++;
if (toupper(getch())=='B' )
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is B.2nd");break;}
case 7:
printf("\n\n\nWhich country was the winner of Cricket World Cup 1987?");
printf("\n\nA.West Indies\tB.India\n\nC.Australia\tD.England\n\n");
countq++;
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is C.Australia");break;}
case 8:
printf("\n\n\nWhat is the height of Mount everest in feet?");
printf("\n\nA.8648\tB.6648\n\nC.8884\tD.8848\n\n");
countq++;
if (toupper(getch())=='D')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is D.8848");break;}
case 9:
printf("\n\n\nWhat is the capital of Denmark?");
printf("\n\nA.Copenhagen\tB.Helsinki\n\nC.Rome\t\tD.Madrid\n\n");
countq++;
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is A.Copenhagen");break;}
case 10:
printf("\n\n\nWhich syllabe is stressed in the word 'instanteneous'?");
printf("\n\nA.1st\tB.2nd\n\nC.3rd\tD.4th\n\n");
countq++;
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is C.3rd");break;}
case 11:
printf("\n\n\nWho was the only player to score 6 successive sixes in an over?");
printf("\n\nA.Adam Gilchrist\tB.M.S.Dhoni\n\nC.Herschel Gibbs\tD.Sanath
Jayasurya\n\n");
countq++;
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is C.Herschel Gibbs");break;}
case 12:
printf("\n\n\nWho was the only player to take 4 successive wickets?");
printf("\n\nA.Malinga Bandara\tB.Lasith Malinga\n\nC.Bret Lee\tD.Murali Daran\n\n");
countq++;
if (toupper(getch())=='B')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is B.Lasith Malinga");break;}
case 13:
printf("\n\n\nWhich country is hosting the Fifa World Cup 2010?");
printf("\n\nA.South Africa\tB.Italy\n\nC.Argentina\tD.Spain\n\n");
countq++;
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is A.South Africa");break;}
case 14:
printf("\n\n\nWho is the author of 'Pulpasa Cafe'?");
printf("\n\nA.Narayan Wagle\tB.Lal Gopal Subedi\n\nC.B.P. Koirala\tD.Khagendra
Sangraula\n\n");
countq++;
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is A.Narayan Wagle");break;}
case 15:
printf("\n\n\nWhich country is Maria Sarapova from?");
printf("\n\nA.Russia\tB.Switzerland\n\nC.Argentina\tD.Spain\n\n");
countq++;
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is A.Russia");break;}
case 16:
printf("\n\n\nWho was awarded the youngest player award in Fifa World Cup 2006?");
printf("\n\nA.Wayne Rooney\tB.Lucas Podolski\n\nC.Lionel Messi\tD.Christiano
Ronaldo\n\n");
countq++;
if (toupper(getch())=='B')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is B.Lucas Podolski");break;}
case 17:
printf("\n\n\nWhat is the smallest district of Nepal?");
printf("\n\nA.Lalitpur\tB.Karnali\n\nC.Bhaktapur\tD.Gulmi\n\n");
countq++;
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is C.Bhaktapur");break;}
case 18:
printf("\n\n\nWhat is the headquarter of Western Development Region?");
printf("\n\nA.Dhankuta\tB.Kathmandu\n\nC.Dhangadhi\tD.Pokhara\n\n");
countq++;
if (toupper(getch())=='D')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is D.Pokhara");break;}
case 19:
printf("\n\n\nWhich place is called 'The Cherrapunji of Nepal'?");
printf("\n\nA.Dharan\tB.Kathmandu\n\nC.Pokhara\tD.Butwal\n\n");
countq++;
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is C.Pokhara");break;}
case 20:
printf("\n\n\nWhich city is known at 'The City of Seven Hills'?");
printf("\n\nA.Rome\tB.Vactican City\n\nC.Madrid\tD.Berlin\n\n");
countq++;
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is A.Rome");break;}
case 21:
printf("\n\n\nWho was the F1 racing champion of 2006?");
printf("\n\nA.Louis Hamilton\tB.Felipe Massa\n\nC.Fernando Alonso\tD.Michael
Schumaker\n\n");
countq++;
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is C.Fernanda Alonso");break;}
case 22:
printf("\n\n\nWho won the Women Australian Open 2007?");
printf("\n\nA.Martina Hingis\tB.Maria Sarapova\n\nC.Kim Clijster\tD.Serena
Williams\n\n");
countq++;
if (toupper(getch())=='D')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is D.Serena Williams");break;}
case 23:
printf("\n\n\nName the country where there no mosquito is found?");
printf("\n\nA.Germany\tB.Spain\n\nC.Japan\tD.France\n\n");
countq++;
if (toupper(getch())=='D')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is D.France");break;}
}
i++;
if (i<=5) goto start;
finaltime=time(NULL);
score=(float)countr/countq*100-difftime(finaltime,initialtime)/3;
if (score<0) score=0;
printf("\n\n\nYour Score: %.2f",score);
if (score==100) printf("\n\nEXCELLENT!!! KEEP IT UP");
else if (score>=80 && score<100) printf("\n\nVERY GOOD!!");
else if (score>=60 &&score<80) printf("\n\nGOOD! BUT YOU NEED TO KNOW MORE.");
else if (score>=40 && score<60) printf("\n\nSATISFACTORY RESULT, BUT THIS MUCH
IS MUCH SUFFICIENT.");
else printf("\n\nYOU ARE VERY POOR IN G.K.,WORK HARD");
puts("\n\nNEXT PLAY?(Y/N)");
if (toupper(getch())=='Y')
goto home;
else
{
writescore(score,playername);
goto mainhome;
}
}
else
{
printf("\n\n\t\t Enter the right key\n\n\t\t ");
Sleep(700);
goto mainhome;
}
return 0;
}
LIBRARY MANAGEMENT
This is my college 1st semester mini project “library management “ in C programming
language.This is console application without graphic and compiled in code::block with
gcc compiler. I hope it will help you to develop your own project similar project related
to file handling for example “Banking “,” customer records”,”student records" etc.
I have divided my project into many function and I will describe each of them which may
help you to understand better.
Using like this function is not good so don’t use in your project.
void issuerecord();
This function is used to keep record of student for whom book is issued.
void loaderanim();
void gotoxy (int x, int y)
This is most important function used to print text in any place of screen of our
programme .We can use this function directly in turbo c but it doesn’t work in
code::block so we write code for this.
Below I have given code for gotoxy in code::block.
This mini project is about department store all features required for department store
are added in this programe.You can copy the source code and compile it in a code
block.This project is perfect for your college mini project in C. Download Project from
Github
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<windows.h>
#define ANS 15
#define ACS 4
COORD coord={0,0}; // this is global variable
//center of axis is set to the top left cornor of the screen
void gotoxy(int x,int y)
{
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
/*declaration of checking functions*/
void c_code(char[]);
int check(char[]);
/*structure declaration*/
typedef struct{
char name[ANS],code[ACS];
float rate;
int quantity;
}rec;
rec item;
/*start of main*/
int main()
{
d_mainmenu();
return 0;
}
void d_mainmenu()
{
int i;
char ch;
const char *menu[]={" Calculate Bill"," Add Goods"," Edit Goods"," Display All ","
Search", " Delete Goods"," Exit"};
system("cls");
//textbackground(11);
//textcolor(0);
//_setcursortype(_NOCURSOR);
window(25,50,20,32);
gotoxy(33,18);printf("MAIN MENU");
for (i=0;i<=6;i++){
gotoxy(30,22+i+1);printf("%s\n\n\n",menu[i]);}
curser(7);
}
void d_search()
{
char ch;
int i;
const char *menu[]={" By Code"," By Rate"," By Quantity"," Back to main
menu"};
system("cls");
//textbackground(11);
//textcolor(0);
window(25,50,20,32);
gotoxy(33,18);printf("SEARCH MENU");
for (i=0;i<=3;i++){
gotoxy(30,22+i+1);printf("%s\n\n\n",menu[i]);}
curser(4);
}
if(no==7){
//textbackground(11);
//textcolor(0);
gotoxy (30,23);printf(" Calculate Bill ");
gotoxy (30,24);printf(" Add Goods ");
gotoxy (30,25);printf(" Edit Goods ");
gotoxy (30,26);printf(" Display All ");
gotoxy (30,27);printf(" Search ");
gotoxy (30,28);printf(" Delete Goods ");
gotoxy (30,29);printf(" Exit ");
//textcolor(0);
//textbackground(2);
switch(count){
case 1:
gotoxy (30,23);
printf(" - Calculate Bill ");
break;
case 2:
gotoxy (30,24);
printf(" - Add Goods ");
break;
case 3:
gotoxy (30,25);
printf(" - Edit Goods ");
break;
case 4:
gotoxy (30,26);
printf(" - Display All ");
break;
case 5:
gotoxy (30,27);
printf(" - Search ");
break;
case 6:
gotoxy (30,28);
printf(" - Delete Goods ");
break;
case 7:
gotoxy (30,29);
printf(" - Exit ");
break;
}
}
}
void bill()
{
char x[4]={0};
int j=29,q=0,size=0,i=1;
float total=0,gtotal=0;
FILE *file;
file=fopen("record.txt","r+b");
rewind(file);
system("cls");
dbill();
gotoxy(26,15);printf("enter \"end\" to finish input");
while(1){
gotoxy(25,18);printf(" ");
gotoxy(25,19);printf(" ");
gotoxy(25,18);printf("enter item code:");
scanf("%s",x);
if(strcmp(x,"end")==0)
break;
gotoxy(25,19);printf("enter quantity:");
scanf("%d",&q);
rewind(file);
while(fread(&item,sizeof(item),1,file)){
if((strcmp(item.code,x)==0)){
total=item.rate*q;
gotoxy(11,j);printf("%4d",i);
printf("%9s",item.name);
printf("%13d",q);
printf("%15.2f",item.rate);
printf("%13.2f",total);
gtotal=gtotal+total;
size=sizeof(item);
item.quantity=item.quantity-q;
j+=2; i++;
fseek(file,-size,SEEK_CUR);fwrite(&item,sizeof(item),1,file);
break;
}
}
}
if(gtotal!=0){
gotoxy(30,j+5);
printf("TOTAL AMOUNT = NRs. %6.2f",gtotal);
}
fclose(file);
getch();
d_mainmenu();
}
/*function to display bill window*/
void dbill()
{
int i;
gotoxy(20,10);
//;
for (i=1;i<=10;i++)
printf("*");
printf(" * FASHION WEAR * ");
for (i=1;i<=10;i++)
printf("*");
printf("\n\n");
gotoxy(30,11);printf("Departmental Store");
//textcolor(1);
gotoxy(32,25);printf("CUSTOMER'S BILL") ;
//textcolor(8);
gotoxy(13,27);printf("SN. Item Name Quantity Rate Total");
}
/*function to add records*/
void add ()
{
FILE *file;
char y[ACS],x[12];
system("cls");
//textbackground(11);
//textcolor(0);
gotoxy(25,25);printf("Enter new record(Y/N)?");
while(toupper(getche())=='Y'){
system("cls");
file=fopen("record.txt","ab");
c_code(y);
strcpy(item.code,y);
gotoxy(22,28);printf("Enter rate of the item:");
scanf("%f",&item.rate);
gotoxy(22,30);printf("Enter quantity of the item:");
scanf("%d",&item.quantity);
gotoxy(22,32);printf("Enter name of the item:");
scanf("%s",item.name);
fseek(file,0,SEEK_END);fwrite(&item,sizeof(item),1,file);
fclose(file);
gotoxy(22,34);printf("Enter new record(Y/N)?");
}
d_mainmenu();
}
gotoxy(a,17);printf("\xc9");
gotoxy(a,18);printf("\xba");
gotoxy(a,19);printf("\xc8");
gotoxy(b,17);printf("\xbb");
gotoxy(b,18);printf("\xba");
gotoxy(b,19);printf("\xbc");
//textcolor(4);
for(i=c;i<=d;i++){
gotoxy(a,i);printf("\xba");
gotoxy(b,i);printf("\xba");
}
gotoxy(a,c);printf("\xc9");
gotoxy(a,d);printf("\xc8");
gotoxy(b,c);printf("\xbb");
gotoxy(b,d);printf("\xbc");
//textbackground(11);
//textcolor(0);
}