Write a program to compute the correct state sales tax, given a list of item prices. For example, a retailer selling two items each costing $3.45 and one item costing $123.45 could compute the sales tax by typing
salesTax salesTaxRates TX 3.45 3.45 123.45into any shell. Here,
(3.45 + 3.45 + 123.45) * 6.25% = 8.146875,which is then rounded to the closest penny.
The example given above has six command-line arguments, separated by whitespace. Just as for arrays, they are numbered starting with zero. For example, argv[2] is TX, and argv[5] is 123.45.
Here are the three rules for using command-line arguments:
For an example of a program that uses command-line arguments, see sample program sumpgm.cpp.
All command-line arguments are C-style strings, even for numeric arguments; e.g., argv[3] is the string ``3.45''. You can use the atof() library function to convert from a string to a double. Under Linux/Unix, you can get online help about this function by typing man atof or info atof. For example, use
atof(argv[3])to convert the string to its double value 3.45. Be sure to include stdlib.h.
Submit your source code as described in the Guidelines for Programming Assignments. Use a subject heading of ``cs1321 hw1'', and submit a single file containing your C++ source code.