1 answer

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

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 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

[email protected]:/Documents/Implementation/Teaching/SF/files ./q3 Enter your commande snap thanos Enter your commande snap -ironman Enter your commande snap -holk Enter your commande: exit [email protected]~/Documents/Implementation/Teaching/SF/files
Write contents into a text file 1#include 2#include 3 using namespace std 5 int mainO 6 ofstream myfile; 7 myfile.open ("example.txt", ios::app); 8 myfile

Answers

Programming language:c++

The file names are given as per the question.Please maintain the proper file name and input content of the input.txt file.

source code:

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
string input;
ifstream file1;
while (1)
{
cout << "Enter your commande : ";
cin >> input >>endl;
switch(input)
{
case "snap -ironman":
{
ofstream file2;
string line;   
file1.open("input.txt");
string str="thanos";
file2.open("ironmansnap.txt");
while (getline(file1, line))
{
if (line.find(str) != std::string::npos) //the reading line does not contain the word thanos.
{
file2<< line<<"\n";
}
  
}
break;   
  
}
case "snap -thanos":
{
string line;
ofstream file2;
file1.open("input.txt");
string str="thanos";
file2.open("thanossnap.txt");
while(getline(file1, line))
{
if (line.find(str) == std::string::npos)//reading the line that contains the word thanos.
{
file2<< line<<"\n";
}
}
break;

}
case "snap -holk":
{
string line;
ofstream file2;
file1.open("thanossnap.txt");
file2.open("holksnap.txt");
while(getline(file1, line))
{
file2<< line<<"\n";//duplicating the content of thanossnamp.txt into holksnap.txt.
}
break;

}
case "exit":
exit(0);
default:
cout<<"Enter the valid commande":

}

}

return 0;
}

//Hope i answered for this question.
  

.

Similar Solved Questions

1 answer
24. A radioisotope of argon, 35 Ar, lies below the "band of stability: (n/p ratio too...
24. A radioisotope of argon, 35 Ar, lies below the "band of stability: (n/p ratio too low). One would predict that it decays via (a) positron emission (b) beta emission (c) neutron emission (d) alpha emission (e) fission...
1 answer
(16 points) Consider the equation for the charge on a capacitor in an LRC circuit +...
(16 points) Consider the equation for the charge on a capacitor in an LRC circuit + 9 + 169 = E which is linear with constant coefficients. First we will work on solving the corresponding homogeneous equation. Divide through the equation by the coefficient on and find the auxiliary equation (using m...
1 answer
Why is calcium oxide basic in nature?
Why is calcium oxide basic in nature?...
1 answer
If #17/3 L# of a gas at room temperature exerts a pressure of #24 kPa# on its container, what pressure will the gas exert if the container's volume changes to #19/4 L#?
If #17/3 L# of a gas at room temperature exerts a pressure of #24 kPa# on its container, what pressure will the gas exert if the container's volume changes to #19/4 L#?...
1 answer
Real Analysis question, give clear writing please Let h(x) be the function on (0, 1) defined...
Real Analysis question, give clear writing please Let h(x) be the function on (0, 1) defined by ſi x <1 h(x) = 2 X=1 (a) For any P, what is the value of L(f,P)? (b) Can you find a P such that U(f,P) is within 1/10 of L(f,P)? (c) Show that h is integrable....
1 answer
Briefly describe the evolutionary history and tree of the hominids. Show the relationship to living apes...
Briefly describe the evolutionary history and tree of the hominids. Show the relationship to living apes like chimps, the main groups and when they branched off, the origin of bipedalis., tool use, and migrations out of Africa, Include chimps, Ardi, Tomo floriensis and modern human( Homo sapiens)...
1 answer
Exercise 20-10 Stahl Inc. produces three separate products from a common process costing $100,200. Each of...
Exercise 20-10 Stahl Inc. produces three separate products from a common process costing $100,200. Each of the products can be sold at the split-off point or can be processed further and then sold for a higher price. Shown below are cost and selling price data for a recent period. Sales Value at Spl...
1 answer
Need help 8) (18 points) A student wonders if tall women tend to date taller men...
need help 8) (18 points) A student wonders if tall women tend to date taller men than do short women. She randomly selected couples from her school. Here are the data (heights in inches): (remember to do ALL parts) Women Men 62 71 68 67 67 71 69 70 71 68 71 69 a. Do these data provide convincing ...
1 answer
A particle leaves the origin with a speed of 3.5 106 m/s at 28 degrees to...
A particle leaves the origin with a speed of 3.5 106 m/s at 28 degrees to the positive x axis. It moves in a uniform electric field directed along positive y axis. Find Ey such that the particle will cross the x axis at x = 1.5 cm if the particle is an electron...
1 answer
How do you simplify #2(4 + t)#?
How do you simplify #2(4 + t)#?...
1 answer
Could you please provide a clear and accurate worked solution for the following problem. I will...
Could you please provide a clear and accurate worked solution for the following problem. I will leave feedback that matches the accuracy and effort of your solution. Please make any formulas used clear. Thank you. There is an object with some forces acting on it. Through its centre of gravity at (0...
1 answer
4. A bullet is fired vertically upward with an initial velocity of 260m/s. a) How high...
4. A bullet is fired vertically upward with an initial velocity of 260m/s. a) How high does it go? b) How long does it take to reach maximum height? c) How long is it the air ? ( or time to hit the ground) Farh 5. The volume of a cylinder is: Vanrh If V=2,500 m and h = 17 m find the value ofr...
1 answer
JAVA: Excerpt B.A: Complete the implementation of the following method. The purpose of this method is...
JAVA: Excerpt B.A: Complete the implementation of the following method. The purpose of this method is to return true if and only if all the elements in the array are x. In other words, all elements in the array are the value x (replace -a- with right answer). public static -a- allSame(int[] nums, in...
1 answer
A stock’s return has the distribution below. Calculate the stock’s Sharpe ratio, expressed to three decimals....
A stock’s return has the distribution below. Calculate the stock’s Sharpe ratio, expressed to three decimals. Assume the risk-free rate is 3%. (Note: it is easier to use your values from above and plug & chug.) Demand for Products Probability of Demand Occurring Rate of Retur...
1 answer
Chance Company had two operating divisions, one manufacturing farm equipment and the other office supplies. Both...
Chance Company had two operating divisions, one manufacturing farm equipment and the other office supplies. Both divisions are considered separate components as defined by generally accepted accounting principles. The farm equipment component had been unprofitable, and on September 1, 2021, the comp...
1 answer
5. If the actual GDP is greater than YN, it will return to YN in the...
5. If the actual GDP is greater than YN, it will return to YN in the long run. Why and how does this happen?...
1 answer
Last 3 pics is all one chart just many parts bc so long Question 3 of...
last 3 pics is all one chart just many parts bc so long Question 3 of 6 -/1 E View Policies Current Attempt in Progress Helen Martin started her own consulting firm, Ivanhoe Consulting, on May 1, 2020. The following transactions occurred during the month of May May 1 2 3 5 9 12 15 17 20 23 26 ...
1 answer
2. (10 pts.) Consider sending a large file of F bits from Host A to Host...
2. (10 pts.) Consider sending a large file of F bits from Host A to Host B. There are six links (and five switches) between A and B, and the links are not congested (that is, no queueing delays). Host A segments the file into segments of S bits each and adds 30 bits of header to each segment, formin...