Отчет 6 - ООП - СФ
.pdfПриложение А
(обязательное)
Код программы
#include <iostream> #include <string> using namespace std;
class TextBox
{
public:
string text;
virtual bool createText() = 0; virtual bool deleteText() = 0;
};
class User
{
protected:
string adress; public:
string GetAdress()
{
return adress;
}
void PrintAdress()
{
cout << "Adress: " << adress << endl;
}
string SetAdress(string adress)
{
this->adress = adress; return adress;
}
};
class Message : public TextBox
{
public:
void PrintText()
{
cout << "Cообщение: " << text << endl;
}
bool createText() override
{
cout<<"Сообщение \""<<text<<"\" отправлено." << endl; return true;
}
bool deleteText() override
{
cout << "Сообщение \"" << text << "\" удалено." << endl; return true;
}
};
class Notebook : public TextBox
{
static int countNote; public:
bool createText() override
{
cout << "Заметка \"" << text << "\" создана." << endl; countNote += 1;
11
return true;
}
bool deleteText() override
{
countNote -= 1;
cout << "Заметка \"" << text << "\" удалена." << endl; return true;
}
static void ShowCountNote()
{
cout << "Всего заметок: " << countNote << endl;
}
};
class Calendar : public TextBox
{
private:
bool ChekDate()
{
if (day > 0 && day <= 31 && month>0 && month <= 12 && year > 0 && year <
9999)
return true;
else
return false;
}
public:
int day; int month; int year;
bool createText() override
{
if (ChekDate())
{
cout << "Напоминание: \""<< text << "\"\nДобавлено на дату: " << day << "." << month << "." << year << endl;
return true;
}
else
{
cout << "Введена некорректная дата." << endl; return false;
}
}
bool deleteText() override
{
if (ChekDate())
{
cout << "Напоминание удалено (Дата: " << day << "." << month << "." << year <<")" << endl;
return true;
}
else
{
cout << "Введена некорректная дата." << endl; return false;
}
}
};
class Contacts : public User
{
public:
bool AddContact()
{
cout << "Контакт добавлен - " << adress << endl;
12
return true;
}
bool deleteContact()
{
cout << "Контакт удален - "<< adress << endl; return true;
}
};
class MailClient : public User, public Message
{
private:
string pass; public:
string SetPass(string pass)
{
this->pass = pass; return pass;
}
bool AddAccount()
{
if(pass != "")
{
cout << "Аккаунт с адресом: " << adress << " добавлен" << endl; return true;
}
else
{
cout << "Введите пароль!" << endl; return false;
}
}
void GetInfo()
{
cout << "\n\tInfo about email\n" << endl;
cout << "-\tEmail: " << adress << "\t-" << endl << endl;
}
};
int Notebook::countNote = 0; int main()
{
setlocale(LC_ALL, "ru");
MailClient firstUser; firstUser.SetAdress("firstemail"); firstUser.SetPass("qwerty123"); firstUser.AddAccount();
firstUser.text = "Тестовое сообщение."; firstUser.PrintText(); firstUser.createText(); firstUser.deleteText(); firstUser.GetInfo();
cout << "------------\n"<<endl;
Notebook firstNote; Notebook secondNote; Notebook thirdNote;
firstNote.text = "Яйцо варится 10 минут"; firstNote.createText();
secondNote.text = "2+2*2 = 6"; secondNote.createText(); thirdNote.text = "ящерица не бегемот";
13
thirdNote.createText(); Notebook::ShowCountNote(); secondNote.deleteText(); Notebook::ShowCountNote();
cout << "\n------------\n" << endl;
Calendar date; date.day = 31; date.month = 12; date.year = 1999;
date.text = "Переход в следующее тысячелетие - Милениум"; date.createText();
date.deleteText();
cout << "\n------------\n" << endl;
Contacts friend1; friend1.SetAdress("friend1@gmail.com"); friend1.AddContact(); friend1.deleteContact();
return 0;
}
14
