Write a C++ console application that creates a list of itemsusing both command-line arguments and user inputs from theconsole.
The application reads both the list’s name and number of itemsfrom its command-line arguments. Once it starts, it proceeds toprompt the user for each item on the list, up to the total numberof items. Each item is a line of text read from the console(accepting spaces). After each item is read, the program’s promptproperly updates to display the current number of items read.
Once all items are read, the program outputs the list namefollowed by the numbered list of items with their first lettercapitalised and all others lower cased.
Interface
list.exe <list name> <number of items>
<listname> a string representing the name of the list
<number of items> the number of items in the list
Validation
If the minimum number of arguments is not supplied, theapplication prompts the user with a usage message and quits with anon-zero return value.
The <number of items> comes as a string from thecommand-line and must be first converted into an integer, thenvalidated to be greater than 0. If it’s not, the application warnsthe user with a console message and quits with a non-zero returnvalue.
To showcase the ability to use C in a C++ program, you can usethe atoi C function to convert the number of items arguments from ac-string into an int. But be careful of reading that int returninto a size_t variable.
While the list name doesn’t need validation, each list of theitem must have at least two letters to showcase the capitalisationof the first (and only the first).
Example of what the program should look like:
C:\grocerylist> .\grocerylist.exe "Groceries List" 5 Item (1 of 5): bread Item (2 of 5): fruit of the week Item (3 of 5): milk Item (4 of 5): butter Item (5 of 5): eggs [Groceries List] 1. Bread 2. Fruit of the week 3. Milk 4. Butter 5. Eggs C:\grocerylist>
Write a C++ console application that creates a list of items using both command-line arguments and user inputs from the
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am