Question

Please provide commenting of code so I can understand how to solve this problem. Please provide...

Please provide commenting of code so I can understand how to solve this problem. Please provide text files. Using C++ Write a program that reads a given file, and then outputs the contents of it to another file. It should also print out the number of lines and the number of times each alphabetic character appears (regardless of case) in the input file at the end of the output file. It should prompt the user for the input and output file names. For example, if the input file contains: This is just a test. Some more text is needed. Then the output file should contain: This is just a test. Some more text is needed. The number of lines in the input file is 3. A appears 1 times. D appears 2 times. E appears 6 times. I appears 3 times. M appears 1 times. N appears 1 times. O appears 2 times. R appears 1 times. S appears 6 times. T appears 6 times. U appears 1 times. X appears 1 times.

Homework Answers

Answer #1

CODE:

#include<iostream>
#include<fstream>
#include<string>

using namespace std;


int main(){
fstream fileIn,fileOut;
//num stores the number of line
int num = 0;
string filename,line;
string *lines = new string[100];
//opening the input file
cout<<"Enter input filename: "<<endl;
cin>>filename;
fileIn.open(filename.c_str(),ios::in);
//opening the output file
cout<<"Enter output filename: "<<endl;
cin>>filename;
fileOut.open(filename.c_str(),ios::out);

//getting the lines from a file and storing in an array
while(getline(fileIn,line)){
lines[num] = line;
fileOut<<line<<endl;;
num += 1;
}
//array to store the frequency of each alphabet
int *freq = new int[26];
for(int i=0;i<26;i++)
freq[i] = 0;
//counting the number of characters
for(int i=0;i<num;i++){
for(int j=0;j<lines[i].length();j++){
if(int(lines[i].at(j)) > 64 && int(lines[i].at(j)) < 91)
freq[int(lines[i].at(j))-65] += 1;
if(int(lines[i].at(j)) > 96 && int(lines[i].at(j)) < 123)
freq[int(lines[i].at(j))-97] += 1;
}
}
//writing the number of lines in the file
fileOut<<"Number of lines in the file is "<<num<<"."<<endl;
//printing the frequency of each character in the file
for(int i =0;i<26;i++){
if(freq[i] != 0){
fileOut<<char(i+65)<<" appears "<<freq[i]<<" times."<<endl;
}
}
//closing the files
fileIn.close();
fileOut.close();
cout<<"Files written!"<<endl;
return 0;
}
________________________________________

CODE IMAGES:

_________________________________________________

OUTPUT:

output.txt

_____________________________________

input.txt

This is just a test.
Please provide commenting of code so I can understand how to solve this problem.
Please provide text files.
Using C++ Write a program that reads a given file, and then outputs the contents of it to another file.
It should also print out the number of lines and the number of times each alphabetic character appears (regardless of case) in the input file at the end of the output file.
It should prompt the user for the input and output file names.

//input file is just the question you posted..This code will work for any kind of input text.

________________________________________________

Feel free to ask any questions in the comments section

Thank You!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
using matlab please present code for the following (ALL PARTS PLEASE AND THANK YOU) 1. No...
using matlab please present code for the following (ALL PARTS PLEASE AND THANK YOU) 1. No Input/No Output Write a function that has no input and no outputs. This function will simply display some text when it is called. (this is my code, are there suggestions for improvements?) function Display() disp('some text') end 2. 1 Input/No Outputs Write a function with one input and no outputs. This function will simply display a variable that is provided as an input argument....
Please write a program that reads the file you specify and calculates how many times each...
Please write a program that reads the file you specify and calculates how many times each word stored in the file appears. However, ignore non-alphabetic words and convert uppercase letters to lowercase letters. For example, all's, Alls, alls are considered to be the same words. What is the output of the Python program when the input file is specified as "proverbs.txt"? That is, in your answer, include the source codes of your word counter program and its output. <proverbs.txt> All's...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report the total number of words (as an integer) and the average word length (as an un-rounded number). For example, suppose the file tobe.txt contains the following text: To be or not to be, that is the...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
And need to be writing in C++ language Programm need to start with   #include<fstream> Prepare a...
And need to be writing in C++ language Programm need to start with   #include<fstream> Prepare a text file data_in.txt with the following information (highlight the piece of text below with numbers and copy it to a text file): 54, 70, 75, 63, 17, 59, 87, 16, 93, 81, 60, 67, 90, 53, 88, 9, 61, 8, 96, 98, 12, 34, 66, 76, 38, 55, 58, 27, 92, 45, 41, 4, 20, 22, 69, 77, 86, 35, 19, 32, 49, 15,...
(Use Java ) please write comment on every line I need to understand the code Problem...
(Use Java ) please write comment on every line I need to understand the code Problem Description: Write a program that prompts the user to enter a point (x, y) and checks whether the point is within the rectangle centered at (0, 0) with width 10 and height 5. For example, (2, 2) is inside the rectangle and (6, 4) is outside the rectangle, as shown in the Figure. (Hint: A point is in the rectangle if its horizontal distance...
Please provide an explanation and an example with your response so I can understand, interpret and...
Please provide an explanation and an example with your response so I can understand, interpret and learn from it. Describe the risks associated with allowing remote access to internal systems and what security should be in place.
Please provide the work and explanations so that I can understand the problem. Your friend wants...
Please provide the work and explanations so that I can understand the problem. Your friend wants to invest in a portfolio that includes two stocks and the risk free investment. Stock G has a beta of 2.5 and an expected return of 10%, Stock E has a beta of 0.5 and an expected return of 5% and the risk free rate is 2%. Your friend comes to you asking for help in creating a portfolio with an expected return of...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT