In: Electrical Engineering
Write a program that reads in characters until end of file. The program should count and print the number of characters, printable characters, vowels, digits, and consonants in the input. Use functions to check whether a character is a vowel, a consonant, or a printable character. Define and use macros to test if a character is a digit or a letter.
close all,
clear all,
clc,
ProjectPath = pwd;
DocPath = strcat(ProjectPath,'\SampleText.txt');
fid=fopen(DocPath,'r');
Text=textread(DocPath,'%s');
fclose (fid);
[row col] = size(Text);
tempCharArray=[];
N=1;
for r=1:row
tempCharArray = [tempCharArray Text{r},' '];
end
CharArray=[];
Count_A=0;
Count_E=0;
Count_I=0;
Count_O=0;
Count_U=0;
Count_a=0;
Count_e=0;
Count_i=0;
Count_o=0;
Count_u=0;
Count_Numerals=0;
Count_Spaces=0;
for r=1:length(tempCharArray)-1
CharArray(r) = tempCharArray(r);
if(CharArray(r) == 'A'), Count_A = Count_A+1; end
if(CharArray(r) == 'E'), Count_E = Count_E+1; end
if(CharArray(r) == 'I'), Count_I = Count_I+1; end
if(CharArray(r) == 'O'), Count_O = Count_O+1; end
if(CharArray(r) == 'U'), Count_U = Count_U+1; end
if(CharArray(r) == 'a'), Count_a = Count_a+1; end
if(CharArray(r) == 'e'), Count_e = Count_e+1; end
if(CharArray(r) == 'i'), Count_i = Count_i+1; end
if(CharArray(r) == 'o'), Count_o = Count_o+1; end
if(CharArray(r) == 'u'), Count_u = Count_u+1; end
if(CharArray(r) >= 48 && CharArray(r) <= 57), Count_Numerals = Count_Numerals+1; end
if(CharArray(r) == 32), Count_Spaces = Count_Spaces+1;end
end
tempCharArray
Count_A
Count_E
Count_I
Count_O
Count_U
Count_a
Count_e
Count_i
Count_o
Count_u
Count_Numerals
Count_Spaces