Write a program that reads in characters until end of file. The program should count and...

Free

90.2K

Verified Solution

Question

Electrical Engineering

Write a program that reads in characters until end of file. Theprogram should count and print the number of characters, printablecharacters, vowels, digits, and consonants in the input. Usefunctions to check whether a character is a vowel, a consonant, ora printable character. Define and use macros to test if a characteris a digit or a letter.

Answer & Explanation Solved by verified expert
3.8 Ratings (493 Votes)

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


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students