0% found this document useful (0 votes)
34 views

Assignment 2

The document describes an ice cream machine program with the following requirements: 1. Show the user the brands available and allow them to select one 2. Show the cost of the selected item 3. Accept payment from the user 4. Release the item if payment is sufficient It then provides C++ classes to model the money register component and product types, with functions for checking balances, making purchases, and retrieving item details. The main function brings these components together by displaying options, processing a sale, and updating quantities.

Uploaded by

sultan ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Assignment 2

The document describes an ice cream machine program with the following requirements: 1. Show the user the brands available and allow them to select one 2. Show the cost of the selected item 3. Accept payment from the user 4. Release the item if payment is sufficient It then provides C++ classes to model the money register component and product types, with functions for checking balances, making purchases, and retrieving item details. The main function brings these components together by displaying options, processing a sale, and updating quantities.

Uploaded by

sultan ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

aWrite a program for a ice-cream machine.

The machine should be able to


sell icecreams and it should perform below tasks.
The program should do the following:
1. Show the user the different brands sold by the ice-cream machine.
2. Let the user make the selection.
3. Show the user the cost of the item selected.
4. Accept money from the user.
5. Release the item.
The machine has two main components: a built-in cash register and several
dispensers to hold and release the brands.

Define class moneyRegister in C++ with the following descriptions :


Private Members:
moneyOnHand of type integer
Public Members:
A default constructor moneyRegister() sets the money in the register to 500.
A constructor moneyRegister(int) sets the money in the register to a specific
amount.
A function getCurrentBalance() which returns value of moneyOnHand
A function acceptAmount(int) to receive the amount deposited by the user
and update the amount in the register
Define class productType in C++ with the following descriptions :
Private Members:
numberOfItems of type integer
cost of type integer
Public Members:
A default constructor productType () sets the cost and number of items in
the product to 50 each.
A constructor productType (int,int) sets the cost and number of items in the
product to the values specified by the user.
A function getNoOfItems() to return the value of numberOfItems.
A function getCost() to return the value of cost.
A function makeSale() to reduce the number of items by 1.
When the program executes, it must do the following:
1. Show the different brands sold by the ice-cream machine.
2. Show how to select a particular product.
Once the user has made the appropriate selection, the ice-cream machine
must act accordingly. If the user has opted to buy a product and that
product is available, the ice-cream machine should show the cost of the
product and ask the user to deposit the money. If the amount deposited is at
least the cost of the item, the ice-cream machine should sell the item and
display an appropriate message.
Divide this program into three functions: showSelection, sellProduct, and
main.
The function sellProduct must have access to the product holding the product
(to decrement the number of items in the product by 1 and to show the cost
of the item) as well as the money register (to update the money). Therefore,
this function has two parameters: one corresponding to the product and the
other corresponding to the money register.
code

#include<iostream>

using namespace std;

void showSelection(int);

void sellProduct(int);

void showSelection(int i)

int num1, num2, num3, num4;

num1 = 100;

num2 = 200;

num3 = 300;

num4 = 400;

cout<<" \tBrands sold by the ice cream machine are"<<endl<<endl;

cout<<"1- Brand A"<<endl;

cout<<"2- Brand B"<<endl;

cout<<"3- Brand C"<<endl;

cout<<"4- Brand D"<<endl<<endl;

cout<<"select brand by choosing number of that brand"<<endl<<endl;

cout<<"select number: ";

cin>>i;

if (i==1)

cout<<"price of Brand A is "<<num1<<"Rs"<<endl;

else if (i==2)

cout<<"price of Brand A is "<<num2<<"Rs"<<endl;

else if (i==3)
{

cout<<"price of Brand A is "<<num3<<"Rs"<<endl;

else if (i==4)

cout<<"price of Brand A is "<<num4<<"Rs"<<endl;

else

cout<<"you entered wrong number"<<endl;

class moneyRegister{

private:

int moneyOnHand;

public:

moneyRegister()

moneyOnHand = 500;

moneyRegister(int x)

moneyOnHand= x;

int getCurrentBalance()

return moneyOnHand;

void acceptAmount(int amountIn)

{
cout<<"enter money: ";

cin>>moneyOnHand;

moneyOnHand +=amountIn;

cout << "Collect your item at the bottom and " << "enjoy." << endl;

};

class productType{

private:

int numberOfItems, cost;

public:

productType()

numberOfItems = 50;

cost = 50;

productType(int a, int b)

numberOfItems = a;

cost = b;

getNoOfItems()

return numberOfItems;

getcost()

return cost;

void makesale()

{
numberOfItems--;

};

int main()

int a;

showSelection(a);

moneyRegister R1;

R1.acceptAmount(500);

productType P1(50, 50);

P1.makesale();

return 0;

You might also like