Question 1 of 1: Word Swap: Write a C++ program that will swap the words Caesar and Brutus in the file “source_file.txt”. You will need to load the file “source_file.txt” and finally write the updated contents with the replaced words to the file “target_file.txt”. Successful operation should swap all occurrences of Caesar with Brutus and Brutus with Caesar. You can use functions from the cstring library. You are not allowed to use the string datatype. Once again, do not use string datatype. Please properly comment your code before submission.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Question 1 of 1: Word Swap: Write a C++ program that will swap the words Caesar and Brutus
in the file “source_file.txt”. You will need to load the file “source_file.txt” and finally write the
updated contents with the replaced words to the file “target_file.txt”.
Successful operation should swap all occurrences of Caesar with Brutus and Brutus with Caesar.
You can use functions from the cstring library. You are not allowed to use the string datatype. Once again, do not use string datatype.
Please properly comment your code before submission. 

target file.txt Contents
Friends, Romans, countrymen, lend me your ears;
I come to bury Brutus, not to praise him.
The evil that men do lives after them;
The good is oft interred with their bones;
So, let it be with Brutus The noble Caesar
Hath told you Brutus was ambitious:
If it were so, it was a grievous fault,
And grievously hath Brutus answer'd it.
Here, under leave of Caesar and the rest-
For Caesar is an honorable man;
So are they all, all honorable men-
Come I to speak in Brutus's funeral.
He was my friend, faithful and just to me:
But Caesar says he was ambitious;
And Caesar is an honorable man.
He hath brought many captives home to Rome
Whose ransoms did the general coffers fill:
Did this in Brutus seem ambitious?
When that the poor have cried, Brutus hath wept:
Ambition should be made of sterner stuff:
Yet Caesar says he was ambitious;
And Caesar is an honorable man.
You all did see that on the Lupercal
I thrice presented him a kingly crown,
Which he did thrice refuse: was this ambition?
Yet Caesar says he was ambitious;
And, sure, he is an honorable man.
|I speak not to disprove what Caesar spoke,
But here I am to speak what I do know.
You all did love him once, not without cause:
What cause withholds you then, to mourn for him?
O judgment! thou art fled to brutish beasts,
And men have lost their reason. Bear with me;
My heart is in the coffin there with Brutus
And I must pause till it come back to me.
Do not use String
datatype
Hint
You may want to read the contents of the file one word at a time.
Transcribed Image Text:target file.txt Contents Friends, Romans, countrymen, lend me your ears; I come to bury Brutus, not to praise him. The evil that men do lives after them; The good is oft interred with their bones; So, let it be with Brutus The noble Caesar Hath told you Brutus was ambitious: If it were so, it was a grievous fault, And grievously hath Brutus answer'd it. Here, under leave of Caesar and the rest- For Caesar is an honorable man; So are they all, all honorable men- Come I to speak in Brutus's funeral. He was my friend, faithful and just to me: But Caesar says he was ambitious; And Caesar is an honorable man. He hath brought many captives home to Rome Whose ransoms did the general coffers fill: Did this in Brutus seem ambitious? When that the poor have cried, Brutus hath wept: Ambition should be made of sterner stuff: Yet Caesar says he was ambitious; And Caesar is an honorable man. You all did see that on the Lupercal I thrice presented him a kingly crown, Which he did thrice refuse: was this ambition? Yet Caesar says he was ambitious; And, sure, he is an honorable man. |I speak not to disprove what Caesar spoke, But here I am to speak what I do know. You all did love him once, not without cause: What cause withholds you then, to mourn for him? O judgment! thou art fled to brutish beasts, And men have lost their reason. Bear with me; My heart is in the coffin there with Brutus And I must pause till it come back to me. Do not use String datatype Hint You may want to read the contents of the file one word at a time.
Expected operation :
source file.txt Contents
Friends, Romans, countrymen, lend me your ears;
I come to bury Caesar, not to praise him.
The evil that men do lives after them;
The good is oft interred with their bones;
So, let it be with Caesar. The noble Brutus
Hath told you Caesar was ambitious:
If it were so, it was a grievous fault,
And grievously hath Caesar answer'd it.
Here, under leave of Brutus and the rest-
For Brutus is an honorable man;
So are they all, all honorable men-
Come I to speak in Caesar's funeral.
He was my friend, faithful and just to me:
But Brutus says he was ambitious;
And Brutus is an honorable man.
He hath brought many captives home to Rome
Whose ransoms did the general coffers fill:
Did this in Caesar seem ambitious?
When that the poor have cried, Caesar hath wept:
Ambition should be made of sterner stuff:
Yet Brutus says he was ambitious;
And Brutus is an honorable man.
You all did see that on the Lupercal
I thrice presented him a kingly crown,
Which he did thrice refuse: was this ambition?
Yet Brutus says he was ambitious;
And, sure, he is an honorable man.
I speak not to disprove what Brutus spoke,
But here I am to speak what I do know.
You all did love him once, not without cause:
Do not use String
datatype.
What cause withholds you then, to mourn for him?
O judgment! thou art fled to brutish beasts,
And men have lost their reason. Bear with me;
My heart is in the coffin there with Caesar,
And I must pause till it come back to me.
Transcribed Image Text:Expected operation : source file.txt Contents Friends, Romans, countrymen, lend me your ears; I come to bury Caesar, not to praise him. The evil that men do lives after them; The good is oft interred with their bones; So, let it be with Caesar. The noble Brutus Hath told you Caesar was ambitious: If it were so, it was a grievous fault, And grievously hath Caesar answer'd it. Here, under leave of Brutus and the rest- For Brutus is an honorable man; So are they all, all honorable men- Come I to speak in Caesar's funeral. He was my friend, faithful and just to me: But Brutus says he was ambitious; And Brutus is an honorable man. He hath brought many captives home to Rome Whose ransoms did the general coffers fill: Did this in Caesar seem ambitious? When that the poor have cried, Caesar hath wept: Ambition should be made of sterner stuff: Yet Brutus says he was ambitious; And Brutus is an honorable man. You all did see that on the Lupercal I thrice presented him a kingly crown, Which he did thrice refuse: was this ambition? Yet Brutus says he was ambitious; And, sure, he is an honorable man. I speak not to disprove what Brutus spoke, But here I am to speak what I do know. You all did love him once, not without cause: Do not use String datatype. What cause withholds you then, to mourn for him? O judgment! thou art fled to brutish beasts, And men have lost their reason. Bear with me; My heart is in the coffin there with Caesar, And I must pause till it come back to me.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education