Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- class Postachalnik {
- char* country;
- char* name;
- char* phone;
- public:
- Postachalnik();
- Postachalnik(char*, char*, char*);
- Postachalnik(Postachalnik&);
- ~Postachalnik();
- char* GetCountry() { return country; };
- char* GetName() { return name; };
- char* GetPhone() { return phone; };
- void PrintFull();
- void PrintPart();
- Postachalnik& SetCountry(char*);
- Postachalnik& SetName(char*);
- Postachalnik& SetPhone(char*);
- };
- Postachalnik::Postachalnik() {
- country = new char [11];
- strcpy(country, "no country");
- name = new char[8];
- strcpy(name, "no name");
- phone = new char[9];
- strcpy(phone, "no phone");
- }
- Postachalnik::Postachalnik(char* CountryToAdd, char* NameToAdd, char* PhoneToAdd){
- name = new char[strlen(NameToAdd) + 1];
- strcpy(name, NameToAdd);
- country = new char[strlen(CountryToAdd) + 1];
- strcpy(country, CountryToAdd);
- phone = new char[strlen(PhoneToAdd) + 1];
- strcpy(phone, PhoneToAdd);
- }
- Postachalnik::Postachalnik(Postachalnik& a) {
- country = new char[strlen(a.country) + 1];
- name = new char[strlen(a.name) + 1];
- phone = new char[strlen(a.phone) + 1];
- strcpy(country, a.country);
- strcpy(name, a.name);
- strcpy(phone, a.phone);
- }
- Postachalnik::~Postachalnik() {
- delete name;
- delete country;
- delete phone;
- }
- void Postachalnik::PrintFull() {
- std::cout << name << '\t' << country << '\t' << phone << '\n';
- }
- void Postachalnik::PrintPart() {
- std::cout << name << '\n';
- }
- Postachalnik& Postachalnik::SetCountry(char* CountryToAdd) {
- delete country;
- country = new char[strlen(CountryToAdd) + 1];
- strcpy(country, CountryToAdd);
- return *this;
- }
- Postachalnik& Postachalnik::SetName(char* NameToAdd) {
- delete name;
- name = new char[strlen(NameToAdd) + 1];
- strcpy(name, NameToAdd);
- return *this;
- }
- Postachalnik& Postachalnik::SetPhone(char* PhoneToAdd) {
- delete phone;
- phone = new char[strlen(PhoneToAdd) + 1];
- strcpy(phone, PhoneToAdd);
- return *this;
- }
- class Product {
- Postachalnik obj;
- char* product;
- int count;
- float price;
- public:
- Product();
- Product(char*, int, float, Postachalnik&);
- Product(Product&);
- ~Product();
- Product& SetPostachalnik(Postachalnik&);
- Product& SetProduct(char*);
- Product& SetCount(int);
- Product& SetPrice(float);
- Postachalnik GetObject();
- char* GetProduct();
- int GetCount();
- float GetPrice();
- void PrintFull();
- };
- Product::Product() {
- product = new char[8];
- strcpy(product, "no name");
- count = 0;
- price = 0;
- Postachalnik firma;
- }
- Product::Product(char* NameToAdd, int CounttoAdd, float PriceToAdd, Postachalnik& ObjectToAdd) {
- product = new char[strlen(NameToAdd) + 1];
- strcpy(product, NameToAdd);
- count = CounttoAdd;
- price = PriceToAdd;
- obj = ObjectToAdd;
- }
- Product::Product(Product& a) {
- product = new char[strlen(a.product) + 1];
- count = a.count;
- price = a.price;
- obj = a.obj;
- }
- Product::~Product() {
- delete product;
- obj.~Postachalnik();
- }
- Postachalnik Product::GetObject() {
- return obj;
- }
- int Product::GetCount(){
- return count;
- }
- char* Product::GetProduct(){
- return product;
- }
- float Product::GetPrice() {
- return price;
- }
- void Product::PrintFull() {
- std::cout << product << '\t' << count << '\t' << price << '\t';
- obj.PrintFull();
- }
- int main()
- {
- char COUNTRY[20];
- char NAME[20];
- char PHONE[20];
- Postachalnik Obj1;
- std::cout << "Enter Postachalnik as Country,Name,Phone";
- std::cin >> COUNTRY;
- std::cin >> NAME;
- std::cin >> PHONE;
- Postachalnik Obj2(COUNTRY, NAME, PHONE);
- Postachalnik Obj3 = Obj2;
- Obj1.PrintFull();
- Obj2.PrintFull();
- Obj3.PrintFull();
- Obj1.SetName(COUNTRY).SetCountry(NAME).SetPhone(PHONE);
- std::cout << "Objects after changes:" << '\n';
- Obj1.PrintFull();
- Obj2.PrintFull();
- Obj3.PrintFull();
- Obj1.SetCountry(PHONE);
- Obj2.SetName(COUNTRY);
- Obj3.SetPhone(NAME);
- Obj1.PrintFull();
- Obj2.PrintFull();
- Obj3.PrintFull();
- Product object1;
- Product object2(NAME, 10, 3.5, Obj3);
- object1.PrintFull();
- object2.PrintFull();
- object2.GetObject().PrintFull();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement