Subj : Newb question on style and choices To : borland.public.cpp.borlandcpp From : "Base8" Date : Sat Nov 29 2003 03:18 pm Hi all, I'm using BC++ 4.0 and I'm looking for some feedback on style and the choices I've made in the class included below. Please comment on anything you'd like that helps me advance in my understanding of C++ (I haven't had any classes or courses on it). What I'm trying to do here is create a tiny executable that will simply act as a passthrough to an MVS system to which the user only has text mode access (CLI) so they don't have to delve into DOS. This class will check the information the user entered against the requirements and concatenate the passwords as required for changing. Is this too klugy for this simple task? Am I on the right track? Are there obvious choices I should have made, but didn't? All constructive replies appreciated. //file password.h #ifndef PASSWORD_H #define PASSWORD_H class Password // class name Password { public: int ChangePassword (char *, int) ; // declare change function char *ReturnPassword() const { return Password ; } // return password to caller char *RACFPassword() ; // racf concatenator int SetPassword(char *) ; // set Password data member Password() ; // default constructor ~Password() ; // default destructor private: int Validate(char *) ; // validator for passwords char *Password, *Password1, *Password2, *Password3, *Newp ; // data members }; #endif //file password.cpp #include "password.h" Password::Password() // default constructor { Password = new char[9] ; // allocate data members Password1 = new char[9] ; Password2 = new char[9] ; Password3 = new char[9] ; Newp = new char[50] ; } Password::~Password() // default destructor { delete [] Password ; // delete data members delete [] Password1 ; delete [] Password2 ; delete [] Password3 ; delete [] Newp ; } int Password::SetPassword(char *pass) // Set Password member for sending { // to a server as text if(!Validate(pass)) // call password validator { strcpy(Password,pass) ; // copy to Password member if valid return 0 ; } // return zero if successful else return -1 ; // return -1 if not valid } int Password::Validate(char *pass) // validator { if(strlen(pass) >= 5 && strlen(pass) <= 8 ) // check for correct length if( isalpha(pass[0] )) // check if first char is alpha { return 0 ; } // return zero if passed else return(-1) ; // return -1 if failed } int Password::ChangePassword(char *pass, int num) // set data members { // for password change if(num==1) // perform in 1 case { if(!Validate(pass)) // call validator { strcpy(Password1,pass) ; // copy if valid return 0 ; } } // return zero else if(num==2) // perform in 2 case { if(!Validate(pass)) // call validator { strcpy(Password2,pass) ; // copy if valid return 0 ; } } // return zero else if(num==3) // perform in 3 case { if(!Validate(pass)) // password validator { strcpy(Password3,pass) ; // copy if valid return 0 ;} } // return zero else return -1 ; // return -1 if any invalid or incorrect } // num entered char *Password::RACFPassword() // password concatenator for RACF { // password changing in text mode strcpy(Newp,Password1) ; // copy first password to Newp strcat(Newp,"/") ; // append a virgule to end strcat(Newp,Password2) ; // append second password to Newp strcat(Newp,"/") ; // append a virgule to end strcat(Newp,Password3) ; // append third password Newp return Newp ; // return Newp to caller } .