Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COSC1076 | Semester 1 2023

Advanced Programming Techniques

Assignment 2 Vending Machine

Assessment Type: Both group and individual assessments.

Weight: 40% of the final course mark

Due Date: 23:59, Friday 26 May 2023 (Note that there is also a group demonstration due in Week 10)

Silence Policy: From 5:00pm, Thursday 25 May 2023 (Week 12)

Submission: Online via Canvas. Submission instructions are provided on Canvas.

1 Introduction

1.1 Overview

In this assignment, you will use your C++ programming skills to create a front-end system for a  vending machine. The vending machine serves all kinds of pastry treats. The company’s name is Penelope’s Pastry Delights and as such, the executable you are creating will be called“ppd”.

The following sections contain the details of this assignment. You are expected to understand every requirement explained in this document and implement all of them accordingly. This assignment has a strong emphasis on

linked lists. You should get yourself familiar with this concept as soon as possible.

In this assignment you will:

• Practice the programming skills covered throughout this course, such as:

– ADTs

– Linked Lists

– Pointers

– Dynamic Memory Management

– File Processing

– Program State Management

Exception Handling

• Practice the use of testing

• Implement a medium size C++ program:

– Use features of C++14

– Use elements of the C++ STL

• Work as a team

– Use group collaboration tools

This assignment is divided into four Milestones:

• Milestone 1 (Group work):  Test Cases, to be developed to ensure your ppd program implementation is correct (due week 10).

• Milestone 2  (Group work):  A fully functioning implementation of the base ppd program, which pass Milestone 1 tests. The group work (milestone 1 & 2) is worth 25% of the course mark.  Your group is required to demonstrate REQ5, 6, 8 and 9 in week 10 lab session (due week 10).

• Milestone 3  (Individual work):  You will individually extend upon your group’s implementation with additional functionality (called enhancements).  The individual work is worth 15% of the course mark (due week 12).

• Milestone 4 (Group + Individual work): Written report (no more than 4 pages) analysing the design and implementation of your software, and the use of your test cases.  You will demonstrate your group and

individual work. This is where your final work will be graded (due week 12).

Group Progress Update (Group work): Your group will need to provide regular updates on your progress in this assignment to your tutor during your weekly lab classes. This will require your group to have completed a list of activities.  Group Progress Update will not be marked directly, however, this will influence the final grade.

1.2 Group Work

The group work must be completed in groups of 4.

• You may form groups with any student in the course.

• We strongly recommend that you form groups from within your labs, because:

– Your tutor will help you form groups, but only within your lab.

– You will have plenty of opportunity to discuss your groups progress and get help from your tutor during the rest of the course.  It will be extremely helpful for your whole group to be present, but this can’t happen if you have group members outside the lab.

– If you form a group with students from multiple practicals, you will still need to be allocated to a single tutor and we may need you to switch labs to ensure everyone gets a fair amount of time.

Groups for Assignment 2 must be registered with your tutor by week 8 lab . Your tutor will“register” your group on Canvas. If you are unable to find a group, discuss this with your tutor as soon as possible.

If at any point you have problems working with your group, inform your tutor immediately, so that issues may be resolved. We will do our best to help manage group issues, so that everybody receives a fair grade for their contributions. To help with managing your group work we will be requiring your group to use particular tools. These are detailed in Section 5.

There are important requirements about keeping your tutor informed if you have been unwell or other wise unable to contribute to your group. Remember your actions affect everybody in your group.

1.3 Learning Outcomes

This assessment relates to all of the learning outcomes of the course which are:

• Analyse and Solve computing problems; Design and Develop suitable algorithmic solutions using software concepts and skills both (a) introduced in this course, and (b) taught in pre-requisite courses; Implement and Code the algorithmic solutions in the C++ programming language.

• Discuss and Analyse software design and development strategies; Make and Justify choices in software design and development;  Explore underpinning concepts as related to both theoretical and practical applications of software design and development using advanced programming techniques.

• Discuss, Analyse, and Use appropriate strategies to develop error-free software including static code anal- ysis, modern debugging skills and practices, and C++ debugging tools.

• Implement small to medium software programs of varying complexity; Demonstrate and Adhere to good programming style, and modern standards and practices; Appropriately Use typical features of the C++ language include basic language constructs, abstract data types, encapsulation and polymorphism, dy- namic memory management, dynamic data structures, file management, and managing large projects containing multiple source files; Adhere to the C++14 ISO language features.

• Demonstrate and Adhere to the standards and practice of Professionalism and Ethics, such as described in the ACS Core Body of Knowledge (CBOK) for ICT Professionals.

2 Description of the Program and Functionalities

You have been approached by a company to create a front-end system for a vending machine written in C++. The vending machine serves all kinds of pastry treats. The company’s name is Penelope’s Pastry Delights and as such, the executable you are creating will be called“ppd”. In this assignment you are to implement an application that will perform the above tasks as a single user model.

This section describes in detail all functional requirements of this assignment. You should make a conscientious effort to write your program in a way that is capable of replicating the functionalities of the ppd program, described in the requirements below.

REQ1: Command-line arguments

A user of your program must be able to execute it by passing in the names of two data files that the system is to use. You need to check that exactly 3 command line arguments are entered. Your program will be run using these command line arguments:

[s3344949@csitprdap02]$  ./ppd    

For example:

[s3344949@csitprdap02]$  ./ppd  stock .dat  coins .dat

REQ2: Load Data

Your program needs to be populated with the data provided in the 2 data files whose names are conveyed via the command line.  You will need to tokenize this data in order to load it into the system.  You may use the class definitions provided in the startup code to store your system data.  As part of this requirement you need to ensure that the specified files are valid (that is, they exist and the data contained in them matches the specification for this assignment). You need to abort the program and provide a suitable error message if this is not the case.

Item (or stock) File Format:

[ItemID] | [ItemName] | [ItemDesc] | [Price] | [NumberOnHand]

Please note that the Price is stored as numbers delimited by the‘.’.  The number to the left of the‘. ’is the dollars and the number to the right will be the cents, for example:

I0001 |Meat  Pie |Yummy  Beef  in  Gravy  surrounded  by  pastry|3 .50 |50

Where the 3 represents the dollar component and the 50 represents the cents component of the price. A missing ‘.’from the price should be considered a data error.

You must ensure that items are inserted in the linked list sorted by name.

Money data file format:

[denomination],[quantity]

That is, there will be a row for each value of money that exists and the system will have an amount of each denomination. For example:

1000,3

500,4

200,20

100,30

50,5

20,3

10,40

5,20

This means that the system currently has 3 x 10 dollar notes, 4 x 5 dollar notes, 20 x 2 dollar coins, etc. Note that the above denominations are the only valid denominations for your vending machine. The vending machine does not accept $20 or $50 notes.  A valid file will always contain exactly 8 denominations, with no repeated denominations. If you wanted to initialise the vending machine with no change then the valid way to do that would be:

1000,0

500,0

200,0

100,0

50,0

20,0

10,0

5,0

Please note that you cannot assume that the data contained in these files are valid. Some examples (this is not a complete list) might be, there may be lines with too many or too few fields, and the data in each field may not be of the correct type, range and/or length.

Sample (valid) data files have been provided with the startup code. Make sure that your program works with at least these files.  We will also be testing your program with invalid data in the data files.  We recommend that you get your program working for the (valid) provided data files first. Then spend some time testing for invalid files after you have completed most/all of the remainder of the assignment.

You should validate the contents of the files when loading.  Please note that we may feed in file names when testing that don’t end in ’.dat’, so please don’t validate for that.  Likewise, you cannot assume the data files will be in the same directory as the executable, nor that we will have the same directory structure as you.

REQ3: Display Main Menu

Your program must display an interactive menu displaying 9 options. Your menu should look like this:

Main  Menu:

1 .Display  Items

2 .Purchase  Items

3 .Save  and  Exit

Administrator-Only  Menu:

4 .Add  Item

5 .Remove  Item

6 .Display  Coins

7 .Reset  Stock

8 .Reset  Coins

9 .Abort  Program

Select  your  option  (1-9):

Your program must print out the above options and then allow the user to select these options by typing the number and hitting enter. Upon selection of an option, an appropriate task will be carried out.

Upon completion of all options except Exit”, the user is returned to the main menu.  You can assume that customers can only see the first three menu options, and the administrator can see all of them.

The behavior of these menu options is described in following requirements from REQ4 to REQ12.

REQ4: Display Items

This option allows the user to request a display of the items available for purchase. This is the data loaded into the linked list in the REQ2. This requirement should behave as follows from the main menu, the user selects 1 and data should be displayed in the following format:

Items  Menu

----------

ID      |Name

-------------------------------------------------------------------

I0002 |Apple Pie

|18

|$ 3 .00

I0003 |Lemon  Cheesecake

|20

|$ 4 .00

I0004 |Lemon Meringue Pie

|20

|$ 3 .00

I0005 |Lemon Tart

|20

|$ 3 .75

I0001 |Meat Pie

|18

|$ 3 .50

REQ5: Purchase Item

This option allows the user to purchase an item from the menu.  This function is called from the main menu when the user has finally decided to purchase an item.  This function allows the user to pay for their item by collecting money from them, and adjusting balances within the system as appropriate.  Change is then given back to the customer, if appropriate. The number of items on hand should also be deducted. You should not allow an item to be purchased if there are 0 or less of that item on hand. For example, from the main menu, if the user selects 2, then the following should be displayed:

Select  your  option  (1-9):  2

Purchase  Item

-------------

Please  enter  the  id  of  the  item  you  wish  to  purchase:

If the user enters the item ID I0001, and subsequently $2, $3 and $5 as prompted, then the following should be displayed:

You  have  selected  "Meat  Pie  -  Yummy  Beef  in  . . .  by  pastry" .  This  will  cost  you  $  3 .50 . Please  hand  over  the money  -  type  in  the  value  of  each  note/coin  in  cents .

Press  enter  or  ctrl-d  on  a  new  line  to  cancel  this  purchase:

You  still  need  to  give  us  $3 .50:  200

You  still  need  to  give  us  $1 .50:  300

Error:  $3 .00  is  not  a  valid  denomination  of money .  Please  try  again .

You  still  need  to  give  us  $1 .50:  500

Here  is  your  Meat  Pie  and  your  change  of  $  3 .50:  $2  $1  50c

After which the user would be returned to the main menu.

When refunding money, you must display each note or coin separately used in the refund and you must ensure that prior to the sale that there is sufficient denominations in the system so that the customer is given the correct change. You must also subtract these coins from the coins array if a sale can take place. Note that coins entered to pay for an item can form part of the change that is given to the customer if that is required to give the customer the smallest amount of change possible.  If ppd cannot give correct change then the sale should not occur, and your program should display an appropriate message explaining why.

If the user presses enter on a new line, refund all the coins/notes they have entered so far and return them to the main menu. If Ctrl-d is entered, then exit the program.

REQ6: Save and Exit

You must save all data to the data files that were provided on the command line when the program loaded up. When the saving is completed, you must have the program exit. The specifications mentioned for each file must be maintained and the program must be able to load up your files as easily as it loaded up the files that we have provided you with. Also, at this point, once you have implemented dynamic memory allocation, you must free all memory allocated and exit the program.  A program which does everything but exit the program will still lose marks, as much as a program that does not implement any other requirement.

REQ7: Add Item

This option adds an item to the system.  When the user selects this option, the system should generate the next available item id and associate that with this item.  The user should then be prompted for the Name, Description and Price (a valid amount of money in dollars and cents). The item should then be allocated the default“on hand” value specified in the startup code.  The new item id shall have an‘I’prepended to it and will be 5 characters long. For example:

The  id  of  the  new  stock  will  be:  I0006

Enter  the  item  name:  Baklava

Enter  the  item  description:  rich,  sweet  pastry made  of  layers  of  filo  filled  with  chopped nuts  and  sweetened  and  held  together  with  syrup  or  honey .

Enter  the  price  for  the  item:  8 .00                                                                                                         This  item  "Baklava  -  rich,  sweet  pastry made  of  layers  of  filo  filled  with  chopped  nuts and  sweetened  and  held  together  with  syrup  or  honey . "  has  now  been  added  to  the menu .

Please note that the price entered for an item must have a dollars and a cents component as above.

REQ8: Remove Item

Remove an item from a category and delete it from the system, including free memory that is no longer being used. For example,

Enter  the  item  id  of  the  item  to  remove  from  the menu:  I0001

"I0001  -  Meat  Pie  -  Yummy  Beef  in  Gravy  surrounded  by  pastry"  has  been  removed  from  the system .

REQ9: Reset Stock Count

This option will require you to iterate over every stock in the list and set its‘on hand’ count to the default value specified in the startup code. You should display a message once this is done such as

“All  stock  has  been  reset  to  the  default  level  of  X”

where X is the default stock level specified in the startup code.

REQ10: Reset Coin Count

This option will require you to iterate over every coin in the coin list and set its ‘count’to the default value specified in the startup code. You should display a message once this is done such as

“All  coins  have  been  reset  to  the  default  level  of  X”

where X is the default amount of coins specified in the startup code.

REQ11: Display Coins

This option will require you to display the coins as follows. In particular, the counts of coins should be correctly aligned, and they should be sorted from lowest to highest value:


Coins  Summary

-------------

Denomination        |        Count

---------------------------

5 Cents

10  Cents

20 Cents

50 Cents

1 Dollar

2 Dollar

5 Dollar

10 Dollar

|

|

|

|

|

|

|

|

20

40

3

1

28

16

2

5

REQ12: Abort

This option should terminate your program. All program data will be lost. You should also be freeing memory at this point as well.

REQ13: Return to Menu Functionality

Your program should allow the user to return to the main menu at any point during these options.  The user can do this by hitting enter on an empty line.  If the user is in the middle of a transaction, that transaction should be cancelled, and money refunded.

REQ14: Memory Leaks and Abuses

The startup code requires the use of dynamic memory allocation. Therefore, you will need to check that your program does not contain memory leaks. Use the following:

valgrind –-leak-check=full –-show-leak-kinds=all    

to check for memory leaks. Marks will only be awarded for this requirement if the feedback valgrind provides reports zero memory leaks and no other memory related problems.

Another common problem in is memory abuses. These are inappropriate accesses such as reading from unini- tialized memory, writing to memory addresses you should not have access to and conditional statements (if, while, etc) that depend on uninitialized memory. You can test for these again by using valgrind:

valgrind –-track-origins=yes    

Sample Executable

An executable of the program with most of the above-mentioned functionalities is provided.  You can access and run the sample executable file directly on the school teaching server (e.g., via PuTTy on Windows) at the following location:  ∼/KDrive/SEH/SCSIT/Students/Courses/COSC1076/apt/ppd .  Once logged in with your RMIT credential, you can just cd into this folder, and follow the readme .txt file to run the executable file ppd.

3 Deliverables

3.1 Mandatory Requirements

As part of your implementation, you must:

• Implement your own Linked List.

• Use your Linked List implementation to store the items for ppd.

• You may only use the C++14 standard library. You may not incorporate any additional libraries. If you fail to comply with these mandatory requirements, marks will be deducted.

3.2 Milestone 1: Test Cases (Group Component)

For Milestone 1, you must develop test cases for your ppd implementation, including your enhancements. These test cases will help ensure that your ppd implementation is correct.

For a single test case, following 3 files need to be provided:

1. .input - Input to provide to the ppd program via stdin.

2.   .output - Expected output from the ppd program on stdout.

3. .expcoins - Expected output saved coin file when exiting ppd program.

Likewise if you have tests for the stock file, follow the above naming convention for your tests.

A test is run using the following sequence of commands.

./ppd  stock .dat  coins .dat  < .input  >   .actual_ppd_out diff  -w   .output   .actual_ppd_out

diff  -w  -y   .expcoins  

If the first diff command displays any output, then the test has failed. This command checks to see if two files have any differences. The -w options ignores any white-space.

The second diff command checks if two coin files (expected vs actual) have any differences.

You should aim with your tests to thoroughly test all the functionality of your program. If you write insufficient tests, your program may fail our tests when we assess you.

3.3 Milestone 2: Basic ppd Implementation (Group Component)

For Milestone 2, your group must implemented the base ppd program as described in Section 2. Section 2 lists the components that your group must implement.  Generally, it is up to your group to decide the best way to implement these components. However, there are some important requirements that your group must satisfy.

Aspects of this specification are flexible and open to your interpretation.   It is up to your group to determine the best course of action. You will need to analyse and justify your choices in the report.

Your group will also need to consider the data structures that are used to represent aspects of ppd, and functionality. It is up to your group to make this decision provided that you meet the requirements in Section 3.1. In your report your group will be marked on your analysis of the above choices.

Finally, remember to do the the group contribution spreadsheet described in 5.3 - fill this in on a weekly basis so it is accurate.

3.3.1    Group Demonstration

Your group is required to attend an assignment demonstration in Week 10 lab session . Your group will be required to demonstrate REQ5, 6, 8 and 9 in this demonstration using test cases you developed from Milestone 1. Please note that this includes implementation of any requirements that these options depend upon.

Each presentation should be around 12 minutes (for a group of 4), with an emphasis on showing what the group has done collectively as a team, as well as contribution from each individual to the project so far. Group work will be evaluated (see Section 8), and poor group work may result in mark deduction for individuals in the team (Section 7.3). You should also be ready to answer any additional questions about design and implementation from your tutor.

3.3.2    Group code and Test Cases

The deadline for submitting your group’s Milestone 1  (test cases) and Milestone 2  (code for the ppd base implementation) is the end of Week 10 (11.59pm, Friday 12 May 2023 (Week 10)).  See detailed information regarding submission instructions on Canvas.