Question

Update the program in the bottom using C++ to fit the requirements specified in the assignment....

Update the program in the bottom using C++ to fit the requirements specified in the assignment.

Description

For this assignment, you will be writing a single program that enters a loop in which each iteration prompts the user for two, single-line inputs. If the text of either one of the inputs is “quit”, the program should immediately exit. If “quit” is not found, each of these lines of input will be treated as a command line to be executed. These two commands should be executed as if the user had typed command1 | command2 at the shell prompt, meaning that the standard output of the first command gets redirected into the standard input of the second command. (It should be noted that using cin >> will not grab a whole line; you will need to use another function instead.) You will need to be able to split the text entered by the user into the different command line arguments that comprise it. I do not care how this is accomplished, but some possibilities are to use the C function strtok, or a C++ istringstream object. You do not need to worry about escaping special characters when splitting the string for the purposes of this assignment; the split can be performed based on spaces alone.After these commands have both finished executing, your program should prompt for another pair of input commands to run, repeating the process over and over again until the user gives “quit” as input.

Requirements

-You may not use the system function to do this. You must make your own child processes, do the appropriate changes to the file descriptors in each of them, and have them use one of the exec calls to run the commands given by the user.

-Use the pipe system call to create the file descriptors used to communicate between the two programs that are run.

-If an error occurs at any point, there should be an appropriate error message printed to the standard error stream.

-Your program must be able to handle user-specified commands that are up to 127 characters long.

-Your program must be able to handle user-specified commands that contain up to five command-line arguments.

-Make sure to close unused pipe file descriptors in all process. If you do not, your program is likely to stall.

-Do not forget that this program involves a loop. After both programs have finished running (but not until), the program should go back to the beginning and prompt for two more commands to run.

******************************************************************************************************

#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char const *argv[])
{

   char op = 'y';
   while (op == 'y' || op == 'Y') {
       string string1, string2;

       cout << "enter first string";

       getline(cin, string1);

       cout << "enter second string";

       getline(cin, string2);
       for (int i = 0; i <= 120; i++)

       {

           if (string1 == wordsToFind[i])

           {

               ifstream the_file(argv[1]);
               if (!the_file.is_open())
                   cout << "Could not open file\n";
               else {
                   char x;
                   while (the_file.get(x))
                       cout << x;
               }

           }
       }

       cout << "Do you want to cintunue (y/n) ? ";
       cin >> op;
   }


   return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream.h>

#include<conio.h>

using namespace std;

void main()

{

char string1[120], string2[120];

int flag=0;

cout<<"enter first string";

gets(string1);

cout<<"enter second string";

gets(string2);

getline(string1,string2)

for(int i=0;i<=120;i++)

{

if(string1==wordsToFind[i]!=string::quit)

{

ifstream the_file ( argv[1] );
     if ( !the_file.is_open() )
      cout<<"Could not open file\n";
    else {
      char x;
      while ( the_file.get ( x ) )
        cout<< x;
    }
 
  }
}
Add a comment
Know the answer?
Add Answer to:
Update the program in the bottom using C++ to fit the requirements specified in the assignment....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IP requirements: Load an exam Take an exam Show exam results Quit Choice 1: No functionality...

    IP requirements: Load an exam Take an exam Show exam results Quit Choice 1: No functionality change. Load the exam based upon the user's prompt for an exam file. Choice 2: The program should display a single question at a time and prompt the user for an answer. Based upon the answer, it should track the score based upon a successful answer. Once a user answers the question, it should also display the correct answer with an appropriate message (e.g.,...

  • Below is the picture for the direction of my program and also the part where I...

    Below is the picture for the direction of my program and also the part where I have problems with I've already finished it and my code works correctly. But what I need to do is to "read the file name from the command line arguments" instead of the standard input (cin) that I did for step 1. I'm not sure how to do that. 2.13 PROGRAM 1: Calculating Coefficient Of Lift For this PROGRAM you will calculate the coefficient of...

  • Star Database Program. This is a more sophisticated assignment, it will take longer to do. Write...

    Star Database Program. This is a more sophisticated assignment, it will take longer to do. Write a program which uses file IO, loops, and function calls. The following files are provided in pub: Assignment.cpp stars.dat solution_stars.dat solution.o when you log in the first time, make a directory for this project mkdir prog3 then copy down the files. (WARNING! This will overwrite any file in the directory named Assignment.cpp, so don't copy down Assignment.cpp if you have already done work): cp...

  • Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text...

    Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...

  • 1. Suppose you wrote a program that reads data from cin. You are now required to...

    1. Suppose you wrote a program that reads data from cin. You are now required to reimplement it so that you can read data from a file. You are considering the following changes. I. Declare an ifstream variable in_file II. Replace all occurrences of cin with in_file III. Replace all occurrences of > > and get_line with the appropriate operations for ifstream objects What changes do you need to make? I, II, and III II and III I and III...

  • Write a program that takes in a line of text as input, and outputs that line of text in reverse.

    Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text.Ex: If the input is:Hello there Hey quitthen the output is:ereht olleH yeHThere is a mistake in my code I can not find. my output is : ereht olleH ereht olleHyeHHow can I fix this?I saw some people use void or the function reverse but we didnt...

  • I need help with using the infile and outfile operations in C++... Here's my assignment requirements:...

    I need help with using the infile and outfile operations in C++... Here's my assignment requirements: Assignment: Cindy uses the services of a brokerage firm to buy and sell stocks. The firm charges 1.5% service charges on the total amount for each transaction, buy or sell. When Cindy sells stocks, she would like to know if she gained or lost on a particular investment. Write a program that allows Cindy to read input from a file called Stock.txt: 1. The...

  • #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure...

    #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure char start_state, to_state; char symbol_read; }; void read_DFA(struct transition *t, char *f, int &final_states, int &transitions){ int i, j, count = 0; ifstream dfa_file; string line; stringstream ss; dfa_file.open("dfa.txt"); getline(dfa_file, line); // reading final states for(i = 0; i < line.length(); i++){ if(line[i] >= '0' && line[i] <= '9') f[count++] = line[i]; } final_states = count; // total number of final states // reading...

  • Hi, need this question ansered in c++, has multiple levels will post again if you can...

    Hi, need this question ansered in c++, has multiple levels will post again if you can complete every level so keep an eye out for that. here is a sketch of the program from the screenshot int main (int argc, char** argv) { enum { total, unique } mode = total; for (int c; (c = getopt(argc, argv, "tu")) != -1;) { switch(c) { case 't': mode = total; break; case 'u': mode = unique; break; } } argc -=...

  • C Language Programming. Using the program below - When executing on the command line only this...

    C Language Programming. Using the program below - When executing on the command line only this program name, the program will accept keyboard input and display such until the user does control+break to exit the program. The new code should within only this case situation “if (argc == 1){ /* no args; copy standard input */” Replace line #20 “filecopy(stdin, stdout);” with new code. Open read a text file “7NoInputFileResponse.txt” that contains a message “There were no arguments on the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT