Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #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) {
- if(country)
- delete[] country;
- country = new char[strlen(CountryToAdd) + 1];
- strcpy(country, CountryToAdd);
- return *this;
- }
- Postachalnik& Postachalnik::SetName(char* NameToAdd) {
- if(name)
- delete name;
- name = new char[strlen(NameToAdd) + 1];
- strcpy(name, NameToAdd);
- return *this;
- }
- Postachalnik& Postachalnik::SetPhone(char* PhoneToAdd) {
- if(phone)
- delete phone;
- phone = new char[strlen(PhoneToAdd) + 1];
- strcpy(phone, PhoneToAdd);
- return *this;
- }
- class Product {
- char* product;
- int count;
- float price;
- Postachalnik obj;
- public:
- Product();
- Product(char*, int, float, Postachalnik&);
- Product(Product&);
- ~Product();
- Product& SetPostachalnik(Postachalnik&);
- Product& SetProduct(char*);
- Product& SetCount(int);
- Product& SetPrice(float);
- Postachalnik GetObject() { return obj; }
- char* GetProduct() { return product; }
- int GetCount() { return count; }
- float GetPrice() { return price; }
- void PrintFull();
- void PrintPart();
- };
- Product::Product() {
- product = new char[8];
- strcpy(product, "no name");
- count = 0;
- price = 0;
- }
- Product::Product(char* NameToAdd, int CounttoAdd, float PriceToAdd, Postachalnik& ObjectToAdd) {
- product = new char[strlen(NameToAdd) + 1];
- strcpy(product, NameToAdd);
- count = CounttoAdd;
- price = PriceToAdd;
- obj.SetCountry(ObjectToAdd.GetCountry());
- obj.SetName(ObjectToAdd.GetName());
- obj.SetPhone(ObjectToAdd.GetPhone());
- }
- Product::Product(Product& a) {
- product = new char[strlen(a.product) + 1];
- strcpy(product, a.product);
- count = a.count;
- price = a.price;
- obj.SetName(a.obj.GetName());
- obj.SetCountry(a.obj.GetCountry());
- obj.SetPhone(a.obj.GetPhone());
- }
- Product::~Product() {
- delete product;
- }
- Product& Product::SetCount(int i) {
- count = i;
- return *this;
- }
- Product& Product::SetPostachalnik(Postachalnik& Set_Object) {
- obj.SetCountry(Set_Object.GetCountry());
- return *this;
- }
- Product& Product::SetPrice(float i) {
- price = i;
- return *this;
- }
- Product& Product::SetProduct(char* name) {
- if (product)
- delete[] product;
- product = new char[strlen(name) + 1];
- strcpy(product, name);
- return *this;
- }
- void Product::PrintFull() {
- std::cout << product << '\t' << count << '\t' << price << '\t';
- obj.PrintFull();
- }
- void Product::PrintPart() {
- std::cout << obj.GetName() << product;
- }
- int main()
- {
- char COUNTRY[20];
- char NAME[20];
- char PHONE[20];
- char PHONE2[20];
- Postachalnik Obj1;
- std::cout << "Enter Postachalnik as Country,Name,Phone\n";
- std::cin >> COUNTRY;
- std::cin >> NAME;
- std::cin >> PHONE;
- Postachalnik Obj2(NAME, COUNTRY, PHONE);
- std::cout << "Enter a callcenter phone of company\n";
- std::cin >> PHONE2;
- Postachalnik Obj3(Obj2);
- Obj3.SetPhone(PHONE2);
- int k;
- std::cout << "chose a type of Postachalnik information\n" << "1-for Full\t" <<"2-for a PART\n";
- std::cin >> k;
- switch (k)
- {
- case 1:
- Obj1.PrintFull();
- Obj2.PrintFull();
- Obj3.PrintFull();
- break;
- case 2:
- Obj1.PrintPart();
- Obj2.PrintPart();
- Obj3.PrintPart();
- }
- Product object1;
- int COUNT;
- float PRICE;
- char PRODUCT[20];
- std::cout << "Enter Product, count of product amd price\n";
- std::cin >> PRODUCT;
- std::cin >> COUNT;
- std::cin >> PRICE;
- Product object2(PRODUCT, COUNT, PRICE, Obj2);
- Product object3(object2);
- float PRICE2;
- std::cout << "Enter price in euro\n";
- std::cin >> PRICE2;
- object3.SetPrice(PRICE2);
- std::cout << "chose a type of Product information\n" << "1-for Full\t" << "2-for a PART\n";
- std::cin >> k;
- switch (k)
- {
- case 1:
- object1.PrintFull();
- object2.PrintFull();
- object3.PrintFull();
- break;
- case 2:
- object1.PrintPart();
- object2.PrintPart();
- object3.PrintPart();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement