Vous êtes sur la page 1sur 4

CSC201: Structured Programming

(Group) Assignment#2
Due on November 27, 2014
Point of Sale (POS) Machine
Note: This is a group activity of 2 students per group. Submission of the
solution report is only through blackboard
Objectives
In this assignment, you will practice:
Functions
Integrating Loops with Functions
Description of the Problem
A point of sale machine shown below is found in all retail
stores. The machine has a barcode reader attached to it and
a touch screen for the user to interact with. When a new
customer comes to the checkout counter, the cashier of the
machine interacts with the menu on the touch screen. For
example, he or she may press on a new sale button to start a
new sale. The operator then starts to enter the barcodes of
the items in the customers basket or trolley. As soon as an
item is scanned, the price of that item is added to the
subtotal. When the items are all scanned, the cashier presses on another button to end the
same. The total amount of the transaction is shown to the customer and cashier. The customer
hands over the money to the cashier who enters the amount received from the customer to see
how much to return to them.
We want to write the program that runs on this point of sale machine with barcode
and practice functions in the process. For security, we will require the cashier to enter a
passcode before they can access the machine. At the end of day, the cashier presses on a
button to find the total for the entire day, which should be inside the machine. After verifying
the amount, they can exist the system by pressing on another button. The following is the
prices of the items in the store.
Barcode
Price (AED)
123
10.5
124
5.99
125
1.99
126
0.99
Study the given code and complete the missing NewSale function. Also provide another
function getPrice that will return the price of a particular barcode (provided as a parameter
value). The getPrice function will be called by the NewSale function.

The following shows a sample output. Note that the correct passcode/PIN is 1234.
Please enter the PIN
1111
Passcode incorrect
Please enter the PIN
2222
Passcode incorrect
Please enter the PIN
1234
Please choose from the following list
1. New Sale
2. End Day
3. Exit
1
Barcode> 123
Total = 10.5
Barcode> 124
Total = 16.49
Barcode> 123
Total = 26.99
Barcode> 123
Total = 37.49
Barcode> -1
Total = 37.49
Enter amount paid
40
Return 2.51
Please choose from the following list
1. New Sale
2. End Day
3. Exit
1
Barcode> 123
Total = 10.5
Barcode> 123
Total = 21
Barcode> -1
Total = 21
Enter amount paid
30
Return 9
Please choose from the following list
1. New Sale
2. End Day
3. Exit
2
Total for Day 58.49
Please choose from the following list
1. New Sale

2. End Day
3. Exit
3
Program ended with exit code: 0

#include <iostream>
using namespace std;
void printMenu()
{
cout<<"Please choose from the following list"<<endl;
cout<<"1. New Sale"<<endl;
cout<<"2. End Day"<<endl;
cout<<"3. Exit"<<endl;
cout<<"";
}
bool verifyPasscode(int passcode)
{
return passcode == 1234;
}
int promptPasscode()
{
int passcode;
cout<<"Please enter the PIN "<<endl;
cin>>passcode;
return passcode;
}
void userLogin()
{
int userCode = promptPasscode();
while(!verifyPasscode(userCode))
{
cout<<"Passcode incorrect"<<endl;
userCode = promptPasscode();
}
}
// define a function called getPrice to return the price of a given barcode
//

double NewSale()
{
double total=0;
/* complete this function. It should repeatedly ask user to enter a barcode until the
user enter -1 for a barcode (to stop the sale). Each time the user enters a barcode,

the getPrice function should be called and the result should be added to total and the
new total should be printed. After the user enter -1 in place of barcode, the function
should ask user for the amount paid and print the difference of amount paid and total
(balance or change to return). The function will then return the total as its return
value. */
return total;
}
int main(int argc, const char * argv[])
{
userLogin();
int choice = 0;
double daytotal = 0.0;
while(choice!=2)
{
printMenu();
int choice;
cin>>choice;
switch(choice)
{
case 1:
daytotal+=NewSale();
break;
case 2:
cout<<"Total for Day "<<daytotal<<endl;
break;
case 3:
return 0;
break;
default:
cout<<"Wrong Choice"<<endl;
}
}
return 0;
}

Vous aimerez peut-être aussi