Question

In: Computer Science

Write a program that reads from the external file input.txt, capitalizes all words that begin with...

Write a program that reads from the external file input.txt, capitalizes all words that begin with the letter "a," and then writes them to an external file output.txt (Note: Do not forget to copy the blanks. You may wish to use infile.get and outfile.put in your program.) Output: After the program generates output.txt, the code should display the contents of the file on the screen to verification.

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

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

using namespace std;

int main(){

   char input_filename[] ="input.txt";
   char output_filename[] ="output.txt";
  
   ifstream infile(input_filename);
   ofstream outfile(output_filename);
  
   if(infile.bad() || outfile.bad() || !infile.is_open() || !outfile.is_open()){
       cout<<"Error: File(s) could not be accessed or opened.\n";
       return 1;
   }
  
   char currChar;
   char prevChar;
   int count = 0;
   while(infile.get(currChar)){
       if(currChar=='a' && (count++==0 || prevChar==' ')){
           outfile.put('A');
       }
       else{
           outfile.put(currChar);
       }
       prevChar = currChar;
   }
   infile.close();
   outfile.close();
  
   cout<<"Output file: "<<output_filename<<" generated successfully.\n";
  

   return 0;
}

===============================================================


Related Solutions

● Write a program that reads words from a text file and displays all the words...
● Write a program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The words must start with a letter. Must use ArrayList. MY CODE IS INCORRECT PLEASE HELP THE TEXT FILE CONTAINS THESE WORDS IN THIS FORMAT: drunk topography microwave accession impressionist cascade payout schooner relationship reprint drunk impressionist schooner THE WORDS MUST BE PRINTED ON THE ECLIPSE CONSOLE BUT PRINTED OUT ON A TEXT FILE IN ALPHABETICAL ASCENDING ORDER...
Write a program that opens the file: "Lab6A_Data", reads all the values from the file, and...
Write a program that opens the file: "Lab6A_Data", reads all the values from the file, and calculates the following: A) The number of values in the file B) The sum of all the values in the file (a running total) C) The average of all the values in the file. D) The minimum value. E) The maximum value. F) The range of the data set of values. G) The number of times the value: '357' occurrs in the file. Display...
Write a C++ pgm which 1.reads an input file named 'input.txt' 2.content of input.txt are not...
Write a C++ pgm which 1.reads an input file named 'input.txt' 2.content of input.txt are not known to you 3.copies content of input file into an output file named 'output.txt' 4.contents of output.txt should be exactly the same as contents of input.txt 5.the user should be given a choice to select input and output file in any folder 6.remember to check that input file opened successfully
4. Write a program that reads all numbers from a file and determines the highest and...
4. Write a program that reads all numbers from a file and determines the highest and lowest numbers. You must NOT use arrays to solve this problem! Write functions where appropriate. Programming language should be C
Write a C++ program that reads a string from a text file and determines if the...
Write a C++ program that reads a string from a text file and determines if the string is a palindrome or not using stacks and queue
Write a Python program called “exam.py”. The input file, “input.txt”, is given to you in the...
Write a Python program called “exam.py”. The input file, “input.txt”, is given to you in the Canvas exam instructions. Name your output file “output.txt”. Ensure the program consists of a main function and at least one other function. Ensure the program will read the input file, and will output the following information to the output file as well as printing it to the screen: output the text of the file to screen output the number of words in the file...
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 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...
How many words are in the Gettysburg Address? Write a program that reads any text file,...
How many words are in the Gettysburg Address? Write a program that reads any text file, counts the number of characters, num- ber of letters and number of words in the file and displays the three counts. To test your program, a text file containing Lincoln’s Gettysburg Address is included on the class moodle page. Sample Run Word, Letter, Character Count Program Enter file name: GettysburgAddress.txt Word Count = 268 Letter Count = 1149 Character Count = 1440 Do 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).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT