Lab 4 Ex 1: Apple Pies

Lab 4 Ex 1: Apple Pies

You cannot submit for this problem because the homework's deadline is due.

Related Topics: exceptions, program arguments.

This exercise will help you better understand how try, throw and catch work for exception handling. Also, you will practise using program arguments.

You are going to simulate the process of buying ingredients for apple pies. The following are some basic rules:

  • To make an apple pie, you need 250 grams of flour, 1 egg and 2 apples.

  • There are 2 markets that you can visit: market1 and market2. market1 sells flour and eggs, and market2 sells apples.

  • You should first visit market1 and then market2. If market1 is open, you should first buy flour and then buy eggs. During the procedure, if any "exception" happens (eg: market1 is closed, eggs in market1 are not enough, etc), the buying process will end (exception caught). See ex1.cpp for details.

  • The input will be a sequence of numbers read from program arguments (6 numbers in total): number of apple pies (integer type), status of market1 (1 for open and 0 for closed), status of market2 (1 for open and 0 for closed), amount of flour remaining in market1 (in grams, float type), number of eggs remaining in market1 (integer type), number of apples remaining in market2 (integer type). For example, if the program name is ex1 and the arguments are "2 1 1 355 10 5", i.e.,

    ./ex1 2 1 1 355 10 5
    

    then you will make 2 pies, both markets are open, 355g of flour and 10 eggs remain in market1, and 5 apples remain in market2.

  • Part of the program has already been implemented. Your work is to complete the program by filling the parts marked with TODO. Please do not change any code that is already written. See ex1.cpp for further instructions.

  • Note: You do not need to round values in this exercise. We will not test you by any strange or long float numbers.

Testing

Compile ex1.cpp to an executable file ex1. Execute it with 6 arguments chosen by yourself. For example,

./ex1 3 1 1 1000 10 5

Then the output should be

You visit market1 first...
You've bought enough flour and eggs. Then you visit market2...
Apples in market2 are not enough. You still need 1 more.
It seems that today is not a good day for making apple pies.

Lab Four

Not Claimed
Status
Finished
Problems
3
Open Since
2022-06-07 20:00
DDL
2022-06-14 23:59
Extension
72.0 hour(s)