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 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...
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...
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
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...
Write a C program that Reads a text file(any file)  and writes it to a binary file....
Write a C program that Reads a text file(any file)  and writes it to a binary file. Reads the binary file and converts it to a text file.
Write the programs in JavaScript: Write a program that reads a text file and outputs the...
Write the programs in JavaScript: Write a program that reads a text file and outputs the text file with line numbers at the beginning of each line.
Part 1 Write a program that reads a line of input and display the characters between...
Part 1 Write a program that reads a line of input and display the characters between the first two '*' characters. If no two '*' occur, the program should display a message about not finding two * characters. For example, if the user enters: 1abc*D2Efg_#!*345Higkl*mn+op*qr the program should display the following: D2Efg_#! 1) Name your program stars.c. 2) Assume input is no more than 1000 characters. 3) String library functions are NOT allowed in this program. 4) To read a...
Using c++, write a program that reads a sequence of characters from the keyboard (one at...
Using c++, write a program that reads a sequence of characters from the keyboard (one at a time) and creates a string including the distinct characters entered and displays the string on the screen. The input terminates once the user enters a white-space character or the user has entered 50 distinct characters. Do not use C-Strings. 2. Use the following function to append character “ch” to the string “s”: s.push_back(ch); 3. Read the input characters one by one, i.e. do...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT