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
Something that might be used below
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.
The input file is already there. the file is too long, don't have to send it. using virtualbox ubuntu We want to cre...
Need to check if File is successfully opened? C++ It works when I input the right txt file. But, it keeps stating, File successfully open." even I put in a non-existing file. Here are the specifications: Develop a functional flowchart and then write a C++ program to solve the following problem. Create a text file named first.txt and write your first name in the file. You will be reading the name of the file from the keyboard as a string,...
Header file: Main file: Test file: Need help operator overloading << and >> for my program. My program reads from a text file, converts it to binary, ones complement and reverses the number and stores them in a new file called encrypt1.txt. Then decrypts it back to original txt in a file decrypt1.txt. Thanks #includeiost ream» #include<fstream> #include«st ring> using namespace std; class encrypt_decryptt public: encrypt_decrypt); int getascii(char); void convert_binary_flip(int); void reverse bits); void decrypt_ones(); void decrypt_reverse(bitset<8>); string getvalue(); void...
How would answer question #4 of this ? #1 and 2 #include<iostream> #include <fstream> using namespace std; void read(int arr[]) { string line; ifstream myfile("input.txt"); int i = 0; if (myfile.is_open()) { while (getline(myfile, line)) { arr[i]; i++; } myfile.close(); } } void output(int arr[]) { ofstream myfile("output.txt"); if (myfile.is_open()) { int i = 0;...
I'm trying to get this program to give the user an option to enter a random word and then have that word included at the end of each break in the story. I can get the option to ask for a word, but can't get the inputted word in the sentence to finish it. I believe my string story is wrong. Please help! //This program will ask a user to input three random words. //The words will be placed within...
Using C++ Part C: Implement the modified Caesar cipher Objective: The goal of part C is to create a program to encode files and strings using the caesar cipher encoding method. Information about the caesar method can be found at http://www.braingle.com/brainteasers/codes/caesar.php. Note: the standard caesar cipher uses an offset of 3. We are going to use a user supplied string to calculate an offset. See below for details on how to calculate this offset from this string. First open caesar.cpp...
Hey, so i am trying to have my program read a text file using a structure but i also want to be able to modify the results(I kinda have this part but it could be better). I cant seem to get it to read the file(all the values come up as 0 and i'm not sure why because in my other program where it wrote to the txt file the values are on the txt file) i copied and pasted...
First create the two text file given below. Then complete the main that is given. There are comments to help you. An output is also given You can assume that the file has numbers in it Create this text file: data.txt (remember blank line at end) Mickey 90 Minnie 85 Goofy 70 Pluto 75 Daisy 63 Donald 80 Create this text file: data0.txt (remember blank line at end) PeterPan 18 Wendy 32 Michael 28 John 21 Nana 12 Main #include...
The purpose of this assignment is to develop solutions that perform File IO and objects. Problem specifications are shown below with my changes in blue. 1. File Previewer Write a program that asks the user for the name of a text file. The program should display the first 10 lines of the file on the screen. If the file has fewer than 10 lines, the entire file should be displayed along with a message indicating the entire file has been...
I need to get this two last parts of my project done by tonight. If you see something wrong with the current code feel free to fix it. Thank you! Project 3 Description In this project, use project 1 and 2 as a starting point and complete the following tasks. Create a C++ project for a daycare. In this project, create a class called child which is defined as follows: private members: string First name string Last name integer Child...
Rework this project to include a class. As explained in class, your project should have its functionalities moved to a class, and then create each course as an object to a class that inherits all the different functionalities of the class. You createclass function should be used as a constructor that takes in the name of the file containing the student list. (This way different objects are created with different class list files.) Here is the code I need you...