#include <iostream>
#include <cstring>
using namespace std;
class Cook {
char* name;
char* surname;
public:
Cook();
Cook(char*, char*);
Cook(Cook&);
~Cook();
char* getName();
char* getSurname();
Cook& setName(char*);
Cook& setSurname(char*);
void print();
};
Cook::Cook() {
name = new char[20];
strcpy(name, "No_name");
surname = new char[20];
strcpy(surname, "No_surname");
};
Cook::Cook(char* fname, char* fsurname)
{
name = new char[strlen(fname) + 1];
strcpy(name, fname);
surname = new char[strlen(fsurname) + 1];
strcpy(surname, fsurname);
};
Cook::Cook(Cook& other) {
name = new char[strlen(other.name) + 1];
strcpy(name, other.name);
surname = new char[strlen(other.surname) + 1];
strcpy(surname, other.surname);
};
Cook::~Cook() {
delete[] name;
delete[] surname;
};
char* Cook::getName() {
return name;
};
char* Cook::getSurname() {
return surname;
};
Cook& Cook::setName(char* fname) {
delete[] name;
name = new char[strlen(fname) + 1];
strcpy(name, fname);
return *this;
};
Cook& Cook::setSurname(char* fsurname) {
delete[] surname;
surname = new char[strlen(fsurname) + 1];
strcpy(surname, fsurname);
return *this;
};
void Cook::print() {
cout << "Cook:" << " " << name << " " << surname << endl;
};
class Dish {
Cook chef;
char* name_dish;
int price;
public:
Dish();
Dish(char*, char*, char*, int);
Dish(Dish&);
~Dish();
char* getName();
int getPrice();
Cook& getChef();
Dish& setNameDish(char*);
Dish& setPrice(int);
Dish& setChef(Cook&);
void printDish();
};
Dish::Dish() : chef(), price(0) {
name_dish = new char[20];
strcpy(name_dish, "No_name");
};
Dish::Dish(char* fname, char* fsurname, char* fname_dish, int fprice) :chef(fname, fsurname), price(fprice)
{
name_dish = new char[strlen(fname_dish) + 1];
strcpy(name_dish, fname_dish);
};
Dish::Dish(Dish& other) : chef(other.chef), price(other.price) {
name_dish = new char[strlen(other.name_dish) + 1];
strcpy(name_dish, other.name_dish);
};
Dish::~Dish() {
delete[] name_dish;
};
char* Dish::getName() {
return name_dish;
};
int Dish::getPrice() {
return price;
};
Cook& Dish::getChef() {
return chef;
};
Dish& Dish::setNameDish(char* fname_dish) {
delete[] name_dish;
name_dish = new char[strlen(fname_dish) + 1];
strcpy(name_dish, fname_dish);
return *this;
};
Dish& Dish::setPrice(int fprice) {
price = fprice;
return *this;
};
Dish& Dish::setChef(Cook& fchef) {
chef = fchef;
return *this;
};
void Dish::printDish() {
cout << "Dish:" << " " << name_dish << " " << price << " " << chef.getName() << " " << chef.getSurname() << endl;
};
int main()
{
int fprice;
char fname_dish[30];
char fname[30];
char fsurname[30];
Cook obj1;
cout << "Enter name of chef: " << endl;
cin >> fname;
cout << "Enter surname of chef: " << endl;
cin >> fsurname;
Cook obj2(fname, fsurname);
Cook obj3 = obj2;
cout << "This is objects before change: " << endl;
obj1.print();
obj2.print();
obj3.print();
Dish dish1;
cout << "Enter name of Dish: " << endl;
cin >> fname_dish;
cout << "Enter price of dish: " << endl;
cin >> fprice;
Dish dish2(fname, fsurname, fname_dish, fprice);
Dish dish3 = dish2;
cout << "This is dishes before change: " << endl;
dish1.printDish();
dish2.printDish();
dish3.printDish();
cout << "New name of dish for obj3:" << endl;
cin >> fname_dish;
cout << "Enter new price for obj3:" << endl;
cin >> fprice;
cout << "Enter new name of chef obj3:" << endl;
cin >> fname;
cout << "Enter new surname of chef obj3:" << endl;
cin >> fsurname;
obj3.setName(fname).setSurname(fsurname);
cout << "This is obj3 after change:" << endl;
dish3.setNameDish(fname_dish).setPrice(fprice).setChef(obj3);
cout << "This is dish3 after change:" << endl;
dish1.printDish();
dish2.printDish();
dish3.printDish();
return 0;
}