What's wrong with this!!!

Hello!!!
Finally, after lot of work i write my program but my program crashes...Here's the code of my program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//User.h
class User
{
      protected:
      int ID;
      char *Name;
      char *Address;
      char *Status;
      
      public:
      User(){};
      User(int id,char *name,char *address,char *status){
      if(id<0)
      {
           ID=0;
           }
           else
           {
               ID=id;
               }
      if(strlen(name)>0)
      {
           Name=new char[strlen(name)+1];
           strcpy(Name,name);
           }
           else
           {
               Name=NULL;
               }
      if(strlen(address)>0)
      {
           Address=new char[strlen(address)+1];
           strcpy(Address,address);
           }
           else
           {
               Address=NULL;
               }
      if(strlen(status)>0)
      {
           Status=new char[strlen(status)+1];
           strcpy(Status,status);
           }
           else
           {
               Status=NULL;
               }
      }
      ~User(){
      }
      void setID()
      {
           cout<<"Enter ID: ";
           cin>>ID;
           }
      void setName()
      {
           cout<<"Enter Name: ";
           cin>>Name;
           }
      void setAddress()
      {
           cout<<"Enter Address: ";
           cin>>Address;
           }
      void setStatus()
      {
           cout<<"Set Status: ";
           cin>>Status;
           }
      int getID()
      {
           return ID;
           }
      char *getName()
      {
           return Name;
           }
      char *getAddress()
      {
           return Address;
           }
      char *getStatus()
      {
           return Status;
           }
};
//Members.h
class Members: public User
{
      char *Password;
      
      public:
      Members(){};
      Members(char *password){
      if(strlen(password)>0)
      {
           Password=new char[strlen(password)+1];
           strcpy(Password,password);
           }
           else
           {
               Password=NULL;
               }
      }
      ~Members(){
      }
      void setPassword()
      {
           cout<<"Enter Password: ";
           cin>>Password;
      }
      char *getPassword()
      {
           return Password;
           }
      void AddMember()
      {
           cout<<"Adding new member information! Please wait....\n"<<endl;
           setID();
           setName();
           setAddress();
           setStatus();
           setPassword();
           cout<<"New member information successfully added....\n"<<endl;
           }
};
#include "User.h"
#include "Members.h"
int main()
{
    Members obj1;
    obj1.AddMember();
    system ("PAUSE");
    getch();
}

This program successfully compiles but after (Set Status prompt) this program crashes. What the hell is wrong with this code? Any kind of help to fix this problem is appreciated.....Thanks!!!
Last edited on
Do you forget about memory allocation for status variable?

It is a much better to use std::string instead of char* for Name, Address, Status.
No memory is allocated for status variable you can see in this code but after (Set Status prompt not on Set Status) when try to ask for (Enter Password) in derived class.
Please someone help me on this problem......... :(
You are using the default constructor, that do nothing.
Can u set the default values of variables in default constructor.......Or can you fix this?
Anybody here who can fix this code???? :(
Try using std::string rather than char*:
http://cplusplus.com/reference/string/string/
I want you guys to fix that piece of code because i don't know anything about C++ strings.....I don't know how to use them.....Please see the code above and try to fix this code with your knowledge......Thanks!!!
Dear hassaanid2011,

I would like to respectfully suggest that you moderate your requests, and make some attempt at researching the solutions that were so kindly given to you. To further this endeavor, I shall compile them here, as follows:

Research std::string at http://cplusplus.com/reference/string/string
Refrain from using char*

In addition, I would like to suggest, very respectfully, that you look at this post, as it may assist you in learning how to successfully request assistance in an internet forum:

http://www.cplusplus.com/forum/beginner/1/#msg6680

Last, I would like you to consider doing one of the following two things: RTFM or choose another career.

Very Respectfully,
ciphermagi
Topic archived. No new replies allowed.