intrat to gitea
This commit is contained in:
commit
025e205b80
|
|
@ -0,0 +1,29 @@
|
|||
NAME = megaphone
|
||||
|
||||
SRCS = megaphone.cpp
|
||||
|
||||
CC = clang++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
|
||||
RM = rm -f
|
||||
|
||||
OBJS = $(SRCS:.cpp=.o)
|
||||
|
||||
%.o: %.cpp
|
||||
@$(CC) $(FLAGS) -c $< -o $@
|
||||
|
||||
all : $(NAME)
|
||||
|
||||
$(NAME) : $(OBJS)
|
||||
@$(CC) $(CFLAGS) $^ -o $(NAME)
|
||||
@echo '$(NAME) compiled!'
|
||||
|
||||
fclean : clean
|
||||
@$(RM) $(NAME)
|
||||
|
||||
clean :
|
||||
@$(RM) $(OBJS)
|
||||
|
||||
re : fclean all
|
||||
|
||||
.PHONY : all clean fclean re
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int i = 1;
|
||||
int j = 0;
|
||||
|
||||
if (ac == 1)
|
||||
{
|
||||
std::cout << "* LOUD AND UNBEARABLE FEEDBACK NOISE *" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
while (av[i])
|
||||
{
|
||||
while (av[i][j])
|
||||
{
|
||||
if (av[i][j] >= 'a' && av[i][j] <= 'z')
|
||||
{
|
||||
av[i][j] = toupper(av[i][j]);
|
||||
j++;
|
||||
}
|
||||
else
|
||||
j++;
|
||||
}
|
||||
std::cout << av[i];
|
||||
i++;
|
||||
j = 0;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
#include "PhoneBook.hpp"
|
||||
#include "Contact.hpp"
|
||||
|
||||
Contact::Contact() {
|
||||
}
|
||||
|
||||
Contact::~Contact() {
|
||||
}
|
||||
|
||||
void Contact::setFirstName(const std::string& firstName)
|
||||
{
|
||||
_firstName = firstName;
|
||||
}
|
||||
|
||||
void Contact::setLastName(const std::string& lastName)
|
||||
{
|
||||
_lastName = lastName;
|
||||
}
|
||||
|
||||
void Contact::setNickname(const std::string& nickname)
|
||||
{
|
||||
_nickname = nickname;
|
||||
}
|
||||
|
||||
void Contact::setPhoneNumber(const std::string& phoneNumber)
|
||||
{
|
||||
_phoneNumber = phoneNumber;
|
||||
}
|
||||
|
||||
void Contact::setDarkestSecret(const std::string& darkestSecret)
|
||||
{
|
||||
_darkestSecret = darkestSecret;
|
||||
}
|
||||
|
||||
std::string Contact::getFirstName() const {
|
||||
return _firstName;
|
||||
}
|
||||
|
||||
std::string Contact::getLastName() const {
|
||||
return _lastName;
|
||||
}
|
||||
|
||||
std::string Contact::getNickname() const {
|
||||
return _nickname;
|
||||
}
|
||||
|
||||
std::string Contact::getPhoneNumber() const {
|
||||
return _phoneNumber;
|
||||
}
|
||||
|
||||
std::string Contact::getDarkestSecret() const {
|
||||
return _darkestSecret;
|
||||
}
|
||||
|
||||
bool Contact::isEmpty() const {
|
||||
return _firstName.empty();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
|
||||
class Contact {
|
||||
private:
|
||||
std::string _firstName;
|
||||
std::string _lastName;
|
||||
std::string _nickname;
|
||||
std::string _phoneNumber;
|
||||
std::string _darkestSecret;
|
||||
|
||||
public:
|
||||
Contact();
|
||||
~Contact();
|
||||
// Setters
|
||||
void setFirstName(const std::string& firstName);
|
||||
void setLastName(const std::string& lastName);
|
||||
void setNickname(const std::string& nickname);
|
||||
void setPhoneNumber(const std::string& phoneNumber);
|
||||
void setDarkestSecret(const std::string& darkestSecret);
|
||||
|
||||
// Getters
|
||||
std::string getFirstName() const;
|
||||
std::string getLastName() const;
|
||||
std::string getNickname() const;
|
||||
std::string getPhoneNumber() const;
|
||||
std::string getDarkestSecret() const;
|
||||
|
||||
bool isEmpty() const;
|
||||
};
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
NAME = PhoneBook
|
||||
|
||||
SRCS = main.cpp PhoneBook.cpp Contact.cpp
|
||||
|
||||
CC = clang++
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
|
||||
RM = rm -f
|
||||
|
||||
OBJS = $(SRCS:.cpp=.o)
|
||||
|
||||
%.o: %.cpp
|
||||
@$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
@$(CC) $(CFLAGS) $^ -o $(NAME)
|
||||
@echo '$(NAME) compiled!'
|
||||
|
||||
fclean: clean
|
||||
@$(RM) $(NAME)
|
||||
|
||||
clean:
|
||||
@$(RM) $(OBJS)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
#include "PhoneBook.hpp"
|
||||
|
||||
PhoneBook::PhoneBook() {
|
||||
_currentIndex = 0;
|
||||
_totalContacts = 0;
|
||||
}
|
||||
|
||||
PhoneBook::~PhoneBook() {}
|
||||
void PhoneBook::addContact() {
|
||||
Contact tempContact;
|
||||
std::string input;
|
||||
|
||||
while (true) {
|
||||
std::cout << "Enter first name: ";
|
||||
if (!std::getline(std::cin, input)) exit(1);
|
||||
if (!input.empty()) break;
|
||||
std::cout << "Field cannot be empty!" << std::endl;
|
||||
}
|
||||
tempContact.setFirstName(input);
|
||||
while (true) {
|
||||
std::cout << "Enter last name: ";
|
||||
if (!std::getline(std::cin, input)) exit(1);
|
||||
if (!input.empty()) break;
|
||||
std::cout << "Field cannot be empty!" << std::endl;
|
||||
}
|
||||
tempContact.setLastName(input);
|
||||
while (true) {
|
||||
std::cout << "Enter nickname: ";
|
||||
if (!std::getline(std::cin, input)) exit(1);
|
||||
if (!input.empty()) break;
|
||||
std::cout << "Field cannot be empty!" << std::endl;
|
||||
}
|
||||
tempContact.setNickname(input);
|
||||
while (true) {
|
||||
std::cout << "Enter phone number: ";
|
||||
if (!std::getline(std::cin, input)) exit(1);
|
||||
if (!input.empty()) break;
|
||||
std::cout << "Field cannot be empty!" << std::endl;
|
||||
}
|
||||
tempContact.setPhoneNumber(input);
|
||||
while (true) {
|
||||
std::cout << "Enter Darkest Secret: ";
|
||||
if (!std::getline(std::cin, input)) exit(1);
|
||||
if (!input.empty()) break;
|
||||
std::cout << "Field cannot be empty!" << std::endl;
|
||||
}
|
||||
tempContact.setDarkestSecret(input);
|
||||
|
||||
_contacts[_currentIndex] = tempContact;
|
||||
_currentIndex = (_currentIndex + 1) % 8;
|
||||
if (_totalContacts < 8) _totalContacts++;
|
||||
|
||||
std::cout << "Contact added successfully!" << std::endl;
|
||||
}
|
||||
|
||||
void PhoneBook::searchContacts() const {
|
||||
std::string input;
|
||||
int index;
|
||||
|
||||
if (_totalContacts == 0) {
|
||||
std::cout << "Phone book is empty!" << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cout << std::setw(10) << "Index" << "|"
|
||||
<< std::setw(10) << "First Name" << "|"
|
||||
<< std::setw(10) << "Last Name" << "|"
|
||||
<< std::setw(10) << "Nickname" << std::endl;
|
||||
std::cout << "----------------------------------------" << std::endl;
|
||||
int i = 0;
|
||||
while (i < _totalContacts) {
|
||||
std::cout << std::setw(10) << i << "|"
|
||||
<< std::setw(10) << truncateString(_contacts[i].getFirstName()) << "|"
|
||||
<< std::setw(10) << truncateString(_contacts[i].getLastName()) << "|"
|
||||
<< std::setw(10) << truncateString(_contacts[i].getNickname()) << std::endl;
|
||||
i++;
|
||||
}
|
||||
while (true) {
|
||||
std::cout << "Enter the index of the contact to display: ";
|
||||
if (!std::getline(std::cin, input)) {
|
||||
exit(1);
|
||||
}
|
||||
if (input.length() == 1 && input[0] >= '0' && input[0] <= '7') {
|
||||
index = input[0] - '0';
|
||||
if (index < _totalContacts) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::cout << "Invalid index! Please enter a valid contact index." << std::endl;
|
||||
}
|
||||
displayContact(index);
|
||||
}
|
||||
|
||||
std::string PhoneBook::truncateString(const std::string& str) const {
|
||||
if (str.length() > 10) {
|
||||
return str.substr(0, 9) + ".";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
void PhoneBook::displayContact(int index) const {
|
||||
std::cout << std::endl << "=== Contact Details ===" << std::endl;
|
||||
std::cout << "First Name: " << _contacts[index].getFirstName() << std::endl;
|
||||
std::cout << "Last Name: " << _contacts[index].getLastName() << std::endl;
|
||||
std::cout << "Nickname: " << _contacts[index].getNickname() << std::endl;
|
||||
std::cout << "Phone Number: " << _contacts[index].getPhoneNumber() << std::endl;
|
||||
std::cout << "Darkest Secret: " << _contacts[index].getDarkestSecret() << std::endl;
|
||||
std::cout << "======================" << std::endl;
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#include "Contact.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iomanip>
|
||||
|
||||
class PhoneBook {
|
||||
private:
|
||||
Contact _contacts[8];
|
||||
int _currentIndex;
|
||||
int _totalContacts;
|
||||
|
||||
public:
|
||||
PhoneBook();
|
||||
~PhoneBook();
|
||||
|
||||
void addContact();
|
||||
void searchContacts() const;
|
||||
void displayContact(int index) const;
|
||||
std::string truncateString(const std::string& str) const;
|
||||
};
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
# include <iostream>
|
||||
# include <iomanip>
|
||||
# include <string>
|
||||
#include "PhoneBook.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string command;
|
||||
PhoneBook phoneBook;
|
||||
|
||||
while (42)
|
||||
{
|
||||
std::cout << "Enter a command > ";
|
||||
if (!std::getline(std::cin, command))
|
||||
{
|
||||
std::cout << "\nBye!" << std::endl;
|
||||
break;
|
||||
}
|
||||
else if (command == "ADD")
|
||||
{
|
||||
phoneBook.addContact();
|
||||
}
|
||||
else if (command == "SEARCH")
|
||||
{
|
||||
phoneBook.searchContacts();
|
||||
}
|
||||
else if (command == "EXIT")
|
||||
{
|
||||
std::cout << "EXIT" << std::endl;
|
||||
break;
|
||||
}
|
||||
else
|
||||
std::cout << "Invalid command. Please use ADD, SEARCH, or EXIT." << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue