Question: 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.

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



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
To create a commandline terminal program in C on Ubuntu using VirtualBox as you described follow these steps Step 1 Setting Up the Environment Ensure ... View full answer
Get step-by-step solutions from verified subject matter experts
