Advertisement
andrewb

Project1.cpp

May 13th, 2014
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <stdio.h>;
  2. #include <iostream>;
  3.  
  4. using namespace std;
  5.  
  6. class Hello {
  7. public:
  8.     Hello::Hello();
  9.     Hello::~Hello();
  10.     void getName();
  11.     void setName(char *name);
  12.     void sayName();
  13. private:
  14.     char name[100];
  15.     char *start;
  16. };
  17.  
  18. int main() {
  19.     Hello* h = new Hello();
  20.     h->getName();
  21.     h->sayName();
  22.     h->~Hello();
  23. }
  24.  
  25. Hello::Hello() {
  26.     this->start = this->name;
  27. }
  28.  
  29. Hello::~Hello() { }
  30.  
  31. void Hello::getName() {
  32.     char gn[100];
  33.     cout << "What is your name? ";
  34.     cin >> gn;
  35.     this->setName(gn);
  36. }
  37.  
  38. void Hello::setName(char *name) {
  39.     int c = 0;
  40.     while (*name != '\0') {
  41.         this->name[c] = *name;
  42.         name++;
  43.         c++;
  44.     }
  45.     this->name[c] = '\0';
  46. }
  47.  
  48. void Hello::sayName() {
  49.     cout << "Your name is: " << this->start << "." << endl;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement