Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are to create a program that properly handles two types of input-- command line arguments and standard input. The purpose of this exercise is

You are to create a program that properly handles two types of input-- command line arguments and standard input. The purpose of this exercise is to ensure that you can effectively handle both types of input and that you clearly understand the differences. In particular, the program will perform as follows:

  1. There are three possible command line arguments for this program: option1, option2, and option3. Each option appears following a single dash ('-'). A word of text follows certain options. Your program must read the actual arguments present and store any additional data associated with them.
  2.  The options appear on the command line as follows:
    • option1: -o
    • option2: -t
    • option3: -h
  3. A word always follows option1 and option2. There is no data following option3.
  4. Any, all, or none of these options may be present on the command line; moreover, they may be present in any order. Your program must properly handle all possible combinations. For example, option3 (-h) may be present, followed by option1 (-o), while option2 is not present on the command line.
  5. In addition to command line arguments, your program must also read data from standard input.
  6. Your program will read data from standard input one line at a time. Your program must continue reading until there is no more data from standard input.
  7. When your program starts, it must output the heading, "Standard Input:" (without quotation marks).
  8. As your program reads a line from standard input, it will output the line immediately to standard output.
  9. Once all data has been read from standard input and output accordingly, your program will output the heading, "Command line arguments:" (again, without quotation marks); your program will then display a list of the command line options found, along with their data, in numeric order. In other words, option1 must be displayed first, if present, then option2, and finally option3. The heading must be output even if there are no command line arguments. DO NOT DISPLAY AN OPTION IF IT IS NOT PRESENT ON THE COMMAND LINE.
  10. If you write your program using Python, you can use the getopt.getopt function, which will do much of the heavy lifting for you.

 Command line:

  • Python:C:UsersKarenPyCode> py input_program.py -h -t giraffe
  • Java:C:UsersKarenEclipse> java InputProgram -h -t giraffe
  • Standard input entered: zebra, hyena, CTRL-z
  • Output as it should appear:Standard Input: zebra zebra hyena hyena ^Z Command line arguments: option 2: giraffe option 3

Step by Step Solution

3.48 Rating (158 Votes )

There are 3 Steps involved in it

Step: 1

Solution Step1 Heres a Python program that meets your requirements python Copy code import getopt im... 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

Principles Of Information Security

Authors: Michael E. Whitman, Herbert J. Mattord

7th Edition

035750643X, 978-0357506431

More Books

Students also viewed these Programming questions

Question

What is self-awareness? (p. 44)

Answered: 1 week ago