Time due: 11:00 PM Thursday, April 17
Before you ask a question about this specification, see if it has already been addressed in the spec or in the Project 2 FAQ. And read the FAQ before you turn in this project, to be sure you didn't misinterpret anything.
(Be sure you also do the homework accompanying this project.)
The mercurial King of Heard Island, Aptenodytes Patagonicus, has suddenly decided to protect the island's only domestic industry, guano production, by imposing tariffs on guano imports. The job of writing a program that determines the amount of import duty imposed on each shipment of guano has come to you.
Your program must accept as input the name of the country from which the guano is imported, the number of kilograms of guano, and the name of the importer. The output will tell how much import duty the importer will have to pay.
Here is an example of a dialog with the program (user input is shown here in boldface):
Country of origin: Ireland Weight in kilograms: 23 Importer: Mumble --- The import duty for Mumble is 1349.6 lantern fish.
(Lantern fish are the island's currency unit.) According to the import duty schedule:
Canada or Ireland (so spelled, with
exactly that upper and lower case), the duty is increased by an additional
amount of 76 lantern fish for each of those additional kilograms instead of
30.3. (The Canadian and Irish press had a field day with the "doody duty",
and the petulant, vindictive king can't stand being the butt of jokes.)
As an example, Mumble above would be assessed 57.6 lantern fish for the first 6 kilograms of guano, plus 1292 lantern fish for the next 17 kilograms (76 lantern fish per kilogram for the next 17 kilograms instead of 30.3, since the country of origin is Ireland), for a total of 1349.6 lantern fish.
Here's another example:
Country of origin: Peru Weight in kilograms: 3.3 Importer: Tux --- The import duty for Tux is 31.7 lantern fish.
You can test your understanding of the duty schedule by experimenting with this import duty calculator we found at the Heard Island Trade Ministry's web site.
Your program must collect the information for one importer in the manner
indicated by the examples, and then write to cout a line with
three hyphens only (no spaces or other characters), followed by exactly
one line in a format required below. Our grading tool will judge the
correctness of your program by examining only the line following the line
with three hyphens (and verifying that there are no additional lines after
that line). That one line you write must be in one of the following four
forms; the text must be identical to what is shown, except
that italicized items are replaced as appropriate:
You must enter a country of origin.
The weight must be positive.
You must enter an importer.
The import duty for importer is
amount lantern fish.
In the last case, importer must be the importer the user entered, and amount must be the correct duty amount, shown as a number with at least one digit to the left and exactly one digit to the right of the decimal point. The lines you write must not start with any spaces. If you are not a good speller or typist, or if English is not your first language, be especially careful about duplicating the messages exactly. Here are some foolish mistakes that may cause you to get very few points for correctness on this project, no matter how much time you put into it, because the mistake will cause your program to fail most or all of the test cases we run:
cout a line with exactly three hyphens in
all cases.cerr instead of cout.The inport duty for Oswald Cobblepot is 4748.2 lantern fish. misspelling The import Duty for Oswald Cobblepot is 4748.2 lantern fish. wrong capitalization The import duty for Oswald Cobblepot is 4748.2 fish. missing text The import duty for Oswald Cobblepot will be 4748.2 lantern fish. wrong text The import duty for Oswald Cobblepot is 4748.2 lantern fish. extra space at start of line The import duty for Oswald Cobblepot is4748.2 lantern fish. missing space The import duty for Oswald Cobblepot is 4748.2 lantern fish missing period The import duty for Oswald Cobblepot is 4748.18 lantern fish. extra digit The import duty for Oswald Cobblepot is 4748 lantern fish. missing decimal point and digit
Your program must gather the country of origin, the weight in kilograms, and
the importer in in that order. However, if you detect an error in an item,
you do not have to request or get the remaining items if you don't want to;
just be sure you write to cout the line of three hyphens, the
required message and nothing more after that. If instead you choose to
gather all input first before checking for errors, and you detect more
than one error, then after writing the line of three hyphens, write only
the error message for the earliest erroneous item.
You will not write any loops in this program. This means that each time you run the program, it handles only one importer. It also means that in the case of bad input, you must not keep prompting the user until you get something acceptable; our grading tool will not recognize that you're doing that.
A string with no characters in it is the empty string. A string with at least one character in it is not the empty string, even if the only characters in it are things like spaces or tabs. Although realistically it would be silly to have an importer consisting of seventeen spaces and nothing more, treat that as you would any other non-empty string: as a valid importer. (Since you don't yet know how to check for that kind of situation anyway, we're not requiring you to.)
The one kind of input error that your program does not
have to deal with (because you don't yet know enough to know how to do this
nicely), is not finding a number in the input where the weight is expected.
We promise that our grading tool will not, for example, supply the text
tons and tons when your program requests the weight. Notice that
the weight need not be an integer.
The correctness of your program must not depend on undefined program behavior.
Your program could not, for example, assume anything about n's
value at the point indicated:
int main()
{
int n;
int m = 42 * n; // n's value is undefined
…
Your program must build successfully under both g31 and either Visual C++ or clang++.
What you will turn in for this assignment is a zip file containing these three files and nothing more:
By April 16, there will be links on the class webpage that will enable you to turn in your zip file electronically. Turn in the file by the due time above. Give yourself enough time to be sure you can turn something in, because we will not accept excuses like "My computer died the afternoon of the day the assignment was due." There's a lot to be said for turning in a preliminary version of your program, report, and homework early (You can always overwrite it with a later submission). That way you have something submitted in case there's a problem later. Notice that most of the test data portion of your report can be written from the requirements in this specification, before you even start designing your program.
The writeup Some Things about Strings tells you what you need to know about strings for this project.
As you develop your program, periodically try it out under another compiler (g31 on cs31.seas.ucla.edu if you're doing your primary development using Visual C++ or Xcode). Sometimes one compiler will warn you about something that another is silent about, so you may be able to find and fix more errors sooner. If running your program under both environments with the same input gives you different results, your program is probably relying on undefined behavior (such as using the value of an uninitialized variable), which we prohibit.