I cannot produce the "other" to form the correct output. The "@" Should read as a other but doesnt and I'm having trouble with making my program read in from a data file.
Develop a program that will read in a text file named "text.data" and produce the following reports as it appears, where xx refers an actual number based on the text data. Please follow the definitions in the glossary section given at the end.
Report:
Text Data: (Content of the text file)
Number of characters: xx
---> Number of letters: xx
--- > Number of upper cases: xx
---> Number of lower cases: xx
---> Number of digits: xx
---> Number of punctuation characters: xx
---> Number of special characters (any character other than a letter, a digit, punctuation character, or a space): xx
---> Number of spaces: xx
Number of words: xx
Number of numbers: xx
Number of others (any group of characters other than a word, or a number): xx
Glossary:
Punctuation characters: (,) ( ;) (.) (:) (!) (?) (") (/) (\) (-) (+)
Word: A group of letters ONLY, separated by a punctuation character or a space.
Number: A group of digits ONLY.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include<stdio.h>
#include<iostream>
#include<iterator>
using namespace std;
main()
{
int others = 0, numbers = 0, countWords = 0, space = 0, punct = 0, character = 0, letters = 0,upper = 0, lower = 0, digit=0, special=0;
char ch[80];
int i;
printf("\nEnter The String : ");
gets(ch);
for (i = 0; ch[i]!='\0';i++)
{
if (ch[i] != ' ')
character++;
if (ch[i] >= 'a' && ch[i] <= 'z' && ch[i] >= 'A' && ch[i] >= 'Z' && ch[i] != ' ') // Checking for spaces
letters++;
if (ch[i] >= 'A' && ch[i] <= 'Z')
upper++;
else if (ch[i] >= 'a' && ch[i] <= 'z')
lower++;
else if(ch[i] >='0' && ch[i] <='9')
digit++;
else if (ch[i] != ',' && ch[i] !=';' && ch[i] != '!' && ch[i] != ' ' && ch[i] != '.' && ch[i] != ':' && ch[i] != '?' && ch[i] != '"' && ch[i] != '-' && ch[i] != '+' && ch[i] != '/')
special++;
else if(ch[i]!=' ')
punct++;
else if (ch[i] == ' ')
space++;
else if (digit >='0' && ch[i] !='9')
numbers++;
else if (ch[i] != '@'&& ch[i] != '#' && ch[i] != '$' && ch[i] != '%' && ch[i] != '^' && ch[i] != '*' && ch[i] != '(' && ch[i] != ')' && ch[i] != '_' && ch[i] != '+' && ch[i] != '{' && ch[i] !='}' && ch[i] != '<' && ch[i] != '>' && ch[i] !='~' && ch[i] != '`')
others++;
}
printf ("\nNnumber of characters: %d", character);
printf ("\nNnumber of letters: %d", upper + lower);
printf ("\nNumber of Uppercase Letters: %d", upper);
printf ("\nNumber of Lowercase Letters: %d", lower);
printf ("\nNumber of Digits: %d", digit);
printf ("\nThe number of special characters: %d", special);
printf ("\nPunctuation Characters: %d", punct);
printf ("\nNumber of spaces: %d", space);
printf ("\nNumber of words: %d", space +1);
printf ("\nNumber of numbers: %d" , digit / 2 );
printf ("\nNumber of others: %d", others);
}
|
Enter The String : I like to Eat Yams @ moms.
Nnumber of characters: 20
Nnumber of letters: 18
Number of Uppercase Letters: 3
Number of Lowercase Letters: 15
Number of Digits: 0
The number of special characters: 1
Punctuation Characters: 1
Number of spaces: 7
Number of words: 8
Number of numbers: 0
Number of others: 0
--------------------------------
Process exited after 11.02 seconds with return value 0
Press any key to continue . . .
|