Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a program that will accept, organise and display command line arguments. Many programs that run using a command line interface (CLI) use command line

write a program that will accept, organise and display command line arguments.

Many programs that run using a command line interface (CLI) use command line arguments to modify and/or establish program behaviour. Command line arguments are provided to the program via the command line, with each argument separated by one or more spaces.

Command line arguments can be split into two categories:

  • Options: Arguments that can modify the behavior of a command. Options start with at least one hyphen (-) and come in short varieties (single hyphen followed by a single letter) and long varieties (double hyphen followed by a word. Options may be followed my zero or more parameters that provide some form of variable information.
  • Parameters: Arguments that provide information/data to an option. The formatting of a parameter will depend on what the option it follows requires. For the purposes of this exercise, we will assume that a parameter must follow an option and cannot be the first command line argument.

If no command line arguments are provided, the program will write the following to the console and exit the program:

WARNING: No command line arguments provided.

If the first argument is a parameter and not an option, the program will write the following to the console and exit the program:

WARNING: Parameters must be provided after options.

Otherwise, the program will display a list of options and their associated parameters. If an option has parameters, they will be listed on the same line (see the formatting in the examples below). If the option has no parameters, it will be listed alone on a line. Below are a number of examples of how the program may play out with a variety of command line arguments. You must test these on your program and confirm that they work before uploading your solution to the AMS.

Arguments: -x

-x

Arguments: --option01 param78

--option01: { param78 }

Arguments: --option92 param95 param72 param73 param24

--option92: { param95, param72, param73, param24 }

Arguments: --option17 param07 param58 -k param71 param90 param69 param56 --option30 -e param73 -b

--option17: { param07, param58 } -k: { param71, param90, param69, param56 } --option30 -e: { param73 } -b

Hints

  • Recall that command line arguments are available to your program as the string array input to the Main function.
  • When exiting the program, refrain from using Environment.Exit, as it will exit the AMS driver as well and you will not receive any marks.

Skeleton Code

Start by copying the sample code below into a new .NET Core console application project in Visual Studio. Attempt to solve the problem and test it. When you are ready, complete the exercise by uploading the .cs file and pressing Submit.

using System; class CommandLineArguments {    public static void Main(string[] args)    {        // Write your solution here...    } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

C program to is as follows including packages using System using SystemCollections namespace Command... 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 Operating System questions