change the code to do the same purpose and same output :
change the code to do the same purpose and same output :
Source Code:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void displayPlain();
void displayHex();
void executeCommand(int choice){
switch (choice)
{
case 1:
displayPlain();
break;
case 2:
displayHex();
break;
case 9:
exit(0);
default:
cout<<"Invalid Choice Entered!!\n";
}
}
void displayMenu(){
cout<<"\n===============Menu==========================\n\n";
cout<<"1. Select 1 to see file data in plain text\n";
cout<<"2. Select 2 to see file data in hexadecimal\n";
cout<<"3. Select 9 to quit\n\n";
}
int main(){
int choice;
do{
displayMenu();
cout<<"choice: ";
cin>>choice;
executeCommand(choice);
}while(choice != 9);
return 0;
}
void displayPlain(){
fstream file;
file.open("q4File.txt", ios::in);
string line;
if(file.is_open()){
while (getline(file, line))
{
cout<<endl<<line<<endl<<endl;
}
}
file.close();
}
void displayHex(){
fstream file;
file.open("q4File.txt", ios::in);
char ch;
if(file.is_open()){
cout<<endl;
while (file.get(ch))
{
printf("%02hhx ", ch);
}
cout<<endl;
}
file.close();
}
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)