Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a C++ program that when given the file (via Linux redirection) will do th

ID: 3730188 • Letter: D

Question

Design a C++ program that when given the file (via Linux redirection) will do the following display your name, lecture and lab section #s and assignment # to the screen count the number of non-whitespace characters found in the file (before words are reformatted) count the number of vowels (upper and lower case) found in the file count the number of letters (upper and lower case) found in the file count the number of digits found in the file for each "word" read, convert all letters to lower case remove any leading characters that are not letters or digits remove any trailing characters that are not letters or digits display the formatted words (to the screen) in 4 columns (left justified) determine the longest words in the file (before the leading/trailing characters have been removed and after) compute the average length of the formatted words (after the leading/trailing characters have been removed) display the counts, the longest words, and the average length of the formatted words with labels (do not set precision for average, leave at least one blank line between end of table and start of counts) REQUIREMENTS The program MUST make use of functions to solve the problem. Identify subtasks and use functions to implement them. Minimum of 3 meaningful functions (in addition to main). Arrays and/or vectors and/or structs and/or classes CANNOT be used in this program. DO NOT use global variables. DO NOT use goto statements. Assumptions/Definitions a "word" is any series of consecutive non-whitespace characters sample words before reformatting: world, (2008) %#we're non-whitespace<+!> <{([r2d2])}>!!! each word in the file will contain at least one letter or one digit after the word is reformatted it must start and end with a letter or digit sample reformatted words: world 2008 we're non-whitespace r2d2 the "words" in the file will be separated by at least one blank space each line in the file, including the last line of the file, will be terminated by a linefeed the following letters will be considered vowels: A, E, I, O, U, a, e, i, o, u maximum length of a word to be displayed will be 15 characters the longest words in the file (both before and after formatting) will be unique the input file will not be empty

Explanation / Answer

#include <stdio.h>
void main(int argc,char *argv[])
{

FILE *fp1;
int vowel=0,consonant=0;
int upper = 0, lower = 0, number = 0, special = 0;
char ch;
clrscr();
if(argc!=2)
{
cout<<"Insufficient Arguments";
exit(0);
}
fp1=fopen(argv[1],"r");
if(fp1==NULL)
{
Cout<<"Source can't be opened";
exit(0);
}
ch=fgetc(fp1);
while(ch!=EOF)
{
if (ch>= 'A' && ch <= 'Z')

upper++;

else if (ch>= 'a' && ch<= 'z')

lower++;

else if (ch>= '0' && ch<= '9')

number++;

else

special++;

}
if((ch=='a')||(ch=='A')||(ch=='e')||(ch=='E')||(ch=='i')||(ch=='I')||(ch=='o') ||(ch=='O')||(ch=='u')||(ch=='U'))
{
vowel++;
}
else
{
consonant++;
}
ch=fgetc(fp1);
}
cout << "Upper case letters: " << upper << endl;

cout << "Lower case letters : " << lower << endl;

cout << "Number : " << number << endl;

cout << "Special characters : " << special << endl;
cout<<" Number of vowels are "<<vowel;
cout<<" Number of consonant are"<<consonant;
getch();
}