A bunch of updates
This commit is contained in:
parent
df4bda7a3e
commit
8e07fdefe1
|
@ -13,20 +13,59 @@ find_package(pugixml CONFIG REQUIRED)
|
||||||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE libs)
|
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE libs)
|
||||||
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE pugixml::static pugixml::pugixml)
|
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE pugixml::static pugixml::pugixml)
|
||||||
|
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
# Check if we're using MinGW or compiling for Windows
|
||||||
# Make all warnings into errors
|
if(MINGW OR WIN32)
|
||||||
-Werror
|
# Windows/MinGW specific settings
|
||||||
|
target_compile_options(${PROJECT_NAME} PRIVATE
|
||||||
|
# Make all warnings into errors
|
||||||
|
-Werror
|
||||||
|
|
||||||
# Basic warning flags
|
# Basic warning flags
|
||||||
-Wall # Enable all common warnings
|
-Wall # Enable all common warnings
|
||||||
-Wextra # Enable extra warnings not covered by -Wall
|
-Wextra # Enable extra warnings not covered by -Wall
|
||||||
-Wpedantic # Issue warnings demanded by strict ISO C and ISO C++
|
-Wpedantic # Issue warnings demanded by strict ISO C and ISO C++
|
||||||
-pedantic-errors # Like -Wpedantic but errors instead of warnings
|
-pedantic-errors # Like -Wpedantic but errors instead of warnings
|
||||||
|
|
||||||
# Specific warning categories
|
# Specific warning categories
|
||||||
-Wshadow # Warn when a variable declaration shadows another
|
-Wshadow # Warn when a variable declaration shadows another
|
||||||
-Wcast-align # Warn for potential performance problems from memory alignment
|
-Wcast-align # Warn for potential performance problems from memory alignment
|
||||||
-Wconversion # Warn on type conversions that may lose data
|
-Wconversion # Warn on type conversions that may lose data
|
||||||
-Wsign-conversion # Warn on sign conversions
|
-Wsign-conversion # Warn on sign conversions
|
||||||
-Wnull-dereference # Warn about null pointer dereference
|
-Wnull-dereference # Warn about null pointer dereference
|
||||||
)
|
|
||||||
|
# MinGW/Windows specific flags
|
||||||
|
-static-libgcc # Link libgcc statically
|
||||||
|
-static-libstdc++ # Link libstdc++ statically
|
||||||
|
)
|
||||||
|
|
||||||
|
# Windows-specific linker flags
|
||||||
|
target_link_options(${PROJECT_NAME} PRIVATE
|
||||||
|
-static # Create a static executable
|
||||||
|
-Wl,--no-undefined # Don't allow undefined symbols
|
||||||
|
)
|
||||||
|
|
||||||
|
# Define Windows macros if needed
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||||
|
WIN32_LEAN_AND_MEAN # Exclude rarely-used stuff from Windows headers
|
||||||
|
NOMINMAX # Prevent Windows.h from defining min/max macros
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
# Linux/Unix specific settings
|
||||||
|
target_compile_options(${PROJECT_NAME} PRIVATE
|
||||||
|
# Make all warnings into errors
|
||||||
|
-Werror
|
||||||
|
|
||||||
|
# Basic warning flags
|
||||||
|
-Wall # Enable all common warnings
|
||||||
|
-Wextra # Enable extra warnings not covered by -Wall
|
||||||
|
-Wpedantic # Issue warnings demanded by strict ISO C and ISO C++
|
||||||
|
-pedantic-errors # Like -Wpedantic but errors instead of warnings
|
||||||
|
|
||||||
|
# Specific warning categories
|
||||||
|
-Wshadow # Warn when a variable declaration shadows another
|
||||||
|
-Wcast-align # Warn for potential performance problems from memory alignment
|
||||||
|
-Wconversion # Warn on type conversions that may lose data
|
||||||
|
-Wsign-conversion # Warn on sign conversions
|
||||||
|
-Wnull-dereference # Warn about null pointer dereference
|
||||||
|
)
|
||||||
|
endif()
|
|
@ -108,15 +108,17 @@ namespace AtmAdmin {
|
||||||
|
|
||||||
std::array<int, 4> pinDigits{};
|
std::array<int, 4> pinDigits{};
|
||||||
|
|
||||||
for (size_t i{}; i != 4; i++) {
|
// Asserts that the pin is exactly 4 letters in length.
|
||||||
pinDigits[i] = (newPin[i] - '0');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newPin.size() != 4) {
|
if (newPin.size() != 4) {
|
||||||
errorReport("The pin has to be 4 numbers long.");
|
errorReport("The pin has to be 4 numbers long.");
|
||||||
return "invalid";
|
return "invalid";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fills the int array with a number version of the string array.
|
||||||
|
for (size_t i{}; i != 4; i++) {
|
||||||
|
pinDigits[i] = (newPin[i] - '0');
|
||||||
|
}
|
||||||
|
|
||||||
if (newPin[0] == '0') {
|
if (newPin[0] == '0') {
|
||||||
errorReport("The first number cannot be \'0\'");
|
errorReport("The first number cannot be \'0\'");
|
||||||
return "invalid";
|
return "invalid";
|
||||||
|
@ -124,7 +126,7 @@ namespace AtmAdmin {
|
||||||
|
|
||||||
// Checks if anything put into the pin is alphabetic.
|
// Checks if anything put into the pin is alphabetic.
|
||||||
for (size_t i = 0; i < 4; i++) {
|
for (size_t i = 0; i < 4; i++) {
|
||||||
if (isalpha(newPin[i])) {
|
if (!isdigit(newPin[i])) {
|
||||||
errorReport("The pin cannot contain alphabet letters.");
|
errorReport("The pin cannot contain alphabet letters.");
|
||||||
return "invalid";
|
return "invalid";
|
||||||
}
|
}
|
||||||
|
@ -174,15 +176,9 @@ namespace AtmAdmin {
|
||||||
Error::ignoreLine();
|
Error::ignoreLine();
|
||||||
std::getline(std::cin, newName);
|
std::getline(std::cin, newName);
|
||||||
|
|
||||||
// Ensures the name is between 2 and 10 characters long.
|
// Ensures the name is between 2 and 15 characters long.
|
||||||
if (newName.length() < 2 or newName.length() > 20) {
|
if (newName.length() < 2 or newName.length() > 15) {
|
||||||
errorReport("Name has to be between 2 and 20 characters.");
|
errorReport("Name has to be between 2 and 15 characters.");
|
||||||
return "invalid";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checks if the first character is a number.
|
|
||||||
if (isdigit(newName.at(0))) {
|
|
||||||
errorReport("First letter cannot be a digit.");
|
|
||||||
return "invalid";
|
return "invalid";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
src/data/users.xml
Normal file
19
src/data/users.xml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<bankapp>
|
||||||
|
<bank>
|
||||||
|
<money>5000.0</money>
|
||||||
|
</bank>
|
||||||
|
|
||||||
|
<accounts>
|
||||||
|
<account owner="foo">
|
||||||
|
<name>Foo Jamerson</name>
|
||||||
|
<money>5017.97</money>
|
||||||
|
<pin>9671</pin>
|
||||||
|
</account>
|
||||||
|
|
||||||
|
<account owner="bar">
|
||||||
|
<name>Bar Memorial</name>
|
||||||
|
<money>8910.51</money>
|
||||||
|
<pin>5217</pin>
|
||||||
|
</account>
|
||||||
|
</accounts>
|
||||||
|
</bankapp>
|
|
@ -19,7 +19,7 @@ int main() {
|
||||||
// startup() presents the user with the choices below.
|
// startup() presents the user with the choices below.
|
||||||
// The other functions should handle invalid choices.
|
// The other functions should handle invalid choices.
|
||||||
// ((1. Change pin || 2. Change money || 3. Change account name || Q. Exit the program))
|
// ((1. Change pin || 2. Change money || 3. Change account name || Q. Exit the program))
|
||||||
char userChoice{AtmAdmin::startup()};
|
char userChoice{startup()};
|
||||||
std::string userInformation{};
|
std::string userInformation{};
|
||||||
|
|
||||||
// The bulk of the program, allowing user to interact with the program.
|
// The bulk of the program, allowing user to interact with the program.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user