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)...
Create a text file called “Trivia.txt” that contains the contents of a trivia game, where the...
Create a text file called “Trivia.txt” that contains the contents of a trivia game, where the questions and answers are on separate lines. Example: How many players are on a Baseball team? Nine What is the name of Batmans butler? Alfred Hg is the chemical symbol for what element? Mercury Create a program that reads the trivia questions from this text file, prints them out to netbeans and asks the user to input an answer. Compare the users answer to...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
Code a C file, following these instructions: This lab is about getting the input from a...
Code a C file, following these instructions: This lab is about getting the input from a file. Let’s assume the words are provided in one file, passed as an argument to your program. The names of the files are provided as arguments to your program (i.e., they are copied by the shell in the argv variable), and each file is a text file with lots of words. Open the manual page for open() system call and add to your code...
How would I go about answering these questions In linux. Please provide the correct linux command...
How would I go about answering these questions In linux. Please provide the correct linux command needed to answer these 4 questions 5. Display total words of each file under your root directory and subdirectories. 6. Change permission of every filename ends “.py” to — write read execute, group - read execute, other - execute 7. Find every line which contains “hello” from your file system, display both file name, line number. 8. Combine files with name “p3.py”, “p31.py”, “p32.py”,...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you will demonstrate how to create an HTML file, externally link a JavaScript file, and write some source code in the JavaScript file. a..Create two blank files to be an HTML file and a JavaScript file. The file names should be partA.html and partA.js. b.. Create a basic HTML webpage structure. c..Link the JavaScript file to the HTML file using the <script> tag. d.. Prompt...
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,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT