Data files will be provided fortesting, ranging from 3K to 260K. i.e. leaf.dat (
ID: 3610971 • Letter: D
Question
Data files will be provided fortesting, ranging from 3K to 260K. i.e. leaf.dat (leaf and stemdata file) Part 6 Write a program to find and output theindicated characters from your text file to the screen using asuitable format. Character types to count: 1. Upper-caseletters 2. Lower-caseletters 3. Digits 4. Punctuation usingispunct(char) 5. Other - not one of thetypes above Part 7 Modify your program from Part 6 to count theoccurrence of each type of character in your text file and outputthe character and its count. Part 8 Write a program to read each line of your textfile, count the number of "words" in each line, and at the end ofthe file, output the total number of words, the maximum number ofwords in one line, and the average number of words per line. Youwill define what a "word" is. Data files will be provided fortesting, ranging from 3K to 260K. i.e. leaf.dat (leaf and stemdata file) Part 6 Write a program to find and output theindicated characters from your text file to the screen using asuitable format. Character types to count: 1. Upper-caseletters 2. Lower-caseletters 3. Digits 4. Punctuation usingispunct(char) 5. Other - not one of thetypes above Part 7 Modify your program from Part 6 to count theoccurrence of each type of character in your text file and outputthe character and its count. Part 8 Write a program to read each line of your textfile, count the number of "words" in each line, and at the end ofthe file, output the total number of words, the maximum number ofwords in one line, and the average number of words per line. Youwill define what a "word" is.Explanation / Answer
#include<iostream.h>
#include <string>
#include <fstream.h>
using namespace std;
bool isupper(char);
bool islower(char);
bool isdigit(char);
int main()
{
int upper=0,i,lower=0,digit=0,other=0,punct=0;
bool up,low,dig,pun;
string input;
ifstream in;
in.open("input.txt"); //open file
if(in.fail()) //is it ok?
{ cout<<"file did notopen please check it ";
system("pause");
return 1;
}
getline(in,input);
while(in)
{for(i=0;i<input.length();i++)
{up=low=dig=false;
if(isupper(input[i]))
{upper++;
up=true;
}
if(islower(input[i]))
{lower++;
low=true;
}
if(isdigit(input[i]))
{digit++;
dig=true;
}
if(ispunct(input[i]))
{punct++;
pun=true;
}
if(!(pun||dig||low||up))
other++;
}
getline(in,input);
}
cout<<"Upper case letters: "<<upper<<endl;
cout<<"Lower letters: "<<lower<<endl;
cout<<"Digits: "<<digit<<endl;
cout<<"Punctuation: "<<punct<<endl;
cout<<"Other: "<<other<<endl;
in.close();
system("pause");
return 0;
}
bool isupper(char c)
{if(c>='A'&&c<='Z')
return true;
else
return false;
}
bool islower(char c)
{if(c>='a'&&c<='z')
return true;
else
return false;
}
bool isdigit(char c)
{if(c>='0'&&c<='9')
return true;
else
return false;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.