Basic framework for prototype implemented
This commit is contained in:
parent
c56b2434e1
commit
bc4343864e
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
11
libs/AtmAdmin.h
Normal file
11
libs/AtmAdmin.h
Normal file
|
@ -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
|
62
libs/Errorseal.h
Normal file
62
libs/Errorseal.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
//
|
||||
// Created by TheSkyWinds on 10/25/24.
|
||||
//
|
||||
|
||||
#ifndef ERRORSEAL_H
|
||||
#define ERRORSEAL_H
|
||||
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
namespace Error {
|
||||
// Clears the buffer for std::cin.
|
||||
inline void ignoreLine() {
|
||||
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::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
|
13
src/AtmAdmin.cpp
Normal file
13
src/AtmAdmin.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
42
src/main.cpp
42
src/main.cpp
|
@ -1,5 +1,45 @@
|
|||
#include <iostream>
|
||||
#include <cctype>
|
||||
|
||||
#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<char>(std::tolower(userChoice)), userInformation);
|
||||
|
||||
std::cout << userInformation << '\n'; // DEBUG
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user