Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>;
- #include <iostream>;
- using namespace std;
- class Hello {
- public:
- Hello::Hello();
- Hello::~Hello();
- void getName();
- void setName(char *name);
- void sayName();
- private:
- char name[100];
- char *start;
- };
- int main() {
- Hello* h = new Hello();
- h->getName();
- h->sayName();
- h->~Hello();
- }
- Hello::Hello() {
- this->start = this->name;
- }
- Hello::~Hello() { }
- void Hello::getName() {
- char gn[100];
- cout << "What is your name? ";
- cin >> gn;
- this->setName(gn);
- }
- void Hello::setName(char *name) {
- int c = 0;
- while (*name != '\0') {
- this->name[c] = *name;
- name++;
- c++;
- }
- this->name[c] = '\0';
- }
- void Hello::sayName() {
- cout << "Your name is: " << this->start << "." << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement