From bc4343864e81a20df85e213c520d101bcc61a030 Mon Sep 17 00:00:00 2001 From: theskywinds Date: Wed, 28 May 2025 10:54:22 +0200 Subject: [PATCH] Basic framework for prototype implemented --- CMakeLists.txt | 9 +++++-- README.md | 2 +- libs/AtmAdmin.h | 11 +++++++++ libs/Errorseal.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ src/AtmAdmin.cpp | 13 ++++++++++ src/main.cpp | 42 +++++++++++++++++++++++++++++++- 6 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 libs/AtmAdmin.h create mode 100644 libs/Errorseal.h create mode 100644 src/AtmAdmin.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d5d4d9f..1987ec6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,13 @@ project(atm_admin_program) set(CMAKE_CXX_STANDARD 20) -add_executable(atm_admin_program - src/main.cpp) +add_executable(${CMAKE_PROJECT_NAME} + src/main.cpp + src/AtmAdmin.cpp) + +find_package(pugixml CONFIG REQUIRED) +target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE libs) +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE pugixml::static pugixml::pugixml) target_compile_options(${PROJECT_NAME} PRIVATE # Make all warnings into errors diff --git a/README.md b/README.md index b718db9..d90868b 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This program will be terminal-only. ## Current plans -- [ ] Allow the user to choose different options (Changing pin, name, etc) +- [x] Allow the user to choose different options (Changing pin, name, etc) - [ ] Make a prototype. Allow variables to be stored & displayed. - [ ] Intergrate it into XML. For now, only allow PIN & money to be changed. - [ ] Add a way to create new users. diff --git a/libs/AtmAdmin.h b/libs/AtmAdmin.h new file mode 100644 index 0000000..0e301cf --- /dev/null +++ b/libs/AtmAdmin.h @@ -0,0 +1,11 @@ + + +#ifndef ATMADMIN_H +#define ATMADMIN_H + +namespace AtmAdmin { + // startup() is inline because of how small it is. + char startup(); +} + +#endif //ATMADMIN_H diff --git a/libs/Errorseal.h b/libs/Errorseal.h new file mode 100644 index 0000000..9c8007c --- /dev/null +++ b/libs/Errorseal.h @@ -0,0 +1,62 @@ +// +// Created by TheSkyWinds on 10/25/24. +// + +#ifndef ERRORSEAL_H +#define ERRORSEAL_H + +#include +#include + +namespace Error { +// Clears the buffer for std::cin. + inline void ignoreLine() { + + std::cin.ignore(std::numeric_limits::max(), '\n'); + + } + +/* + * cinError() returns true if an error occurs. + * cinError() also clears up the error and buffer, so that the program can continue to work. + */ + inline bool cinError(){ + bool errorState{false}; + if (!std::cin) { + + if (std::cin.eof()) { + std::exit(0); // Shut down the program now + } + + std::cin.clear(); + ignoreLine(); + errorState = true; + } + return errorState; + } + +/* + * Throws a generic, undefined error message, but does the same as the function above. + * Primarily used for quick and easy debugging. + */ + + inline bool cinErrorVerbose() { + bool errorState{false}; + if (!std::cin) { + + if (std::cin.eof()) { + std::exit(0); + } + + std::cin.clear(); + ignoreLine(); + + std::cerr << "Whoops, you broke the program!\n"; + errorState = true; + } + return errorState; + } +} + + +#endif //ERRORSEAL_H diff --git a/src/AtmAdmin.cpp b/src/AtmAdmin.cpp new file mode 100644 index 0000000..02fbf0b --- /dev/null +++ b/src/AtmAdmin.cpp @@ -0,0 +1,13 @@ +#include + +namespace AtmAdmin { + char startup() { + char choice{}; + std::cout << "1. Change PIN\n" << "2. Change money\n" << "3. Change account name\n" << "Q. Exit the program\n\n"; + std::cout << ">: "; + + std::cin >> choice; + + return choice; + } +} diff --git a/src/main.cpp b/src/main.cpp index f67f8c5..0a5846c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,45 @@ #include +#include + +#include "AtmAdmin.h" + +bool handleUserInformation(char choice, std::string& information) { + switch (choice) { + case '1': + std::cout << "Enter new pin: "; + std::cin >> information; + break; + case '2': + std::cout << "Enter the amount you wish to have: "; + std::cin >> information; + break; + case '3': + std::cout << "Enter your new username: "; + std::cin >> information; + break; + case 'q': + return false; + default: + std::cout << "Invalid choice.\n"; + } + return true; +} int main() { - std::cout << "Hello, world!"; + bool continueLoop{true}; + + while (continueLoop) { + // startup() presents the user with the choices below, which are then stored and used by other functions. + // The other functions should handle invalid choices. + // ((1. Change pin || 2. Change money || 3. Change account name || Q. Exit the program)) + char userChoice{AtmAdmin::startup()}; + + // userInformation will later store information for the XML entry to save. + std::string userInformation{}; + + // Always returns true unless 'Q' is entered + continueLoop = handleUserInformation(static_cast(std::tolower(userChoice)), userInformation); + + std::cout << userInformation << '\n'; // DEBUG + } } \ No newline at end of file