Add project source files

main
Ilja 2024-02-09 10:15:06 +02:00
parent a240b2534d
commit 3799dd9753
6 changed files with 519 additions and 20 deletions

140
Team_Project/ATM.h 100644
View File

@ -0,0 +1,140 @@
#pragma once
#include <iostream>
#include <windows.h>
#define HARDCODED_MAGIC_NUMBER 365
namespace ATM{
using std::endl,std::string;
using std::cout;
using std::cin;
int main()
{
int choice = 0;//Data validation pirmejam menu
do
{
cout << "\nMenu\n" << endl
<< "1 - Quit\n"
<< "2 - withdraw\n"
<< "3 - take a loan\n"
<< "4 - deposit\n"
<< "5 - account ballance\n"
<< "6 - MAINTENANCE\n"
<< "Enter your choice and press return: ";
std::cin >> choice;
switch(choice)
{
case 1://power off opcija
cout << "Farewell";
return 0;
case 2://naudas izsniegšanas kods
cout << "how much would you like to withdraw?\n";
int money;//kods kas nosaka vai nauda kontā ir pietiekami, lai izsniegtu
cout << " Enter the amount: ";
std::cin >> money;
if(money >= HARDCODED_MAGIC_NUMBER) {
cout << "You dont have the funds for this action\n";
break;
} else
{
cout << "Your cash has been delt\n";
}
break;
case 3://kods priekš lone funkcijas
int loan;
cout << "insert the amount that you would like to borrow: ";
std::cin >> loan;
if(loan >= 0) {
cout << "Thank you for choosing markuss bank for your loans...\nCounting your money\nSucces\n";
break;
} else
{//neļauj ievadīt negatīvus skaitļus
cout << "\nError\n";
}
break;
case 4:
cout << " insert your card\n";
int cardInfo;// attiecīgais int priekš noteiktās darbības
cout << " Enter the amount you would like to deposit: ";
std::cin >> cardInfo;
if(cardInfo >= 0)
{
cout << "Thank you for choosing markuss bank the only bank you need. The funds have been added to your account\n";
break;
} else
{//neļauj ievadīt negatīvus skaitļus
cout << "\nError\n";
}
break;
case 5://balance info
cout << "\nYou have 365$\n";
break;
case 6:
int MAINTENANCE();//kods kas ļauj pikļūt pie MAINTENANCE MODE
{
int msgboxID = MessageBox(
NULL,
(LPCWSTR)L"\nDo you want to enter MAINTENANCE MODE?",
(LPCWSTR)L"",
MB_ICONASTERISK | MB_YESNO | MB_DEFBUTTON2
);
switch(msgboxID)
{
case IDNO:
break;
case IDYES:
string username;
string password;
int otherchoice = 0;
cout << "Please input admin username : "; cin >> username;
cout << "Please input admins password : "; cin >> password;
if(username == "Markuss") {
if(password == "123") {
cout << "you are online admin\n" //ievadot pareizos datus atveras jauns menu
<< "\nAdmins Menu\n\n"
<< "1 - System requirement info\n"
<< "2 - Turn of the device\n"
<< "Enter your choice and press return: ";
std::cin >> otherchoice;
switch(otherchoice)
{
case 1:
cout << "\n*standard atm stuff*\n";
break;
case 2:
return 0;
}
} else
{
cout << "Invalid password! " << endl;
}
} else
{
cout << "Invalid username! " << endl;
}
break;
}
break;
}
break;
}
}
while(choice != 1);
}
}

View File

@ -0,0 +1,306 @@
#pragma once
#include <windows.h>
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <string>
#include <algorithm>
#include <fstream>
#include <ctime>
namespace Coffee {
#pragma warning(disable : 4996)
int DisplayMessageBox(LPCWSTR msg) {
int msgboxID = MessageBox(
NULL,
msg,
(LPCWSTR)L"Error",
MB_ICONERROR | MB_RETRYCANCEL | MB_DEFBUTTON2
);
switch(msgboxID) {
case IDCANCEL:
break;
case IDRETRY:
break;
}
return msgboxID;
}
bool isString(std::string s) {
for(int i = 0; i < s.length(); i++) {
if(isdigit(s[i])) {
return false;
}
}
return true;
}
int inputInt() { //we use it to input int
int x;
while(!(std::cin >> x)) {
std::cout << "Error!\nPlease enter number!\n";
std::cin.clear();
std::cin.ignore(9223372036854775807, '\n'); //cin.ignore(numeric_limits<std::streamsize>::max()); (max possible long long)
}
return x;
}
std::string inputString() { //we use it to input string
std::string s;
std::cin >> s;
return s;
}
class Drink {
public:
int price;
std::string name;
std::string view;
Drink(std::string s, double p,std::string n) : //constructor
view(s),
price(p),
name(n)
{}
bool canBuy(double cash) { //check if we can buy drink
if(price <= cash) {
return true;
}
return false;
}
};
//Initialize Drink type objects, we input ascii art, price, name
Drink tea(" ) (\n ( ) )\n ) ( (\n _______)_\n .-'---------|\n( C|/\\/\\/\\/\\/|\n '-./\\/\\/\\/\\/|\n '_________'\n '-------'\n", 200, "Tea");
Drink coffee(" )))\n (((\n +-----+\n | |]\n `-----'\n___________\n`---------'\n", 200, "Coffee");
Drink hotChocolate(" ( (\n ) )\n ........\n | |]\n \\ /\n `----'\n", 300, "Hot Cohocolate");
Drink latte(" /#/\n _---------//_\n ( / )\n /=============\\\n(///////////////)\n \\ /\n C===========O \n", 200, "Latte");
Drink cappucino(" ..\n .. ..\n ..\n ..\n ..\n ..\n ..\n## .. ####\n##.............## ##\n##.............## ##\n##.............## ##\n##.............###\n ##...........##\n #############\n #############\n#################\n", 250, "Cappucino");
class CoffeeMachine {
private:
bool admin;
bool saveReceipt;
int receiptCount;
public:
CoffeeMachine() : //constructor
admin(false),
saveReceipt(false),
receiptCount(0)
{}
void pour(Drink& drink) { //show drink
std::cout << "Pouring the drink...\n";
std::cout << drink.view;
}
void buy(Drink& drink) { //buy drink
if(saveReceipt) { //save receipt
receiptCount++;
std::ofstream receiptFile; //create ofsteam object
//string name = "Receipt No"+to_string(receiptCount);
//name.append(".txt");
std::string name ="receipt.txt";
receiptFile.open(name,std::ios::app); //create and open new receipt file
time_t timeNow = time(0);
receiptFile << "Receipt:\n";
receiptFile << "Time: " << ctime(&timeNow); //write currect time to receipt
receiptFile<<"You ordered: "<<drink.name<<std::endl; //write drink name to receipt
receiptFile << "The drink cost: " << drink.price << " rubles\n\n"; //write drink cost to receipt
receiptFile.close(); //close file
std::cout << "Receipt Saved\n";
}
pour(drink);
}
void adminMode() { //enter admin mode
admin = true;
}
bool isAdminMode() { //check if in admin mode
return admin;
}
void toggleSaveReceipts() { //toggle if we save recepits
if(admin) {
if(!saveReceipt) {
saveReceipt = true;
std::cout << "Coffee machie now saves receipts!\n";
} else {
saveReceipt = false;
std::cout << "Coffee machie now dont saves receipts!\n";
}
} else {
std::cout << "You are not in admin mode!\n";
}
}
};
CoffeeMachine cm; //initialize CoffeeMachine type object
class Client {
private:
void continueBuyingDrink(Drink& drink) { //call this method if client has insufficient funds to buy drink
while(!drink.canBuy(cash)) {
std::cout << "Insufficient funds!\n";
std::cout << "Do you want to deposit funds and buy the drink?\t Input: 1-for yes\t 2-for no\n";
int choice;
choice = inputInt();
int money;
switch(choice){
case 1:
std::cout << "How much do you want to deposit?\n"; //deposit
money = inputInt();
deposit(money);
printf("You now have %d rubles\n", cash);
break;
case 2:
return;
default:
std::cout << "Incorrect input\n";
break;
}
}
cash -= drink.price;
cm.pour(drink);
}
int cash;
public:
Client() { //constructor
cash = 0;
}
void setCash(int n) {
cash = n;
}
int getCash() {
return cash;
}
void deposit(int n) {
cash += n;
}
void buyDrink(CoffeeMachine& cm) { //call if client buys a drink
int choice;
std::cout << "What do You want to drink?\n1-Tea 2-Coffee 3-Hot Chocolate 4-Latte 5-Cappucino 6-Cancel\n";
printf("You now have %d rubles\n", cash);
choice = inputInt();
switch(choice) {
case 1:
printf("The drink costs: %d\n", tea.price);
if(tea.canBuy(cash)) { //check if we can buy drink, decrease clients money
cash -= tea.price;
cm.buy(tea);
} else {
continueBuyingDrink(tea);
}
break;
case 2:
printf("The drink costs: %d\n", coffee.price);
if(tea.canBuy(cash)) {
cash -= coffee.price;
cm.buy(coffee);
} else {
continueBuyingDrink(coffee);
}
break;
case 3:
printf("The drink costs: %d\n", hotChocolate.price);
if(tea.canBuy(cash)) {
cash -= hotChocolate.price;
cm.buy(hotChocolate);
} else {
continueBuyingDrink(hotChocolate);
}
break;
case 4:
printf("The drink costs: %d\n", latte.price);
if(tea.canBuy(cash)) {
cash -= latte.price;
cm.buy(latte);
} else {
continueBuyingDrink(latte);
}
break;
case 5:
printf("The drink costs: %d\n", cappucino.price);
if(tea.canBuy(cash)) {
cash -= cappucino.price;
cm.buy(cappucino);
} else {
continueBuyingDrink(cappucino);
}
break;
case 6:
return;
default:
std::cout << "Wrong drink choice\n";
buyDrink(cm);
break;
}
printf("You now have %d rubles\n", cash);
}
};
Client client; //initialize Client type object
std::string password = "123qwe43"; //maintenance(admin) password
int main() {
std::cout << "Welcome to our coffee machine!\n\n";
while(true) {
std::cout << "You have a few options to choose from\n1 - check balance\n2 - replenish the balance(only credit card is accepted)\n3 - buy drink\n4 - input maintenance password\n5 - toggle receipt mode\n";
int choice;
choice = inputInt();
int cash;
std::string pass;
LPCWSTR msg;
msg = L"Do you want to try again?";
switch(choice) { //choices, client can make
case 1:
printf("You now have %d rubles\n", client.getCash());
break;
case 2:
while(true) {
cash = inputInt();
if(cash <= 0) {
std::cout << "You can not enter negative summ or 0!\nPlease input valid summ!\n";
} else {
client.deposit(cash);
printf("You now have %d rubles\n", client.getCash());
break;
}
}
break;
case 3:
client.buyDrink(cm);
break;
case 4:
if(cm.isAdminMode()) {
std::cout << "Already in admin mode!\n";
break;
}
while(true) {
std::cout << "Please input password\n";
pass = inputString();
if(pass == password) {
cm.adminMode();
std::cout << "You entered admin mode\n";
break;
} else {
std::cout << "Incorrect password\n";
}
if(DisplayMessageBox(msg) == IDCANCEL) {
break;
}
}
break;
case 5:
cm.toggleSaveReceipts();
break;
default:
std::cout << "Incorrect input\n";
break;
}
}
return 0;
}
}

View File

@ -0,0 +1,14 @@
#include "ATM.h"
#include "Coffee.h"
int main() {
srand(time(0));
if(rand()%2){
ATM::main();
} else{
Coffee::main();
}
return 0;
}

View File

@ -17,7 +17,6 @@
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
@ -53,27 +52,24 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared" >
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
@ -130,8 +126,13 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup></ItemGroup>
<ItemGroup>
<ClInclude Include="ATM.h" />
<ClInclude Include="Coffee.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Source.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@ -14,4 +14,17 @@
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ATM.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Coffee.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Source.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,25 @@
Receipt:
Time: Fri Jan 26 11:24:07 2024
You ordered: Tea
The drink cost: 200 rubles
Receipt:
Time: Fri Jan 26 11:24:08 2024
You ordered: Coffee
The drink cost: 200 rubles
Receipt:
Time: Fri Jan 26 11:24:09 2024
You ordered: Hot Cohocolate
The drink cost: 300 rubles
Receipt:
Time: Fri Jan 26 11:24:10 2024
You ordered: Latte
The drink cost: 200 rubles
Receipt:
Time: Fri Jan 26 11:24:12 2024
You ordered: Cappucino
The drink cost: 250 rubles