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...
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 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 a program that reads a file called document.txt which is a text file containing an...
Write a program that reads a file called document.txt which is a text file containing an excerpt from a novel. Your program should print out every word in the file that contains a capital letter on a new line to the stdout. For example: assuming document.txt contains the text C++
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...
MARS: Use MASKING to convert ASCII characters to Integer Write and run a program that reads...
MARS: Use MASKING to convert ASCII characters to Integer Write and run a program that reads in a string of ASCII characters and converts them to Integer numbers stored in an array USING MASKING, not subtraction. Write a program that: 1. Inputs a 1x8 vector of single-digit integers 2. Stores them into an 8-entry 32-bit Integer array, “V”. After storing the integers in the array: 1. Read the same values using Read Integer and store them in a 32-bit integer...
IN C++ Write a program that reads in int values from the user until they enter...
IN C++ Write a program that reads in int values from the user until they enter a negative number like -1. Once the user has finished entering numbers, print out the highest value they’ve entered, the lowest value they’ve entered, and the total number of numbers they’ve entered. The negative number they entered should not be taken as one of the values entered.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT