Question

In: Electrical Engineering

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

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.

Solutions

Expert Solution

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


Related Solutions

Write a C++ program that reads integers from standard input until end of file. Print out...
Write a C++ program that reads integers from standard input until end of file. Print out the largest integer that you read in, on a line by itself. Any erroneous input (something that is not an integer) should be detected and ignored. In the case where no integers are provided at all, print NO INTEGERS and stop. The whole program is under 40 lines of code. Just read from cin. Now, you need to detect non integers. In this case,...
Write a C++ program that reads integers from standard input until end of file. Print out...
Write a C++ program that reads integers from standard input until end of file. Print out the largest integer that you read in, on a line by itself. Any erroneous input (something that is not an integer) should be detected and ignored. In the case where no integers are provided at all, print NO INTEGERS and stop. Remember, try not to do the entire job all at once! First try input of a single number and make sure it works....
Write a C++ program that reads integers from standard input until end of file. Print out...
Write a C++ program that reads integers from standard input until end of file. Print out the largest integer that you read in, on a line by itself. Any erroneous input (something that is not an integer) should be detected and ignored. In the case where no integers are provided at all, print NO INTEGERS and stop Remember, try not to do the entire job all at once! First try input of a single number and make sure it works....
Write a C program that reads a file and reports how many lines, words, and characters...
Write a C program that reads a file and reports how many lines, words, and characters appear in it. For the purpose of this program, a word consists of a consecutive sequence of any characters except white space characters. For example, if the file lear.txt contains the following passage from King Lear, Poor naked wretches, wheresoe’er you are, That bide the pelting of this pitiless storm, How shall your houseless haeds and unfed sides, Your loop’d and window’d raggedness, defend...
Write a program FileCounter.java that reads a text file text1.txt and reports the number of characters...
Write a program FileCounter.java that reads a text file text1.txt and reports the number of characters and lines contained in the file. For example, the output should be as follows: Lines: 5 Chars: 124 Note: Write a main() method to test in the FileCounter.java. The file path should use relative path. Must use the provided text file text1.txt. The text file say This is an example 1 This is an example 1 2. This is an example 1 2 3....
Write a program which reads an input file. It should assume that all values in the...
Write a program which reads an input file. It should assume that all values in the input file are integers written in decimal. Your program should read all integers from the file and print their sum, maximum value, minimum value, and average. Use the FileClient class here (from a previous reading) as an example. You'll need to create a file to be used as input to test your program, as well. Your program should work whether the integers are separated...
In Java: Write a program that will count the number of characters, words, and lines in...
In Java: Write a program that will count the number of characters, words, and lines in a file. Words are separated by whitespace characters. The file name should be passed as a command-line argument, as shown below. c:\exercise>java Exercise12_13 Loan.java File loan.java has 1919 characters 210 words 71 lines c:\exercise> Class Name: Exercise12_13
C++ Write a program that prompts for a file name and then reads the file to...
C++ Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid. Display the line number the error occurred on. These are a few of the...
Write a program that reads a file (provided as attachment to this assignment) and write the...
Write a program that reads a file (provided as attachment to this assignment) and write the file to a different file with line numbers inserted at the beginning of each line. Such as Example File Input: This is a test Example File Output 1. This is a test. (Please comment and document your code and take your time no rush).
Write a program that reads a file line by line, and reads each line’s tokens to...
Write a program that reads a file line by line, and reads each line’s tokens to create a Student object that gets inserted into an ArrayList that holds Student objects.  Each line from the file to read will contain two strings for first and last name, and three floats for three test grades.  After reading the file and filling the ArrayList with Student objects, sort the ArrayList and output the contents of the ArrayList so that the students with the highest average...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT