Words,Punctuation,Lines & Digits counter in c++

Do you want to make a word counter , a line counter or a program which counts punctuation for you.

It is very easy open your compiler and get started…

Step 1:-

open your compiler and create a new c++ program.


Step 2:-

include following libraries in your program.

// cctypes.cpp — using the ctype.h library
#include <iostream>
#include <cctype> // prototypes for character functions


Step 3:-

Start writing main function and follow the code below & make use of built-in functions of cctype and count when some space punctuation or digit occurs.

following is list of builtin functions of cc type and you can click on any function to get details

 

int main()
{
using namespace std;
cout << “Enter text for analysis, and type @”
” to terminate input.\n”;
char ch;
int whitespace = 0;
int digits = 0;
int chars = 0;
int punct = 0;
int others = 0;
cin.get(ch); // get first character
while(ch != ‘@’) // test for sentinel
{
if(isalpha(ch)) // is it an alphabetic character?
chars++;
else if(isspace(ch)) // is it a whitespace character?
whitespace++;
else if(isdigit(ch)) // is it a digit?
digits++;
else if(ispunct(ch)) // is it punctuation?
punct++;
else
others++;
cin.get(ch); // get next character
}
cout<<“———————————————–“<<endl;
cout<< ” letters = “<< chars <<endl;
cout<< ” whitespace = “<<whitespace << endl;
cout<< ” digits = “<< digits<<endl;
cout<< ” punctuations = “<<punct <<endl;
cout<< ” others = “<<others << endl;
return 0;
}


DOWNLOAD SOURCE CODE

DOWNLOAD MADE

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s