Okay so I need help with this c++ code to change it to where it asks the user to enter the file and search. I am going to break the instructions in three parts so you can understand. First, its the book instructions. Then, the what the actual file looks like and the original code.  Book instructions First I want you to modify the program to prompt the user for the name of the file to output. The file that is used in the code Today we live in an era where information is processed almost at the speed of light. Through computers, the technological revolution is drastically changing the way we live and communicate with one another. Terms such as “the Internet,” which was unfamiliar just a few years ago, are very common today. With the help of computers you can send letters to, and receive letters from, loved ones within seconds. You no longer need to send a résumé by mail to apply for a job; in many cases you can simply submit your job application via the Internet. You can watch how stocks perform in real time, and instantly buy and sell them. Students regularly “surf” the Internet and use computers to design their classroom projects. They also use powerful word processing software to complete their term papers. Many people maintain and balance their checkbooks on computers.   The actual code that needs to be changed //************************************************************* // Author: D.S. Malik // // Program: Line and Letter Count // This program 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 characterCount(char ch, int list[]); void copyText(ifstream& intext, ofstream& outtext, 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 << "Cannot open the input file." << endl; return 1; } 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[]) { int j; lc = 0; for (j = 0; j < 26; j++) list[j] = 0; } //end initialize void characterCount(char ch, int list[]) { int index; ch = toupper(ch); //Step a index = static_cast(ch) - static_cast('A'); //Step b if (0 <= index && index < 26) //Step c list[index]++; } //end characterCount void copyText(ifstream& intext, ofstream& outtext, char& ch, int list[]) { while (ch != '\n') //process the entire line { outtext << ch; //output the character characterCount(ch, list); //call the function //character count intext.get(ch); //read the next character } outtext << ch; //output the newline character } //end copyText void writeTotal(ofstream& outtext, int lc, int list[]) { int index; outtext << endl << endl; outtext << "The number of lines = " << lc << endl; for (index = 0; index < 26; index++) outtext << static_cast(index + static_cast('A')) << " count = " << list[index] << endl; } //end writeTotal

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Okay so I need help with this c++ code to change it to where it asks the user to enter the file and search. I am going to break the instructions in three parts so you can understand. First, its the book instructions. Then, the what the actual file looks like and the original code. 

Book instructions

First I want you to modify the program to prompt the user for the name of the file to output.

The file that is used in the code

Today we live in an era where information is processed
almost at the speed of light. Through computers, the
technological revolution is drastically changing the way we
live and communicate with one another. Terms such as
“the Internet,” which was unfamiliar just a few years ago, are
very common today. With the help of computers you can send
letters to, and receive letters from, loved ones within
seconds. You no longer need to send a résumé by mail to apply for a job; in many cases you can simply submit your job
application via the Internet. You can watch how stocks perform in real time, and instantly buy and sell them. Students
regularly “surf” the Internet and use computers to design
their classroom projects. They also use powerful word
processing software to complete their term papers. Many
people maintain and balance their checkbooks on computers.

 

The actual code that needs to be changed

//*************************************************************
// Author: D.S. Malik
//
// Program: Line and Letter Count
// This program 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 characterCount(char ch, int list[]);
void copyText(ifstream& intext, ofstream& outtext, 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 << "Cannot open the input file."
<< endl;
return 1;
}

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[])
{
int j;
lc = 0;

for (j = 0; j < 26; j++)
list[j] = 0;
} //end initialize

void characterCount(char ch, int list[])
{
int index;

ch = toupper(ch); //Step a

index = static_cast(ch)
- static_cast('A'); //Step b

if (0 <= index && index < 26) //Step c
list[index]++;
} //end characterCount

void copyText(ifstream& intext, ofstream& outtext, char& ch,
int list[])
{
while (ch != '\n') //process the entire line
{
outtext << ch; //output the character
characterCount(ch, list); //call the function
//character count
intext.get(ch); //read the next character
}
outtext << ch; //output the newline character
} //end copyText

void writeTotal(ofstream& outtext, int lc, int list[])
{
int index;

outtext << endl << endl;
outtext << "The number of lines = " << lc << endl;

for (index = 0; index < 26; index++)
outtext << static_cast(index + static_cast('A'))
<< " count = " << list[index] << endl;
} //end writeTotal

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education