Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The input file is already there. the file is too long, don't have to send it. using virtualbox ubuntu We want to create a command

The input file is already there. the file is too long, don't have to send it.

using virtualbox ubuntu

We want to create a command line terminal where user can run the snap commands with three different options: -thanos, -ironman and -holk. The terminal must keep listening to user command.

sprum@tevada:/Documents/Implementation/Teaching/SF/files ./q3 Enter your commande snap thanos Enter your commande snap -ironm

If the user type:

  • ? snap -thanos: all the text line in the text file ?input.txt? that does not contain the word ?thanos? must be randomly removed. The remaining text will be save into the new file named ?thanossnap.txt?. The content in ?input.txt? keep unchanged

  • ? snap -holk: all the text line in the text file ?thanossnap.txt? that does not contain the word ?thanos? will be duplicated. The new content will be save into the new file named ?holksnap.txt?

  • ? snap -ironman: all the text line in the text file ?input.txt? that contains the word ?thanos? must be removed. The remaining contents must be saved in file ?ironmansnap.txt?

  • ? exit: quit the programme

Something that might be used below

Write contents into a text file 1#include iostream 2#include fstream 3 using namespace std 5 int mainO 6 ofstream myfile;

Read a text file 1// reading a text file 2#include ?iostream? 3#include fstream 4#include string 5 using namespace std; 7

Write input text from keyword into a text file 1#include 2#include 3#include 4 iostream string fstream 5 using namespac

sprum@tevada:~/Documents/Implementation/Teaching/SF/file$ ./q3 Enter your commande : snap -thanos Enter your commande : snap -ironman Enter your commande : snap - holk Enter your commande : exit sprum@tevada:~/Documents/Implementation/Teaching/SF/file$ Write contents into a text file 1 #include 2 #include 3 using namespace std; 4 5 int main() { 6 ofstream myfile; 7 myfile.open ("example.txt", 8 ios::app); myfile < < "Writing this to a file."; myfile < < "Writing this to a file."; myfile < < "Writing this to a file."; 11 myfile < < "Writing this to a file."; 12 myfile.close(); 13 return 0; 9 10 Read a text file 1// reading a text file 2 #include 3 #include 4 #include 5 using namespace std; 6 7 int main () { 8 string line; 9 ifstream myfile ("example.txt"); if (myfile.is_open()) 10 11 { 12 13 14 15 16 17 18 19 20 21 22} while (getline (myfile, line) ) { } cout < < line < < < ''; myfile.close(); M } else cout < < "Unable to open file"; return 0; Write input text from keyword into a text file 1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 void writeToFile(string message) { ofstream myfile; 8 9 10 11 myfile.open ("example.txt", ios::app); myfile < < message

Step by Step Solution

3.42 Rating (142 Votes )

There are 3 Steps involved in it

Step: 1

Programming language c The file names are given as per the question Please maintain prope... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Operating Systems

Authors: Andrew S. Tanenbaum, Herbert Bos

4th edition

013359162X, 978-0133591620

More Books

Students also viewed these Programming questions