even better
This commit is contained in:
parent
31ed280bb9
commit
6f31bee965
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/19 16:52:26 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/31 13:38:09 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/04/01 11:37:19 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -28,9 +28,7 @@ int main(int argc, char **argv)
|
||||
{
|
||||
str = argv[i];
|
||||
for (char c : str)
|
||||
{
|
||||
std::cout << (char)toupper(c);
|
||||
}
|
||||
std::cout << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/20 10:53:48 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/31 14:40:58 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/04/01 11:38:02 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/20 11:02:32 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/31 14:58:09 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/04/01 09:17:51 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include "Contact.hpp"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cctype>
|
||||
|
||||
PhoneBook::PhoneBook()
|
||||
{
|
||||
@ -78,6 +79,16 @@ void PhoneBook::printContact(const int i) const
|
||||
return;
|
||||
}
|
||||
|
||||
bool isNumeric(const std::string &str)
|
||||
{
|
||||
for (char c : str)
|
||||
{
|
||||
if (!std::isdigit(c))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PhoneBook::searchContact() const
|
||||
{
|
||||
std::string command;
|
||||
@ -93,38 +104,29 @@ void PhoneBook::searchContact() const
|
||||
std::cout << "---------------------------------------------" << std::endl;
|
||||
|
||||
int index = -1;
|
||||
|
||||
while (true)
|
||||
{
|
||||
std::cout << "Enter the index of the contact you want to see: ";
|
||||
|
||||
while (index < 0)
|
||||
{
|
||||
std::getline(std::cin, command);
|
||||
std::cout << std::endl;
|
||||
if (command == "EXIT")
|
||||
break;
|
||||
if (command.empty())
|
||||
return;
|
||||
if (!isNumeric(command))
|
||||
{
|
||||
std::cout << "Invalid index" << std::endl;
|
||||
std::cout << "Invalid index. Please enter a number: ";
|
||||
continue;
|
||||
}
|
||||
try
|
||||
index = std::stoi(command);
|
||||
if (index < 0 || index >= _contactCount)
|
||||
{
|
||||
index = std::stoi(command); //0dsfsdf is also valid....
|
||||
std::cout << "Invalid index. Please enter a number: ";
|
||||
index = -1;
|
||||
}
|
||||
catch (const std::invalid_argument &e)
|
||||
{
|
||||
std::cout << "Invalid index" << std::endl;
|
||||
continue;
|
||||
}
|
||||
catch (const std::out_of_range &e)
|
||||
{
|
||||
std::cout << "Index out of range" << std::endl;
|
||||
continue;
|
||||
}
|
||||
if (index >= 0 && index < _contactCount)
|
||||
{
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "---------------------------------------------" << std::endl;
|
||||
printContact(index);
|
||||
std::cout << "---------------------------------------------" << std::endl;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user