Showing posts with label Count. Show all posts
Showing posts with label Count. Show all posts

Read Content From a Text File then Count and Display the Number of Alphabets

How to write a C++ Program to read content from a text file out.txt, count and display the number of alphabets present in it in C++ Programming.


C++ Program to read content from a text file out.txt, count and display the number of alphabets present in it
C++ Program to read content from a text file out.txt, count and display the number of alphabets present in it 


Soulution:
//Program to read content from a text file out.txt, count and display the number of alphabets present in it.
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
{
clrscr();

char a;
int count=0;
ifstream ifile("out.txt");
while(!ifile.eof())
{
ifile.get(a);
if((a>=65 && a<=90)||(a>=97&&a<=122))
{
count++;
cout<<a;
}
}
cout<<endl<<"Number of aplhabets in the file out.txt: "<<count;
getch();
}

This C++ Program to read content from a text file out.txt, count and display the number of alphabets present in it in C++ Programming.

C++ Program to count number of words in a text file

How to write Program to count number of words in a text file in C++ Programming.


C++ Program to count number of words in a text file
C++ Program to count number of words in a text file


Solution:
//Program to count number of words in a text file.
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
{
clrscr();

char a[80];
int count=0;
ifstream ifile("out.txt");
while(!ifile.eof())
{
ifile>>a;
count++;
}
cout<<endl<<"Number of words in the file out.txt: "<<count;
getch();
}

.This C++ Program to count number of words in a text file

C++ Program to count number of times for the appearance of word "do".

How to count number of times for the appearance of word "do" in C++ Programming ?

How to count number of times for the appearance of word "do" in C++ Programming ? Program to count number of times for the appearance of word "do".
Count the number of occurrences of a word 

//Program to count number of times for the appearance of word "do".

#include<fstream.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
void main()
{
clrscr();
int count=0;
char a[10];

ofstream ofile("file.txt");
ofile<<"do re me fa so la ti do do re me fa so la ti do do re me fa so la ti do";
ofile.close();

ifstream ifile("file.txt");
while(!ifile.eof())
{
ifile>>a;
if(strcmp(a,"do")==0)
count++;
}
cout<<count;
getch();
}

This C++ Program is: To count number of times for the appearance of word "do".