#include<stdio.h>
#include<stdlib.h>
#define size 20
void loading(void);
void extra(void);
int i,ii,j,k,l;//COUNTER VARIABLES
int RN1,RN2,len,index;//RANDOM NUMBERS,LENGTH of NAME & INDEX of LETTER ENTERED
char ch,chr,name[size],correct[size]="-------------------",wrong[2*size]="---------------------------------------";
char crct[size],wrng[2*size],a,b;
char Boy_Name[180][size]= {
"Abbas","Ali","Abid","Abrar","Adeel","Adil","Afzal","Afzaal","Ahmed","Kamran",
"Abdullah","Ahmer","Ahsan","Ajmal","Akbar","Akhtar","Akram","Aqeel","Aqib","Aleem",
"Shahid","Altaf","Amin","Amir","Amjad","Anwar","Arif","Arsalan","Arshad","Asad",
"Fawad","Asim","Aslam","Ayaaz","Ayub","Azam","Azeem","Azhar","Aziz","Babar",
"Hashaam","Bashir","Danial","Danish","Dawood","Ehtisham","Fahad","Faisal","Faiz","Farid",
"Farrukh","Fawad","Fayaz","Fazal","Hasan","Hussain","Habib","Hafeez","Haider","Hamid",
"Hameed","Haroon","Harris","Humayun","Ibrahim","Idrees","Iftikhar","Ijaz","Ilyas","Imran",
"Inzamam","Iqbal","Irfan","Ishaq","Ismail","Jabbar","Jafar","Jalal","Jaleel","Jamal",
"Jameel","Junaid","Javaid","Jawad","Kabir","Kaleem","Karim","Khalid","Latif","",
"Mohammad","Mahmood","Majid","Mohsin","Mubashar","Mudassar","Munawar","Murtaza","Musharraf","Mustafa",
"Muzaffar","Nabeel","Nadeem","Naeem","Nasir","Naseer","Noman","Naveed","Nawaz","Khaliq",
"Qadir","Qaiser","Qasim","Raza","Rahim","Rahman","Rameez","Rashid","Rauf","Razzaq",
"Riaz","Rizwan","Saad","Sabir","Sadaqat","Saeed","Saif","Sajid","Saqib","Salim",
"Khawar","Araib","Salman","Shabbir","Sarfraz","Shafiq","Shahid","Shahzad","Shan","Sheharyar",
"Sheraz","Shoaib","Shuja","Sohaib","Sohail","Adnan","Tahir","Taimoor","Tanvir","Tariq",
"Umair","Umar","Usman","Uzair","Waheed","Wajid","Waqar","Wasi","Wasim","Yahya",
"Yasir","Younis","Yousaf","Zafar","Zaheer","Zahid","Zain","Zaman","Zameer","Zeeshan",
"Zia","Zohaib","Zubair","Badar","Farooq","Rehman","Waqas","Tabassum","Tasawar","Tayyab"
};
char Girl_Name[180][size]={
"Abida","Adeela","Afreen","Afsheen","Aisha","Alina","Amina","Ammara","Ambreen","Arfa",
"Arzoo","Asma","Atiqa","Azra","Batool","Beenish","Benazir","Bina","Bushra","Fakhra",
"Farah","Fareeha","Farida","Farzana","Fatima","Firdous","Ghazala","Hajira","Iffat","Irum",
"Javeria","Kausar","Khadija","Kulsoom","Laila","Lubna","Madeeha","Maimoona","Maleeha","Mariam",
"Mehek","Momina","Nadira","Nadia","Nafeesa","Nargis","Pakeeza","Parveen","Neelofar","Andaleeb",
"Hania","Hadia","Hafsa","Hira","Hareem","Tehreem","Rabia","Raeesa","Raheela","Rashida",
"Ruqaya","Saba","Sabiha","Sadia","Sabahat","Sabeen","Sehar","Saima","Sajida","Sakina",
"Salma","Sameera","Sana","Sanober","Sara","Seema","Shabana","Shabnam","Shagufta","Shaista",
"Shakeela","Shamim","Sharmeen","Zoha","Shazia","Shumaila","Sobia","Somaiya","Surayya","Shanza",
"Sheeza","Tabassum","Tahira","Nasira","Taskeen","Tasneem","Tasawar","Ulfat","Umaira","Uzma",
"Zunaira","Zahida","Shahida","Yasmeen","Zainub","Zarqa","Zuhra","Zulekha","Aneeqa","Shama",
"Aalia","Hifza","Aiman","Fazeela","Habiba","Kiran","Aafia","Maleeha","Balqees","Abiha",
"Arifa","Ambar","Atiya","Warda","Naseem","Sidra","Fozia","Muntaha","Zobia","Saudia",
"Sofia","Huma","Hina","Sumaira","Rehana","Fajar","Noor","Aiza","Tooba","Resham",
"Mehwish","Juggan","Iman","Hadiqa","Umaima","Sarwat","Fiza","Mehreen","Tania","Anam",
"Neelum","Maheen","Iraj","Maham","Gia","Saira","Faiza","Haya","Maria","Meera",
"Sunbal","Minahil","Natasha","Nosheen","Rubab","Sonia","Zeba","Zara","Deeba","Farwa",
"Faryal","Fareeha","Mahira","Mahnoor","Maya","Naheed","Nimra","Nirma","Rahat","Sanam"
};
void main()
{
clrscr();
gotoxy(32,1);
printf("INSTRUCTIONS:\n\nIn this game, computer will choose a name from a list of names of PAKISTANI boys& girls.\nIt will tell you whether the name chosen is of a BOY or a GIRL and it will");
printf(" also tell you that how many LETTERS are there in the NAME. It will draw two lines as:----\t(TOTAL NUMBER of LETTERS in NAME)\n--------\t(NUMBER of WRONG characters you can enter)\nwhich");
printf(" shows that the name chosen consists of 4 LETTERS & you have 8 chances to\nguess the CORRECT LETTERS (i.e. TWICE the LENGTH of NAME).\nThen you will have to START guessing LETTERS");
printf(" by entering LETTERS. FOR EXAMPLE:\tIf the choosen name is \"ABRAR\" and you guessed \"a\", the computer will put it as:a--a-\n----------\nwhich shows that the letter guessed is PRESENT in");
printf(" the name at FIRST & FOURTH\nPLACE. NEXT, if you guess \"s\", computer will put it as:\na--a-\ns---------\nwhich shows that the letter guessed is NOT PRESENT in the name. AND SO ON.\nIf the UPPER line fills");
printf(" before the LOWER line,it means that you have\nSUCCESSFULLY guessed the name. \nIf the LOWER line fills BEFORE the UPPER line, it means that you have FAILED to guess the name. \n\nIf you");
printf(" want to PLAY, press \"Y\". OTHERWISE, press \"N\" to QUIT. ");
ch=getch();
//if user wants to play the game.
returnc:i=0;
if(ch=='Y' || ch== 'y')
{
loading();
strcpy(crct,correct);//copies CORRECT string to CRCT string.
strcpy(wrng,wrong);//copies WRONG string to WRNG string.
randomize();
RN1=random(2);//1st random number.
RN2=random(180);//2nd random number.
//check if the name to be choosen is of a BOY or a GIRL & assign the choosen name to string NAME.
if(RN1==0)
{
printf("You Have to Guess the Name of a BOY");
for(ii=0;ii<size;ii++)
{
name[ii]=Boy_Name[RN2][ii];
if(Boy_Name[RN2][ii]=='\0')
break;
}
}
else if(RN1==1)
{
printf("You Have to Guess the Name of a GIRL");
for(ii=0;ii<size;ii++)
{
name[ii]=Girl_Name[RN2][ii];
if(Girl_Name[RN2][ii]=='\0')
break;
}
}
//check LENGTH of NAME choosen.
len=strlen(name);
printf("\n\nNAME consists of %d CHARACTERS\n\n",len);
printf("You have %d chances to guess the correct name\n\n",2*len);
//print the strings CRCT and WRNG.
for(ii=0;ii<len;ii++)
printf("%c",crct[ii]);
printf("\n");
for(ii=0;ii<2*len;ii++)
printf("%c",wrng[ii]);
input1: for(i=i;;)
{
input: if(i<=2*len)
{
index=-1;
a=b='y';
printf("\n\n%d chances left",2*len-i);
printf("\n\nEnter Character ");
}
chr=getche();
printf("\n");
//checks whether the entered character exists in the name or not.
for(j=0;j<len;j++)
if(chr==name[j] || chr==name[j]-32 || chr-32==name[j])
{
index=j;
crct[index]=chr;
}
if(index!=-1)
{
for(j=0;j<len;j++)
if(crct[j]=='-')
a='n';
if(a=='n')
{
extra();
goto input1;
}
else
{
extra();
gotoxy(28,13);
printf("CONGRATULATIONS! YOU WON");
gotoxy(17,15);
printf("Press 'y' to PLAY AGAIN or press 'n' to QUIT ");
ch=getch();
goto returnc;
}
}
if(index==-1)
{
if(i==2*len)
goto exit;
else
for(l=0;l<=2*len;l++)
if(wrng[l]=='-')
{
wrng[l]=chr;
goto print;
}
}
//prints the new strings.
print:clrscr();
for(k=0;k<len;k++)
printf("%c",crct[k]);
printf("\n\n");
for(k=0;k<2*len;k++)
printf("%c",wrng[k]);
//Check whether the LOWER line is filled or not. If not, put 'b=n' & take input again until last chance.
for(j=0;j<=2*len;j++)
if(wrng[j]=='-')
b='n';
if(b=='n')
{
i++;
goto input;
}
else if(b=='y')
{
i++;
goto input;
}
exit: clrscr();
gotoxy(34,11);
printf("SORRY! YOU LOST");
gotoxy(20,13);
printf("The Name that was choosen is \"%s\"",name);
gotoxy(17,15);
printf("Press 'y' to PLAY AGAIN or press 'n' to QUIT ");
ch=getch();
goto returnc;
}
}
//if user don't want to play the game.
else if(ch=='N' || ch=='n')
{
clrscr();
gotoxy(31,12);
printf("GOOD BYE...TAKE CARE");
}
//if user enters the wrong input i.e. else than 'y' or 'n'.
else
{
clrscr();
gotoxy(24,12);
printf("Press \"Y\" to PLAY & \"N\" to QUIT ");
ch=getch();
goto returnc;
}
getch();
}
void extra()
{
clrscr();
for(k=0;k<len;k++)
printf("%c",crct[k]);
printf("\n\n");
for(k=0;k<2*len;k++)
printf("%c",wrng[k]);
}
void loading(void)
{
int z;
for(z=5;z>=1;z--)
{
clrscr();
gotoxy(36,10);
printf("LOADING . . .");
gotoxy(31,12);
printf("%d Seconds Remaining",z);
delay(1000);
}
clrscr();
}
Monday, 21 August 2017
Related Posts:
Extend the employee class of Exercise 4 to include a date class (see Exercise 5) and an etype enum (see Exercise 6 in Chapter 4). An object of the date class should be used to hold the date of first employment; that is, the date when the employee was hired. The etype variable should hold the employee’s type:{ laborer, secretary, manager, accountant, executive, researcher }. These two items will be private member data in the employee definition, just like the employee number and salary. You’ll need to extend the getemploy() and putemploy() functions to obtain this new information from the user and display it. These functions will probably need switch statements to handle the etype variable. Write a main() program that allows the user to enter data for th v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);… Read More
Create an employee class. The member data should comprise an int for storing the employee number and a float for storing the employee’s compensation. Member functions should allow the user to enter this data and display it. v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);… Read More
In ocean navigation, locations are measured in degrees and minutes of latitude and longitude. Thus if you’re lying off the mouth of Papeete Harbor in Tahiti, your location is 149 degrees 34.8 minutes west longitude, and 17 degrees 31.5 minutes south latitude. This is written as 149°34.8’ W, 17°31.5’ S. There are 60 minutes in a degree. (An older system also divided a minute into 60 seconds, but the modern approach is to use decimal minutes instead.) Longitude is measured from 0 to 180 degrees, east or west from Greenwich, England, to the international dateline in the Pacific. Latitude is measured from 0 to 90 degrees, north or south from the equator to the poles. v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);… Read More
Create a class date. Its member data should consist of three ints: month, day, and year. It should also have two member functions: getdate(), which allows the user to enter a date in 12/31/02 format, and showdate(), which displays the date. v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);… Read More
0 comments: