CBSE (Science) Class 12CBSE
Share
Notifications

View all notifications

Polina Raj Has Used a Text Editing Software to Type Some Text in an Article. After Saving the Article as Mynotes.Txt, She Realised that She Has Wrongly Typed Alphabet K in Place of Alphabet C Everywhere in the Article Write a Function Definition for Puretext() in C++ that Would Display the Corrected Version of the Entire Article of the File Mynotes.Txt with All the Alphabets "K" to Be Displayed as an Alphabet "C" on Screen - CBSE (Science) Class 12 - Computer Science (C++)

Login
Create free account


      Forgot password?

Question

Polina Raj has used a text editing software to type some text in an article. After saving the article as MYNOTES.TXT, she realised that she has wrongly typed alphabet K in place of alphabet C everywhere in the article.

Write a function definition for PURETEXT() in C++ that would display the corrected version of the entire article of the file MYNOTES.TXT with all the alphabets "K" to be displayed as an alphabet "C" on screen.

Note: Assuming that MYNOTES.TXT does not contain any c alphabet otherwise

Example:

If Polina has stored the following content in the file MYNOTES.TXT

I OWN A KUTE LITTLE KAR

I KARE FOR IT AS MY KHILD

The function PURETEXT() should display the following content

I OWN A CUTE LITTLE CAR

I CARE FOR IT AS MY CHILD.

Solution

void PURETEXT()
{
   ifstream read;
   read.open("MYNOTES.TXT");
   while(!read.eof())
   {
       char str=read.get();
       for (int i=0;i<str.length();i++)
       {
           if(str[i])== 'k')
           {
              str[i]= 'c';
           }
       }
    }
}
  Is there an error in this question or solution?

APPEARS IN

Solution Polina Raj Has Used a Text Editing Software to Type Some Text in an Article. After Saving the Article as Mynotes.Txt, She Realised that She Has Wrongly Typed Alphabet K in Place of Alphabet C Everywhere in the Article Write a Function Definition for Puretext() in C++ that Would Display the Corrected Version of the Entire Article of the File Mynotes.Txt with All the Alphabets "K" to Be Displayed as an Alphabet "C" on Screen Concept: Function Call by Reference.
S
View in app×