Question:7
Write a function in C++ named count_upper() to read a file named “story.txt”. Count and print total upper case alphabets in the file.
Sol:
/* count total upper case alphabet in the file */
#include<iostream>
#include<fstream>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
void count_upper()
{
ifstream pqr;
char ch;
int a=0;
pqr.open("story.txt");
if (pqr.fail())
{
cout<<"Unable to open the file"<<endl;
exit(1);
}
while(!pqr.eof())
{
pqr.get(ch);
if(ch>='A' && ch<='Z')
a++;
cout.put(ch);
}
pqr.close();
cout<<"total upper case alphabets = "<<a<<endl;
}
int main()
{
/* clrscr(); */
count_upper();
return(0);
}
Question:8
Write a function in c++ named count_digit() to read a file named “article1.txt”. Count and print total digits in the file.
Sol:
/* count total digits in the file */
#include<iostream>
#include<fstream>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
void count_upper()
{
ifstream pqr;
char ch;
int d=0;
pqr.open("article.txt");
if (pqr.fail())
{
cout<<"Unable to open the file"<<endl;
exit(1);
}
while(!pqr.eof())
{
pqr.get(ch);
if(ch>='0' && ch<='9')
d++;
cout.put(ch);
}
pqr.close();
cout<<"total digits = "<<d<<endl;
}
int main()
{
/* clrscr(); */
count_upper();
return(0);
}
Question:9
Write a function in c++ named count_vowel() to read a file named “article.txt”. Count and print total vowels in the file.
Sol:
/* count total vowels in the file */
#include<iostream>
#include<fstream>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
void count_vowels()
{
ifstream pqr;
char ch;
int v=0;
pqr.open("article.txt");
if (pqr.fail())
{
cout<<"Unable to open the file"<<endl;
exit(1);
}
while(!pqr.eof())
{
pqr.get(ch);
if(ch=='a' || ch=='A' || ch=='e' || ch=='E' || ch=='i' ||
ch=='i' || ch=='o' || ch=='O' || ch=='u' || ch=='U')
v++;
cout.put(ch);
}
pqr.close();
cout<<"total vowels = "<<v<<endl;
}
int main()
{
/* clrscr(); */
count_vowels();
return(0);
}




