Question
1.Declare the variables. 2. Open the input and output files. 3. Initialize the variables. 4. While there is more data in the input file: For
1.Declare the variables.
2. Open the input and output files.
3. Initialize the variables.
4. While there is more data in the input file:
For each character in a line:
a) Read and write the character.
b) Increment the characters count.
c) Increment the appropriate letter count.
d) Increment the line count.
5. Sort the array that holds the letter counts.
6. Get the five most used letters and the number of occurrence of these letters.
7. Get the letters that were not used in the message
8. Output the message to the screen and the output file.
9. Output line count, characters, and letter counts to the screen and the output file.
10. Output five most used letters and the number of occurrences to the screen and the output file.
11. Output the letters that were not used in the message to the screen and the output file.
12. Close the files.
//************************************************************* // Author: D.S. Malik // // Program: Line and Letter Count // This programs reads a text, outputs the text as is, and also // prints the number of lines and the number of times each // letter appears in the text. An uppercase letter and a // lowercase letter are treated as being the same; that is, // they are tallied together. //*************************************************************
#include #include #include
using namespace std;
void initialize(int& lc, int list[]); void copyText(ifstream& intext, ofstream& outtext, char& ch,int list[]); void characterCount(char ch, int list[]); void writeTotal(ofstream& outtext, int lc, int list[]);
int main() { //Step 1; Declare variables int lineCount; int letterCount[26]; char ch; ifstream infile; ofstream outfile;
infile.open("textin.txt"); //Step 2
if (!infile) //Step 3 { cout
outfile.open("textout.out"); //Step 4
initialize(lineCount, letterCount); //Step 5
infile.get(ch); //Step 6
while (infile) //Step 7 { copyText(infile, outfile, ch, letterCount); //Step 7.1 lineCount++; //Step 7.2 infile.get(ch); //Step 7.3 }
writeTotal(outfile, lineCount, letterCount); //Step 8
infile.close(); //Step 9 outfile.close(); //Step 9
return 0; }
void initialize(int& lc, int list[]) { lc = 0;
for (int j = 0; j
void copyText(ifstream& intext, ofstream& outtext, char& ch, int list[]) { while (ch != ' ') //process the entire line { outtext
characterCount(ch, list); //call the function //character count intext.get(ch); //read the next character } outtext
void characterCount(char ch, int list[]) { int index;
ch = toupper(ch); //Step a
index = static_cast(ch) - static_cast('A'); //Step b
if (0
void writeTotal(ofstream& outtext, int lc, int list[]) { int index;
outtext
for (index = 0; index
Project Three: Message Analyzer Enter file nane: textin.txt Message Report Name : textin.txt outPut textin.txt Input File Name: * Output File Name: Original Message Contents The first device known to carry out calculations was the bacus. The abacus was invented in Asia but vas used in ancient Babylon. China, and throughout Europe until the late middle ages. The abacus uses a system of slidin beads in a rack for addition and subtraction In 1642 the French philosopher and mathenatician Blaise Pascal invented the calculating device called the Pascaline It had eight novable dials on wheels and could calculate suns up to eight figures long. Both the abacus and Pascaline could perform only addition and subtraction operations Later in the 17th centur Gottfried von Leibniz invented a device that was ble to add. subtract. multiply, and divide. Number of lines Number of chars 13 551 * Five Hogt Used Characte 'A 62 counted E 54 counted T 51 counted I45 counted 'N' 43 counted *Characters Not Used q. J. haracter Occurence count= 62 B count- 16 C count- 29 D count= G count= 9 H count= 24 1 count= 45 J countK count2L count30 M count= 8 N count= 43 0 count= 30 P count= 10 Q count= 0 R count= 19 S count = 33 T count= 51 U count= 25 U count9Wcount 6X count0 Y count= 6 Z count- 1 32 E count= 54 F cou nt= ? Process returned 0 0x0) execut ion time : 7.646 s ress any key to continueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started