mirror of
https://github.com/Ladebeze66/cpp-partie-1.git
synced 2026-11-09 13:17:15 +01:00
ccp
This commit is contained in:
61
cpp00/ex00/Makefile
Normal file
61
cpp00/ex00/Makefile
Normal file
@@ -0,0 +1,61 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/12/23 16:15:46 by fgras-ca #+# #+# #
|
||||
# Updated: 2023/12/23 16:39:11 by fgras-ca ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
|
||||
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
|
||||
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
|
||||
echo "( ( ( ( ( ( ( ("
|
||||
|
||||
DEF_COLOR = \033[0m
|
||||
GRAY = \033[0;90m
|
||||
RED = \033[0;91m
|
||||
GREEN = \033[0;92m
|
||||
YELLOW = \033[0;93m
|
||||
BLUE = \033[0;94m
|
||||
MAGENTA = \033[0;95m
|
||||
CYAN = \033[0;96m
|
||||
WHITE = \033[0;97m
|
||||
ORANGE = \033[38;5;214m
|
||||
|
||||
NAME = megaphone
|
||||
|
||||
SRC = megaphone.cpp \
|
||||
|
||||
OBJS = ${SRC:.cpp=.o}
|
||||
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Werror -Wextra -std=c++98
|
||||
RM = rm -f
|
||||
|
||||
all : $(NAME)
|
||||
|
||||
$(NAME) : $(OBJS)
|
||||
@echo "$(RED)Compilation megaphone... $(DEF_COLOR)"
|
||||
$(CC) $(CFLAGS) $(OBJS) -o $(NAME)
|
||||
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./megaphone" with arguments or not!!$(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
clean :
|
||||
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
|
||||
$(RM) $(OBJS)
|
||||
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
fclean : clean
|
||||
@echo "$(RED)Delete program name... $(DEF_COLOR)"
|
||||
$(RM) $(NAME)
|
||||
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
re : fclean all
|
||||
|
||||
.PHONY : all clean fclean re
|
||||
BIN
cpp00/ex00/a.out
Executable file
BIN
cpp00/ex00/a.out
Executable file
Binary file not shown.
BIN
cpp00/ex00/megaphone
Executable file
BIN
cpp00/ex00/megaphone
Executable file
Binary file not shown.
35
cpp00/ex00/megaphone.cpp
Normal file
35
cpp00/ex00/megaphone.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* megaphone.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/23 16:14:56 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/23 16:28:52 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <iostream>
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc == 1)
|
||||
{
|
||||
std::cout << "* LOUD AND UNBEARABLE FEEDBACK NOISE *" << std::endl;
|
||||
return (0);
|
||||
}
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
char *str = argv[i];
|
||||
for (int j = 0; str[j]; j++)
|
||||
{
|
||||
std::cout << (char)toupper(str[j]);
|
||||
}
|
||||
std::cout << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return (0);
|
||||
}
|
||||
BIN
cpp00/ex00/megaphone.o
Normal file
BIN
cpp00/ex00/megaphone.o
Normal file
Binary file not shown.
18
cpp00/ex01/.vscode/c_cpp_properties.json
vendored
Normal file
18
cpp00/ex01/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "linux-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"compilerArgs": [
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
24
cpp00/ex01/.vscode/launch.json
vendored
Normal file
24
cpp00/ex01/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": false,
|
||||
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp00/ex01",
|
||||
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp00/ex01/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
108
cpp00/ex01/.vscode/settings.json
vendored
Normal file
108
cpp00/ex01/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wcast-align",
|
||||
"-Wconversion",
|
||||
"-Wsign-conversion",
|
||||
"-Wnull-dereference"
|
||||
],
|
||||
"C_Cpp_Runner.msvcWarnings": [
|
||||
"/W4",
|
||||
"/permissive-",
|
||||
"/w14242",
|
||||
"/w14287",
|
||||
"/w14296",
|
||||
"/w14311",
|
||||
"/w14826",
|
||||
"/w44062",
|
||||
"/w44242",
|
||||
"/w14905",
|
||||
"/w14906",
|
||||
"/w14263",
|
||||
"/w44265",
|
||||
"/w14928"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||
"C_Cpp_Runner.showCompilationTime": false,
|
||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||
"C_Cpp_Runner.msvcSecureNoWarnings": false,
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"random": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"numbers": "cpp",
|
||||
"ostream": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"typeinfo": "cpp"
|
||||
}
|
||||
}
|
||||
97
cpp00/ex01/Contact.cpp
Normal file
97
cpp00/ex01/Contact.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Contact.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/23 17:17:14 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/23 20:52:55 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Contact.hpp"
|
||||
|
||||
Contact::Contact() {}
|
||||
|
||||
void Contact::SetDetails()
|
||||
{
|
||||
std::cout << "First Name: ";
|
||||
std::cin >> _first_name;
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
std::cout << "Last Name: ";
|
||||
std::cin >> _last_name;
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
std::cout << "Nickname: ";
|
||||
std::cin >> _nickname;
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
while (true)
|
||||
{
|
||||
std::cout << "Phone Number: ";
|
||||
std::cin >> _phone_number;
|
||||
|
||||
bool isValid = true;
|
||||
for (char c : _phone_number)
|
||||
{
|
||||
if (!std::isdigit(c))
|
||||
{
|
||||
isValid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isValid)
|
||||
{
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Invalid input. A phone number should contain only digits (0-9)." << std::endl;
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
}
|
||||
}
|
||||
std::cout << "Darkest Secret: ";
|
||||
std::getline(std::cin, _darkest_secret);
|
||||
}
|
||||
|
||||
Contact::~Contact() {}
|
||||
|
||||
void Contact::DisplaySummary(int index) const
|
||||
{
|
||||
std::string redBar = "\033[31m|\033[0m";
|
||||
std::cout << std::setw(8) << index << redBar;
|
||||
if (_first_name.length() > 10)
|
||||
{
|
||||
std::cout << std::setw(10) << _first_name.substr(0,9) + "." << redBar;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << std::setw(10) << _first_name << redBar;
|
||||
}
|
||||
if (_last_name.length() > 10)
|
||||
{
|
||||
std::cout << std::setw(10) << _last_name.substr(0,9) + "." << redBar;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << std::setw(10) << _last_name << redBar;
|
||||
}
|
||||
if (_nickname.length() > 10)
|
||||
{
|
||||
std::cout << std::setw(10) << _nickname.substr(0,9) + "." << redBar;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << std::setw(10) << _nickname << redBar;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void Contact::DisplayDetails() const
|
||||
{
|
||||
std::cout << "First Name: " << _first_name << std::endl;
|
||||
std::cout << "Last Name: " << _last_name << std::endl;
|
||||
std::cout << "Nickname: " << _nickname << std::endl;
|
||||
std::cout << "Phone Number: " << _phone_number << std::endl;
|
||||
std::cout << "Darkest Secret: " << _darkest_secret << std::endl;
|
||||
}
|
||||
38
cpp00/ex01/Contact.hpp
Normal file
38
cpp00/ex01/Contact.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Contact.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/23 16:56:55 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/23 19:49:10 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CONTACT_HPP
|
||||
# define CONTACT_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <limits>
|
||||
|
||||
class Contact
|
||||
{
|
||||
public:
|
||||
Contact();
|
||||
~Contact();
|
||||
void SetDetails();
|
||||
void DisplaySummary(int index) const;
|
||||
void DisplayDetails() const;
|
||||
|
||||
private:
|
||||
std::string _first_name;
|
||||
std::string _last_name;
|
||||
std::string _nickname;
|
||||
std::string _phone_number;
|
||||
std::string _darkest_secret;
|
||||
};
|
||||
|
||||
#endif
|
||||
BIN
cpp00/ex01/Contact.o
Normal file
BIN
cpp00/ex01/Contact.o
Normal file
Binary file not shown.
63
cpp00/ex01/Makefile
Normal file
63
cpp00/ex01/Makefile
Normal file
@@ -0,0 +1,63 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/12/23 18:31:36 by fgras-ca #+# #+# #
|
||||
# Updated: 2023/12/23 19:06:37 by fgras-ca ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
|
||||
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
|
||||
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
|
||||
echo "( ( ( ( ( ( ( ("
|
||||
|
||||
DEF_COLOR = \033[0m
|
||||
GRAY = \033[0;90m
|
||||
RED = \033[0;91m
|
||||
GREEN = \033[0;92m
|
||||
YELLOW = \033[0;93m
|
||||
BLUE = \033[0;94m
|
||||
MAGENTA = \033[0;95m
|
||||
CYAN = \033[0;96m
|
||||
WHITE = \033[0;97m
|
||||
ORANGE = \033[38;5;214m
|
||||
|
||||
NAME = phonebook
|
||||
|
||||
SRC = PhoneBook.cpp \
|
||||
Contact.cpp \
|
||||
main.cpp \
|
||||
|
||||
OBJS = ${SRC:.cpp=.o}
|
||||
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Werror -Wextra -std=c++98
|
||||
RM = rm -f
|
||||
|
||||
all : $(NAME)
|
||||
|
||||
$(NAME) : $(OBJS)
|
||||
@echo "$(RED)Compilation bookphone... $(DEF_COLOR)"
|
||||
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
|
||||
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./phonebook"!!$(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
clean :
|
||||
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
|
||||
$(RM) $(OBJS)
|
||||
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
fclean : clean
|
||||
@echo "$(RED)Delete program name... $(DEF_COLOR)"
|
||||
$(RM) $(NAME)
|
||||
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
re : fclean all
|
||||
|
||||
.PHONY : all clean fclean re
|
||||
69
cpp00/ex01/PhoneBook.cpp
Normal file
69
cpp00/ex01/PhoneBook.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* PhoneBook.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/23 18:01:39 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/23 20:52:57 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "PhoneBook.hpp"
|
||||
|
||||
PhoneBook::PhoneBook() : next_index(0), total_contacts(0) {}
|
||||
|
||||
PhoneBook::~PhoneBook() {}
|
||||
|
||||
void PhoneBook::AddContact()
|
||||
{
|
||||
contacts[next_index].SetDetails();
|
||||
next_index = (next_index + 1) % 8;
|
||||
if (total_contacts < 8)
|
||||
{
|
||||
total_contacts++;
|
||||
}
|
||||
std::cout << "Contact added successfully!" << std::endl;
|
||||
}
|
||||
|
||||
void PhoneBook::SearchContact() const
|
||||
{
|
||||
std::cout << "\033[31m";
|
||||
std::cout << "------------------------------------------" << std::endl;
|
||||
std::cout << std::setw(8) << "Index" << "|"
|
||||
<< std::setw(10) << "First" << "|"
|
||||
<< std::setw(10) << "Last" << "|"
|
||||
<< std::setw(10) << "Nickname" << "|" << std::endl;
|
||||
std::cout << "------------------------------------------" << std::endl;
|
||||
std::cout << "\033[0m";
|
||||
for (int i = 0; i < total_contacts; ++i)
|
||||
{
|
||||
contacts[i].DisplaySummary(i + 1);
|
||||
}
|
||||
std::cout << "\033[31m";
|
||||
std::cout << "------------------------------------------" << std::endl;
|
||||
std::cout << "\033[0m";
|
||||
while (true)
|
||||
{
|
||||
std::cout << "Enter the index of the contact to display: ";
|
||||
int index;
|
||||
std::cin >> index;
|
||||
|
||||
if (std::cin.fail())
|
||||
{
|
||||
std::cin.clear();
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
std::cout << "Invalid input. Please enter a number." << std::endl;
|
||||
}
|
||||
else if (index < 1 || index > total_contacts)
|
||||
{
|
||||
std::cout << "Invalid index. Please enter a number between 1 and " << total_contacts << "." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
contacts[index - 1].DisplayDetails();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
cpp00/ex01/PhoneBook.hpp
Normal file
37
cpp00/ex01/PhoneBook.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* PhoneBook.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/23 17:55:10 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/23 19:52:34 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PHONEBOOK_HPP
|
||||
# define PHONEBOOK_HPP
|
||||
|
||||
#include "Contact.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
#include <limits>
|
||||
|
||||
class PhoneBook
|
||||
{
|
||||
public:
|
||||
PhoneBook();
|
||||
~PhoneBook();
|
||||
|
||||
void AddContact();
|
||||
void SearchContact() const;
|
||||
|
||||
private:
|
||||
Contact contacts[8];
|
||||
int next_index;
|
||||
int total_contacts;
|
||||
};
|
||||
|
||||
#endif
|
||||
BIN
cpp00/ex01/PhoneBook.o
Normal file
BIN
cpp00/ex01/PhoneBook.o
Normal file
Binary file not shown.
44
cpp00/ex01/main.cpp
Normal file
44
cpp00/ex01/main.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/23 18:16:58 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/23 18:31:05 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Contact.hpp"
|
||||
#include "PhoneBook.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
PhoneBook phonebook;
|
||||
std::string command;
|
||||
|
||||
while (true)
|
||||
{
|
||||
std::cout << "Enter command (ADD, SEARCH, or EXIT): ";
|
||||
std::cin >> command;
|
||||
|
||||
if (command == "ADD")
|
||||
{
|
||||
phonebook.AddContact();
|
||||
}
|
||||
else if (command == "SEARCH")
|
||||
{
|
||||
phonebook.SearchContact();
|
||||
}
|
||||
else if (command == "EXIT")
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Command not recognized." << std::endl;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
BIN
cpp00/ex01/main.o
Normal file
BIN
cpp00/ex01/main.o
Normal file
Binary file not shown.
BIN
cpp00/ex01/phonebook
Executable file
BIN
cpp00/ex01/phonebook
Executable file
Binary file not shown.
18
cpp00/ex02/.vscode/c_cpp_properties.json
vendored
Normal file
18
cpp00/ex02/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "linux-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"compilerArgs": [
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
24
cpp00/ex02/.vscode/launch.json
vendored
Normal file
24
cpp00/ex02/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": false,
|
||||
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp00/ex02",
|
||||
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp00/ex02/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
59
cpp00/ex02/.vscode/settings.json
vendored
Normal file
59
cpp00/ex02/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wcast-align",
|
||||
"-Wconversion",
|
||||
"-Wsign-conversion",
|
||||
"-Wnull-dereference"
|
||||
],
|
||||
"C_Cpp_Runner.msvcWarnings": [
|
||||
"/W4",
|
||||
"/permissive-",
|
||||
"/w14242",
|
||||
"/w14287",
|
||||
"/w14296",
|
||||
"/w14311",
|
||||
"/w14826",
|
||||
"/w44062",
|
||||
"/w44242",
|
||||
"/w14905",
|
||||
"/w14906",
|
||||
"/w14263",
|
||||
"/w44265",
|
||||
"/w14928"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||
"C_Cpp_Runner.showCompilationTime": false,
|
||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||
"C_Cpp_Runner.msvcSecureNoWarnings": false
|
||||
}
|
||||
59
cpp00/ex02/19920104_091532.log
Normal file
59
cpp00/ex02/19920104_091532.log
Normal file
@@ -0,0 +1,59 @@
|
||||
[19920104_091532] index:0;amount:42;created
|
||||
[19920104_091532] index:1;amount:54;created
|
||||
[19920104_091532] index:2;amount:957;created
|
||||
[19920104_091532] index:3;amount:432;created
|
||||
[19920104_091532] index:4;amount:1234;created
|
||||
[19920104_091532] index:5;amount:0;created
|
||||
[19920104_091532] index:6;amount:754;created
|
||||
[19920104_091532] index:7;amount:16576;created
|
||||
[19920104_091532] accounts:8;total:20049;deposits:0;withdrawals:0
|
||||
[19920104_091532] index:0;amount:42;deposits:0;withdrawals:0
|
||||
[19920104_091532] index:1;amount:54;deposits:0;withdrawals:0
|
||||
[19920104_091532] index:2;amount:957;deposits:0;withdrawals:0
|
||||
[19920104_091532] index:3;amount:432;deposits:0;withdrawals:0
|
||||
[19920104_091532] index:4;amount:1234;deposits:0;withdrawals:0
|
||||
[19920104_091532] index:5;amount:0;deposits:0;withdrawals:0
|
||||
[19920104_091532] index:6;amount:754;deposits:0;withdrawals:0
|
||||
[19920104_091532] index:7;amount:16576;deposits:0;withdrawals:0
|
||||
[19920104_091532] index:0;p_amount:42;deposit:5;amount:47;nb_deposits:1
|
||||
[19920104_091532] index:1;p_amount:54;deposit:765;amount:819;nb_deposits:1
|
||||
[19920104_091532] index:2;p_amount:957;deposit:564;amount:1521;nb_deposits:1
|
||||
[19920104_091532] index:3;p_amount:432;deposit:2;amount:434;nb_deposits:1
|
||||
[19920104_091532] index:4;p_amount:1234;deposit:87;amount:1321;nb_deposits:1
|
||||
[19920104_091532] index:5;p_amount:0;deposit:23;amount:23;nb_deposits:1
|
||||
[19920104_091532] index:6;p_amount:754;deposit:9;amount:763;nb_deposits:1
|
||||
[19920104_091532] index:7;p_amount:16576;deposit:20;amount:16596;nb_deposits:1
|
||||
[19920104_091532] accounts:8;total:21524;deposits:8;withdrawals:0
|
||||
[19920104_091532] index:0;amount:47;deposits:1;withdrawals:0
|
||||
[19920104_091532] index:1;amount:819;deposits:1;withdrawals:0
|
||||
[19920104_091532] index:2;amount:1521;deposits:1;withdrawals:0
|
||||
[19920104_091532] index:3;amount:434;deposits:1;withdrawals:0
|
||||
[19920104_091532] index:4;amount:1321;deposits:1;withdrawals:0
|
||||
[19920104_091532] index:5;amount:23;deposits:1;withdrawals:0
|
||||
[19920104_091532] index:6;amount:763;deposits:1;withdrawals:0
|
||||
[19920104_091532] index:7;amount:16596;deposits:1;withdrawals:0
|
||||
[19920104_091532] index:0;p_amount:47;withdrawal:refused
|
||||
[19920104_091532] index:1;p_amount:819;withdrawal:34;amount:785;nb_withdrawals:1
|
||||
[19920104_091532] index:2;p_amount:1521;withdrawal:657;amount:864;nb_withdrawals:1
|
||||
[19920104_091532] index:3;p_amount:434;withdrawal:4;amount:430;nb_withdrawals:1
|
||||
[19920104_091532] index:4;p_amount:1321;withdrawal:76;amount:1245;nb_withdrawals:1
|
||||
[19920104_091532] index:5;p_amount:23;withdrawal:refused
|
||||
[19920104_091532] index:6;p_amount:763;withdrawal:657;amount:106;nb_withdrawals:1
|
||||
[19920104_091532] index:7;p_amount:16596;withdrawal:7654;amount:8942;nb_withdrawals:1
|
||||
[19920104_091532] accounts:8;total:12442;deposits:8;withdrawals:6
|
||||
[19920104_091532] index:0;amount:47;deposits:1;withdrawals:0
|
||||
[19920104_091532] index:1;amount:785;deposits:1;withdrawals:1
|
||||
[19920104_091532] index:2;amount:864;deposits:1;withdrawals:1
|
||||
[19920104_091532] index:3;amount:430;deposits:1;withdrawals:1
|
||||
[19920104_091532] index:4;amount:1245;deposits:1;withdrawals:1
|
||||
[19920104_091532] index:5;amount:23;deposits:1;withdrawals:0
|
||||
[19920104_091532] index:6;amount:106;deposits:1;withdrawals:1
|
||||
[19920104_091532] index:7;amount:8942;deposits:1;withdrawals:1
|
||||
[19920104_091532] index:0;amount:47;closed
|
||||
[19920104_091532] index:1;amount:785;closed
|
||||
[19920104_091532] index:2;amount:864;closed
|
||||
[19920104_091532] index:3;amount:430;closed
|
||||
[19920104_091532] index:4;amount:1245;closed
|
||||
[19920104_091532] index:5;amount:23;closed
|
||||
[19920104_091532] index:6;amount:106;closed
|
||||
[19920104_091532] index:7;amount:8942;closed
|
||||
119
cpp00/ex02/Account.cpp
Normal file
119
cpp00/ex02/Account.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
// ************************************************************************** //
|
||||
// //
|
||||
// Account.cpp for GlobalBanksters United //
|
||||
// Created on : Sat Dec 23 19:43:15 2023 //
|
||||
// //
|
||||
// Made by : fgras-ca //
|
||||
// //
|
||||
// ************************************************************************** //
|
||||
|
||||
#include "Account.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
|
||||
// Initialisation des variables statiques
|
||||
int Account::_nbAccounts = 0;
|
||||
int Account::_totalAmount = 0;
|
||||
int Account::_totalNbDeposits = 0;
|
||||
int Account::_totalNbWithdrawals = 0;
|
||||
|
||||
// Constructeur : Initialise un compte avec un dépôt initial et met à jour les informations globales
|
||||
Account::Account(int initial_deposit) : _amount(initial_deposit), _nbDeposits(0), _nbWithdrawals(0)
|
||||
{
|
||||
_accountIndex = _nbAccounts++; // Assignation d'un index unique au compte et incrémentation du nombre total de comptes
|
||||
_totalAmount += _amount; // Mise à jour du montant total détenu par tous les comptes
|
||||
_displayTimestamp(); // Affichage de l'horodatage de la création du compte
|
||||
std::cout << "index:" << _accountIndex << ";amount:" << _amount << ";created\n"; // Enregistrement de la création du compte
|
||||
}
|
||||
|
||||
// Destructeur : Met à jour les informations globales lors de la fermeture d'un compte
|
||||
Account::~Account()
|
||||
{
|
||||
_nbAccounts--; // Décrémentation du nombre total de comptes
|
||||
_totalAmount -= _amount; // Mise à jour du montant total détenu par tous les comptes
|
||||
_displayTimestamp(); // Affichage de l'horodatage de la fermeture du compte
|
||||
std::cout << "index:" << _accountIndex << ";amount:" << _amount << ";closed\n"; // Enregistrement de la fermeture du compte
|
||||
}
|
||||
|
||||
// Dépôts : Ajoute un montant au compte et met à jour les informations globales
|
||||
void Account::makeDeposit(int deposit)
|
||||
{
|
||||
_displayTimestamp(); // Affichage de l'horodatage de l'opération
|
||||
std::cout << "index:" << _accountIndex << ";p_amount:" << _amount << ";deposit:" << deposit;
|
||||
_amount += deposit; // Mise à jour du montant dans le compte
|
||||
_nbDeposits++; // Incrémentation du nombre de dépôts pour ce compte
|
||||
_totalAmount += deposit; // Mise à jour du montant total détenu par tous les comptes
|
||||
_totalNbDeposits++; // Incrémentation du nombre total de dépôts effectués sur tous les comptes
|
||||
std::cout << ";amount:" << _amount << ";nb_deposits:" << _nbDeposits << "\n"; // Enregistrement de l'opération de dépôt
|
||||
}
|
||||
|
||||
// Retraits : Diminue le montant du compte si possible et met à jour les informations globales
|
||||
bool Account::makeWithdrawal(int withdrawal)
|
||||
{
|
||||
_displayTimestamp(); // Affichage de l'horodatage de l'opération
|
||||
std::cout << "index:" << _accountIndex << ";p_amount:" << _amount << ";withdrawal:";
|
||||
if (withdrawal > _amount)
|
||||
{ // Vérification si le retrait est possible (fonds suffisants)
|
||||
std::cout << "refused\n"; // Enregistrement d'un retrait refusé
|
||||
return (false);
|
||||
}
|
||||
_amount -= withdrawal; // Mise à jour du montant dans le compte
|
||||
_nbWithdrawals++; // Incrémentation du nombre de retraits pour ce compte
|
||||
_totalAmount -= withdrawal; // Mise à jour du montant total détenu par tous les comptes
|
||||
_totalNbWithdrawals++; // Incrémentation du nombre total de retraits effectués sur tous les comptes
|
||||
std::cout << withdrawal << ";amount:" << _amount << ";nb_withdrawals:" << _nbWithdrawals << "\n"; // Enregistrement de l'opération de retrait
|
||||
return (true);
|
||||
}
|
||||
|
||||
// Vérifier le montant : Retourne le montant actuel du compte
|
||||
int Account::checkAmount() const
|
||||
{
|
||||
return (_amount);
|
||||
}
|
||||
|
||||
// Afficher le statut du compte : Affiche les informations détaillées sur le compte
|
||||
void Account::displayStatus() const
|
||||
{
|
||||
_displayTimestamp(); // Affichage de l'horodatage de l'opération
|
||||
std::cout << "index:" << _accountIndex << ";amount:" << _amount
|
||||
<< ";deposits:" << _nbDeposits << ";withdrawals:" << _nbWithdrawals << "\n"; // Enregistrement de l'état actuel du compte
|
||||
}
|
||||
|
||||
// Retourner le nombre total de comptes
|
||||
int Account::getNbAccounts() { return _nbAccounts; }
|
||||
|
||||
// Retourner le montant total détenu par tous les comptes
|
||||
int Account::getTotalAmount() { return _totalAmount; }
|
||||
|
||||
// Retourner le nombre total de dépôts effectués sur tous les comptes
|
||||
int Account::getNbDeposits() { return _totalNbDeposits; }
|
||||
|
||||
// Retourner le nombre total de retraits effectués sur tous les comptes
|
||||
int Account::getNbWithdrawals() { return _totalNbWithdrawals; }
|
||||
|
||||
// Afficher les informations globales de tous les comptes
|
||||
void Account::displayAccountsInfos()
|
||||
{
|
||||
_displayTimestamp(); // Affichage de l'horodatage de l'opération
|
||||
std::cout << "accounts:" << getNbAccounts() << ";total:" << getTotalAmount()
|
||||
<< ";deposits:" << getNbDeposits() << ";withdrawals:" << getNbWithdrawals() << "\n"; // Enregistrement des informations globales
|
||||
}
|
||||
|
||||
void Account::_displayTimestamp()
|
||||
{
|
||||
// Obtenir l'heure et la date actuelles
|
||||
std::time_t now = std::time(nullptr);
|
||||
std::tm *ltm = std::localtime(&now);
|
||||
|
||||
std::cout << "["
|
||||
<< 1900 + ltm->tm_year // Ajouter 1900 pour obtenir l'année complète
|
||||
<< std::setw(2) << std::setfill('0') << 1 + ltm->tm_mon // Mois (0-11 donc +1 pour 1-12)
|
||||
<< std::setw(2) << std::setfill('0') << ltm->tm_mday // Jour (1-31)
|
||||
<< "_"
|
||||
<< std::setw(2) << std::setfill('0') << ltm->tm_hour // Heures (0-23)
|
||||
<< std::setw(2) << std::setfill('0') << ltm->tm_min // Minutes (0-59)
|
||||
<< std::setw(2) << std::setfill('0') << ltm->tm_sec // Secondes (0-59)
|
||||
<< "] ";
|
||||
}
|
||||
69
cpp00/ex02/Account.hpp
Normal file
69
cpp00/ex02/Account.hpp
Normal file
@@ -0,0 +1,69 @@
|
||||
// ************************************************************************** //
|
||||
// //
|
||||
// Account.hpp for GlobalBanksters United //
|
||||
// Created on : Thu Nov 20 19:43:15 1989 //
|
||||
// Last update : Wed Jan 04 14:54:06 1992 //
|
||||
// Made by : Brad "Buddy" McLane <bm@gbu.com> //
|
||||
// //
|
||||
// ************************************************************************** //
|
||||
|
||||
|
||||
#pragma once
|
||||
#ifndef __ACCOUNT_H__
|
||||
#define __ACCOUNT_H__
|
||||
|
||||
// ************************************************************************** //
|
||||
// Account Class //
|
||||
// ************************************************************************** //
|
||||
|
||||
class Account {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
typedef Account t;
|
||||
|
||||
static int getNbAccounts( void );
|
||||
static int getTotalAmount( void );
|
||||
static int getNbDeposits( void );
|
||||
static int getNbWithdrawals( void );
|
||||
static void displayAccountsInfos( void );
|
||||
|
||||
Account( int initial_deposit );
|
||||
~Account( void );
|
||||
|
||||
void makeDeposit( int deposit );
|
||||
bool makeWithdrawal( int withdrawal );
|
||||
int checkAmount( void ) const;
|
||||
void displayStatus( void ) const;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
static int _nbAccounts;
|
||||
static int _totalAmount;
|
||||
static int _totalNbDeposits;
|
||||
static int _totalNbWithdrawals;
|
||||
|
||||
static void _displayTimestamp( void );
|
||||
|
||||
int _accountIndex;
|
||||
int _amount;
|
||||
int _nbDeposits;
|
||||
int _nbWithdrawals;
|
||||
|
||||
Account( void );
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// ************************************************************************** //
|
||||
// vim: set ts=4 sw=4 tw=80 noexpandtab: //
|
||||
// -*- indent-tabs-mode:t; -*-
|
||||
// -*- mode: c++-mode; -*-
|
||||
// -*- fill-column: 75; comment-column: 75; -*-
|
||||
// ************************************************************************** //
|
||||
|
||||
|
||||
#endif /* __ACCOUNT_H__ */
|
||||
BIN
cpp00/ex02/Account.o
Normal file
BIN
cpp00/ex02/Account.o
Normal file
Binary file not shown.
50
cpp00/ex02/Makefile
Normal file
50
cpp00/ex02/Makefile
Normal file
@@ -0,0 +1,50 @@
|
||||
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
|
||||
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
|
||||
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
|
||||
echo "( ( ( ( ( ( ( ("
|
||||
|
||||
DEF_COLOR = \033[0m
|
||||
GRAY = \033[0;90m
|
||||
RED = \033[0;91m
|
||||
GREEN = \033[0;92m
|
||||
YELLOW = \033[0;93m
|
||||
BLUE = \033[0;94m
|
||||
MAGENTA = \033[0;95m
|
||||
CYAN = \033[0;96m
|
||||
WHITE = \033[0;97m
|
||||
ORANGE = \033[38;5;214m
|
||||
|
||||
NAME = bank
|
||||
|
||||
SRC = Account.cpp \
|
||||
tests.cpp \
|
||||
|
||||
OBJS = ${SRC:.cpp=.o}
|
||||
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Werror -Wextra -std=c++98
|
||||
RM = rm -f
|
||||
|
||||
all : $(NAME)
|
||||
|
||||
$(NAME) : $(OBJS)
|
||||
@echo "$(RED)Compilation Account Bank... $(DEF_COLOR)"
|
||||
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
|
||||
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./bank"$(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
clean :
|
||||
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
|
||||
$(RM) $(OBJS)
|
||||
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
fclean : clean
|
||||
@echo "$(RED)Delete program name... $(DEF_COLOR)"
|
||||
$(RM) $(NAME)
|
||||
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
re : fclean all
|
||||
|
||||
.PHONY : all clean fclean re
|
||||
BIN
cpp00/ex02/bank
Executable file
BIN
cpp00/ex02/bank
Executable file
Binary file not shown.
72
cpp00/ex02/tests.cpp
Normal file
72
cpp00/ex02/tests.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
// ************************************************************************** //
|
||||
// //
|
||||
// tests.cpp for GlobalBanksters United //
|
||||
// Created on : Thu Nov 20 23:45:02 1989 //
|
||||
// Last update : Wed Jan 04 09:23:52 1992 //
|
||||
// Made by : Brad "Buddy" McLane <bm@gbu.com> //
|
||||
// //
|
||||
// ************************************************************************** //
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include "Account.hpp"
|
||||
|
||||
|
||||
int main( void ) {
|
||||
|
||||
typedef std::vector<Account::t> accounts_t;
|
||||
typedef std::vector<int> ints_t;
|
||||
typedef std::pair<accounts_t::iterator, ints_t::iterator> acc_int_t;
|
||||
|
||||
int const amounts[] = { 42, 54, 957, 432, 1234, 0, 754, 16576 };
|
||||
size_t const amounts_size( sizeof(amounts) / sizeof(int) );
|
||||
accounts_t accounts( amounts, amounts + amounts_size );
|
||||
accounts_t::iterator acc_begin = accounts.begin();
|
||||
accounts_t::iterator acc_end = accounts.end();
|
||||
|
||||
int const d[] = { 5, 765, 564, 2, 87, 23, 9, 20 };
|
||||
size_t const d_size( sizeof(d) / sizeof(int) );
|
||||
ints_t deposits( d, d + d_size );
|
||||
ints_t::iterator dep_begin = deposits.begin();
|
||||
ints_t::iterator dep_end = deposits.end();
|
||||
|
||||
int const w[] = { 321, 34, 657, 4, 76, 275, 657, 7654 };
|
||||
size_t const w_size( sizeof(w) / sizeof(int) );
|
||||
ints_t withdrawals( w, w + w_size );
|
||||
ints_t::iterator wit_begin = withdrawals.begin();
|
||||
ints_t::iterator wit_end = withdrawals.end();
|
||||
|
||||
Account::displayAccountsInfos();
|
||||
std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) );
|
||||
|
||||
for ( acc_int_t it( acc_begin, dep_begin );
|
||||
it.first != acc_end && it.second != dep_end;
|
||||
++(it.first), ++(it.second) ) {
|
||||
|
||||
(*(it.first)).makeDeposit( *(it.second) );
|
||||
}
|
||||
|
||||
Account::displayAccountsInfos();
|
||||
std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) );
|
||||
|
||||
for ( acc_int_t it( acc_begin, wit_begin );
|
||||
it.first != acc_end && it.second != wit_end;
|
||||
++(it.first), ++(it.second) ) {
|
||||
|
||||
(*(it.first)).makeWithdrawal( *(it.second) );
|
||||
}
|
||||
|
||||
Account::displayAccountsInfos();
|
||||
std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************** //
|
||||
// vim: set ts=4 sw=4 tw=80 noexpandtab: //
|
||||
// -*- indent-tabs-mode:t; -*-
|
||||
// -*- mode: c++-mode; -*-
|
||||
// -*- fill-column: 75; comment-column: 75; -*-
|
||||
// ************************************************************************** //
|
||||
BIN
cpp00/ex02/tests.o
Normal file
BIN
cpp00/ex02/tests.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user