Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class NameCard
- {
- private:
- char *name;
- char *phone;
- char *company;
- char *position;
- public:
- NameCard(char *name, char *phone, char *company, char *position)
- {
- this->name = new char(strlen(name) + 1);
- this->phone = new char(strlen(phone) + 1);
- this->company = new char(strlen(company) + 1);
- this->position = new char(strlen(position) + 1);
- strncpy_s(this->name, strlen(name) + 1, name, strlen(name));
- strncpy_s(this->phone, strlen(phone) + 1, phone, strlen(phone));
- strncpy_s(this->company, strlen(company) + 1, company, strlen(company));
- strncpy_s(this->position, strlen(position) + 1, position, strlen(position));
- }
- NameCard(const NameCard& c)
- {
- this->name = new char(strlen(c.name)+1);
- this->phone = new char(strlen(c.phone) + 1);
- this->company = new char(strlen(c.company) + 1);
- this->position = new char(strlen(c.position) + 1);
- strncpy_s(this->name, strlen(c.name) + 1, c.name, strlen(c.name));
- strncpy_s(this->phone, strlen(c.phone) + 1, c.phone, strlen(c.phone));
- strncpy_s(this->company, strlen(c.company) + 1, c.company, strlen(c.company));
- strncpy_s(this->position, strlen(c.position) + 1, c.position, strlen(c.position));
- }
- ~NameCard()
- {
- delete[] this->name;
- delete[] this->phone;
- delete[] this->company;
- delete[] this->position;
- }
- void ShowData()
- {
- cout << this->name << endl;
- cout << this->phone << endl;
- cout << this->company << endl;
- cout << this->position << endl;
- }
- };
- int main()
- {
- NameCard James("James", "11231123", "la", "manager");
- James.ShowData();
- NameCard James2(James);
- James2.ShowData();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement