You are on page 1of 15

PROJECT REPORT

Department of Applied Mathematics


Delhi Technological University(Formerly Delhi College of Engineering)
Bawana road, Delhi-110042

Submitted by-
SAHIL(2K19/MC/112)
SAMEER KUMAR(2K19/MC/113)
Delhi Technological University
(Formerly Delhi College of Engineering)
Bawana road, Delhi-110042

Candidate Declaration

We, Sahil(2K19/MC/112) and Sameer Kumar (2K19/MC/113) of


B.Tech Mathematics and Computing, hereby declare that the project
report entitled __________submitted to Department of Applied
Mathematics, Delhi Technological University, Delhi in partial fulfilment
of the requirements for the award of degree of Bachelor of Technology
is original and not copied from any source without proper citation. This
work has not previously formed the basis for the award of any degree,
Fellowship or other similar title or recognition.

Date 18/04/2022
ACKNOWLEDGEMENT

We would like to express our special thanks of gratitude to ________


who gave us the golden opportunity to do this wonderful project on
____________ which also helped us in gaining knowledge on many new
things and perform a detailed study on it. His instructions and
suggestions have served as the major contributor towards the completion
of the project .

Secondly, we would like to thank all our friends who helped me in


completing this project and we would also like to express our thanks to
all the sources and websites that provided us with the knowledge to
complete this project successfully.
Introduction

Deterministic Finite Automata, or DFAs, have a rich background in terms of the


mathematical theory underlying their development and use. However, this project
will focus on examining real-world applications of DFAs to gain an appreciation of
the usefulness of this theoretical concept. DFA uses include protocol analysis, text
parsing, video game character behavior, security analysis, CPU control units,
natural language processing, and speech recognition. Additionally, many simple
(and not so simple) mechanical devices are frequently designed and implemented
using DFAs, such as elevators, vending machines, and traffic-sensitive traffic
lights.
Our project is based on vending machines, which need to remember how much
money the user has input.
A finite state machine (sometimes called a finite state automaton) is a
computation model that can be implemented with hardware or software and can be
used to simulate sequential logic and some computer programs. Finite state
automata generate regular languages. Finite state machines can be used to model
problems in many fields including mathematics, artificial intelligence, games, and
linguistics.

Finite state machines (FSMs) are used in lots of different situations to model
complex entity state.

An entity may transition from one state to another, or it may remain in its current
state. The arrows denote transitions. The conditions under which a transition
should take place will need to be coded into the FSM itself.
Pure FSM form is composed of:
• A set of states
• A set of possible inputs (or events)
• A set of possible outputs (or actions)
• A transition function: – Given the current state and an input: defines the output
and the next state
States:
• Represent all possible “situations” that must be distinguished
• At any given time, the system is in exactly one of the states
• There is a finite number of these states

How do we relate FSMs to Control?


• States are our memory of recent inputs
• Inputs are some processed representation of what the sensors are observing
• Outputs are the control actions

Finite State Machine (FSM) of a custom vending machine implemented in C++


program.

When the user puts in money, money counter tells the control unit, the amount of
money inserted in the Vending Machine. When the user presses the button to
purchase the item that he wants, the control unit turns on the motor and dispenses
the product if correct amount is inserted. If there is any change, machine will
return it to the user. The machine will demand for servicing when the products are
not available inside the machine.
Desc: Simple 4 state finite state machine for simulating a console application
vending machine that allows user to pay with points, update wallet, and keep track
of inventory.
#include <iostream>
#include <string>

using namespace std;

enum VendingMachineState {
SELECT, QUANTITY, CALCULATE, UPDATE
};

enum Brand {
COKE = 100, PEPSI = 200, SEVENUP = 300
};

struct Student {
string name;
int points;
};

struct Soda {
Brand brandName;
int inventory;
int price;
};
int main() {

//Initial Vending Machine State is SELECT. Update upon state change.


VendingMachineState currentState = SELECT;

//Fill up our vending machine with Sodas.


Soda vendingMachine[3];
//Load Up with COKE
vendingMachine[0].brandName = COKE;
vendingMachine[0].inventory = 10;
vendingMachine[0].price = 1000;
//Load Up with PEPSI
vendingMachine[1].brandName = PEPSI;
vendingMachine[1].inventory = 10;
vendingMachine[1].price = 2000;
//Load Up with SEVENUP
vendingMachine[2].brandName = SEVENUP;
vendingMachine[2].inventory = 10;
vendingMachine[2].price = 3000;

Soda selectedSoda;
Student eric;
eric.name = "Eric";
eric.points = 100000; //100,000 Points in Wallet
while (true) {
switch (currentState) {
case SELECT:
//1. Display the current status for the vending machine and the
student's wallet.
cout << "<<<<<---CURRENT STATUS--->>>>>" << endl;
cout << "[[[Vending Machine]]]" << endl;
for (int i = 0; i < 3; i++) {
cout << vendingMachine[i].brandName << " has " <<
vendingMachine[i].inventory << " drinks, and each costs " <<
vendingMachine[i].price << " points." << endl;
}
cout << "[[[Student]]]" << endl;
cout << eric.name << " has " << eric.points << " points total."
<< endl;
cout << "<<<<<---END STATUS--->>>>>" << endl << endl;
//2. Ask the user what drink they want.
cout << "Please select a drink from the following available
options: " << endl;
//3. Display the soda names and corresponding ID values.
cout << "COKE = 100\nPEPSI = 200\nSEVENUP = 300" <<
endl;
//4. User inputs the drink.
int selectedDrink;
cin >> selectedDrink;
//5. If valid drink selected, move to QUANTITY state; else, go
back to SELECT state.
switch (selectedDrink) {
case COKE:
cout << "You have selected COKE" << endl;
selectedSoda.brandName = COKE;
currentState = QUANTITY;
break;
case PEPSI:
cout << "You have selected PEPSI" << endl;
selectedSoda.brandName = PEPSI;
currentState = QUANTITY;
break;
case SEVENUP:
cout << "You have selected SEVENUP" << endl;
selectedSoda.brandName = SEVENUP;
currentState = QUANTITY;
break;
default:
cout << "Invalid Drink Selected!" << endl;
currentState = SELECT;
break;
}
break;
case QUANTITY:

cout << "How many drinks would you like? ";


int orderQuantity;
cin >> orderQuantity;

cout << "Your order has been received. You placed an order "
<< orderQuantity << " soda(s)." << endl;

switch (selectedSoda.brandName) {
case COKE:
if (orderQuantity < 0 || orderQuantity >
vendingMachine[0].inventory) {
cout << "Not Enough " <<
selectedSoda.brandName << " In Stock" << endl;
currentState = SELECT;
cout << endl << endl;
}
else {
currentState = CALCULATE;
}
break;
case PEPSI:
if (orderQuantity < 0 || orderQuantity >
vendingMachine[1].inventory) {
cout << "Not Enough In Stock" << endl;
currentState = SELECT;
cout << endl << endl;
}
else {
currentState = CALCULATE;
}
break;
case SEVENUP:
if (orderQuantity < 0 || orderQuantity >
vendingMachine[2].inventory) {
cout << "Not Enough In Stock" << endl;
currentState = SELECT;
cout << endl << endl;
}
else {
currentState = CALCULATE;
}
break;
default:
cout << "Invalid Amount Received." << endl;
break;
}

break;
case CALCULATE:
cout << "The total cost for your soda is: ";
int cost;
switch (selectedSoda.brandName) {
case COKE:
cost = vendingMachine[0].price * orderQuantity;
cout << cost << endl;
break;
case PEPSI:
cost = vendingMachine[1].price * orderQuantity;
cout << cost << endl;
break;
case SEVENUP:
cost = vendingMachine[2].price * orderQuantity;
cout << cost << endl;
break;
default:
cout << "Error!" << endl;
break;
}
int payment;
cout << "Please type in your payment: ";
cin >> payment;

if (payment > eric.points || payment < cost || payment <= 0) {


cout << "You don't have enough money!" << endl;
currentState = SELECT;
cout << endl << endl;
}
else {
eric.points = eric.points - payment;
int change = payment - cost;
cout << "Thank you! Your change is " << change << "
points." << endl;
eric.points = eric.points + change;
currentState = UPDATE;
}

break;
case UPDATE:

switch (selectedSoda.brandName) {
case COKE:
vendingMachine[0].inventory =
vendingMachine[0].inventory - orderQuantity;
currentState = SELECT;
cout << endl << endl;
break;
case PEPSI:
vendingMachine[1].inventory =
vendingMachine[1].inventory - orderQuantity;
currentState = SELECT;
cout << endl << endl;
break;
case SEVENUP:
vendingMachine[2].inventory =
vendingMachine[2].inventory - orderQuantity;
currentState = SELECT;
cout << endl << endl;
break;
default:
cout << "Error" << endl;
currentState = SELECT;
cout << endl << endl;
break;
}

cout << "Inventory Updated" << endl;


currentState = SELECT;
cout << endl << endl;

break;
default:
cout << "Error! Invalid State Detected." << endl;
break;
}
}
return 0;

You might also like