Question

Convert the contents of text file to upper case (C++ Programming) Convert the contents of a...

Convert the contents of text file to upper case (C++ Programming)

Convert the contents of a text file to upper case.

Perform the following operations:

  • Read the console input and create a file. ['$' character denotes end of content in file.]
  • Close the file after creation.
  • Now convert the contents of the file to upper case.
  • Display the contents of the updated file.

Input:

    Music is like a dream.
    Without music, life would be a mistake
    I can chase you, and I can catch you, but there is nothing I can do to make you mine.
    Music gives a soul to the universe,
    wings to the mind,
    flight to the imagination and life to everything.

    $

where,

  • '$' character denotes end of content in file.

Output:

    MUSIC IS LIKE A DREAM.

    WITHOUT MUSIC, LIFE WOULD BE A MISTAKE

    I CAN CHASE YOU, AND I CAN CATCH YOU, BUT THERE IS NOTHING I CAN DO TO MAKE YOU MINE.

    MUSIC GIVES A SOUL TO THE UNIVERSE,

    WINGS TO THE MIND,

    FLIGHT TO THE IMAGINATION AND LIFE TO EVERYTHING.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//do comment if any problem arises

//Code

#include <iostream>

#include <fstream>

#include <algorithm>

#include <string>

using namespace std;

//name of file

#define filename "word.txt"

//number of lines in file

int n = 0;

//this function reads data from user and writes to file

void read()

{

string temp;

//open file for write

ofstream outfile(filename);

while (getline(cin, temp))

{

//if user enters $ break

if (temp.find("$") != string::npos)

break;

outfile << temp << endl;

}

//close file

outfile.close();

}

//this funciton displays contents of file

void display()

{

string temp;

//open file for read

ifstream infile(filename);

while (getline(infile, temp))

{

cout << temp << endl;

}

//close file

infile.close();

}

//this function converts all lines of file to capital letters

void Capital()

{

string words[1000], temp;

ifstream infile(filename);

while (getline(infile, temp))

{

//this line of code converts whole string to uppercase

transform(temp.begin(), temp.end(), temp.begin(), ::toupper);

words[n++] = temp;

}

//close file

infile.close();

//open file for output

ofstream outfile(filename);

//writer all words from words array of strings

for (int i = 0; i < n; i++)

{

outfile << words[i] << endl;

}

//close file

outfile.close();

}

int main()

{

string temp;

read();

Capital();

display();

}

Output:

Add a comment
Know the answer?
Add Answer to:
Convert the contents of text file to upper case (C++ Programming) Convert the contents of a...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Lab 1. Read in the contents of a text file up to a maximum of...

    C++ Lab 1. Read in the contents of a text file up to a maximum of 1024 words – you create your own input. When reading the file contents, you can discard words that are single characters to avoid symbols, special characters, etc. 2. Sort the words read in ascending order in an array (you are not allowed to use Vectors) using the Selection Sort algorithm implemented in its own function. 3. Search any item input by user in your...

  • You're to write a C++ program that analyzes the contents of an external file called data.txt....

    You're to write a C++ program that analyzes the contents of an external file called data.txt. (You can create this file yourself using nano, that produces a simple ASCII text file.) The program you write will open data.txt, look at its contents and determine the number of uppercase, lowercase, digit, punctuation and whitespace characters contained in the file so that the caller can report the results to stdout. Additionally, the function will return the total number of characters read to...

  • Programming language --> Matlab The name of a text file Outputs: (cell) An Nx2 cell array...

    Programming language --> Matlab The name of a text file Outputs: (cell) An Nx2 cell array listing words and their counts in sorted order Function Description: Have you ever seen those fancy word-clouds based on the frequency of word occurrences in some text? Well the first step of making a graphic like that is to figure out how often the words in some text occur, which is exactly what this function will do. You will count the number of occurrences...

  • In c programming The Consumer Submits processing requests to the producer by supplying a file name, its location and a character. It also outputs the contents of the file provided by the producer...

    In c programming The Consumer Submits processing requests to the producer by supplying a file name, its location and a character. It also outputs the contents of the file provided by the producer to the standard output. The Producer Accepts multiple consumer requests and processes each request by creating the following four threads. The reader thread will read an input file, one line at a time. It will pass each line of input to the character thread through a queue...

  • A. File I/O using C library functions File I/O in C is achieved using a file...

    A. File I/O using C library functions File I/O in C is achieved using a file pointer to access or modify files. Processing files in C is a four-step process: o Declare a file pointer. o Open the desired file using the pointer. o Read from or write to the file and finally, o Close the file. FILE is a structure defined in <stdio.h>. Files can be opened using the fopen() function. This function takes two arguments, the filename and...

  • I need help with this exercise. Than you for the help. Language is C++ 2 Enumeration...

    I need help with this exercise. Than you for the help. Language is C++ 2 Enumeration Data Types Reformat is the shell of a program designed to read characters and process them in the following way Lowercase character Uppercase character Digit Blank Newline Any other character Converts to uppercase and writes the character Writes the character Writes the digit Writes a blank Writes newline Does nothing / Program Reformat reads characters from file DataIn and // writes them to DataOut...

  • Write a C program which will display the contents of a file in base-16 (hexadecimal) and...

    Write a C program which will display the contents of a file in base-16 (hexadecimal) and in ASCII. Complete the following tasks: Obtain the name of the input file from the command line. If the command-line is “./hexdump xxx.bin” then argv[1] will contain “xxx.bin”. Open the file for binary input Print the entire file, 16-bytes per line. Each line should begin with an 8-digit hexadecimal offset into the file. This is the count of the bytes that you have already...

  • I need help programming this program in C. 1.) Write a program that reads a message,...

    I need help programming this program in C. 1.) Write a program that reads a message, then checks whether it's a palindrome (the letters in the message are the same from left to right as from right to left), example is shown below: Enter a message: He lived as a devil, eh? Palindrome Enter a message: Madam, I am Adam. Not a Palindrome 2.) Ignore all characters that aren't letters. Use integer variables to keep track of positions in the...

  • Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program...

    Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program 3 - Hangman Game Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman. You will need to: e You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of...

  • C++ Programming Objects Problem Assignment: Programming challenge #1 on page 714: "File Head Program" Write a...

    C++ Programming Objects Problem Assignment: Programming challenge #1 on page 714: "File Head Program" Write a program that asks the user for the name of a file. The program should display the first ten lines of the file on the screen (the “head" of the file). If the file has fewer than ten lines, the entire file should be displayed, with a message indicating the entire file has been displayed. Lab Help: Use the following two files to test your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT