You are on page 1of 6

DATA FILE HANDLING PRACTICAL

TEST
ROLL NO WITH EVEN SEQ 2,4,6

Write a user-defined function in
C++ to write and read the
content from a text file OUT.TXT,
count and display the number of
alphabets present in it.
ROLL NO WITH ODD SEQ 1,3,5

Write a function to count the
number of blank present in a
text file named "OUT.TXT".
Read and write both function

void alphabets()
{
ifstream fin;
fin.open("out.txt");
char ch;
int count=0;
while(!fin.eof())
{
fin.get(ch);
if(isalpha(ch))
count++;
}
cout<<"Number of alphabets in file are
"<<count;
fin.close();
}
void blankspace()
{
ifstream fin;
fin.open("out.txt");
char ch;
int count=0;
while(!fin.eof())
{
fin.get(ch);
if(ch==' ')
count++;
}
cout<<"Number of blank spaces in file
are "<<count;
fin.close();
}
Write a function in C++ to print
the count of word theas an
independent word in a text file
STORY.TXT.
for example, if the content of the
file STORY.TXT is
There was a monkey in the zoo.
The monkey was very naughty.

Then the ouput of the program
should be 2.
Assuming that a text file named
FIRST.TXT contains some text
written into it, write a function
named copyupper(), that reads
the file FIRST.TXT and creates a
new file named SECOND.TXT
contains all words from the file
FIRST.TXT in uppercase.
void countword()
{
ifstream fin;
fin.open("STORY.TXT");
char word[30];
int count=0;
while(!fin.eof())
{
fin>>word;
if(strcmpi(word,"the")==0)
count++;
}
cout<<"Number of the word in file are
"<<count;
fin.close();
}
void copyupper()
{
ifstream fin;

fin.open("FIRST.TXT");
ofstream fout;
fout.open("SECOND.TXT");
char ch;
while(!fin.eof())
{
fin.get(ch);
ch=toupper(ch);
fout<<ch;
}
fin.close();
fout.close();
}

05-Aug-14 Tuesday Ahmedabad Rabindranath Tagore Hall
Rabindranath Tagore Hall, Opp. Museum, Near Paldi bus stand, Paldi, Ahmedabad

You might also like