Hey guys, i'm having an issue with the my class, when i go to cout in the main, all i receive is jibberish, any help
Here is my code: @ = file names
@person.h
Code:#ifndef PERSON_H #define PERSON_H #include <string> class person { private: char first[20]; char last[20]; char middle; int year; int month; int day; public: void setFname(char *); void setLname(char *); void setmiddle(char); void setBirthyear(int); void setBirthmonth(int); void setBirthday(int); const char *getFname() const; const char *getLname() const; char getmiddle() const; int getBirthyear() const; int getBirthmonth() const; int getBirthday() const; }; #endif @persontypeimpl.cpp #include "person.h" #include <iostream> #include <cstdlib> #include <string> using namespace std; void person::setFname(char *first) { if (first == NULL) { cout << " Invalid First Name"; exit(EXIT_FAILURE); } } void person::setLname(char *last) { if (last == NULL) { cout << " Invalid Last Name"; exit(EXIT_FAILURE); } } void person::setmiddle(char) { if (middle == NULL) { cout << " Invalid middle initial"; exit(EXIT_FAILURE); } } void person::setBirthyear(int y) { if (year >= 0) year = y; else { cout << " Invalid Birth Year"; exit(EXIT_FAILURE); } } void person::setBirthmonth(int m) { if (month >= 0) month = m; else { cout << " Invalid Birth month"; exit(EXIT_FAILURE); } } void person::setBirthday(int d) { if (day >= 0) day = d; else { cout << " Invalid Birth Day"; exit(EXIT_FAILURE); } } const char *person:: getFname() const { return first; } const char *person:: getLname() const { return last; } char person:: getmiddle() const { return middle; } int person:: getBirthyear() const { return year; } int person:: getBirthmonth() const { return month; } int person:: getBirthday() const { return day; } @program.cpp #include <iostream> #include "person.h" #include <string> using namespace std; int main() { person *name; name = new person; name->setFname("Shimar"); cout << name->getFname(); delete name; system("pause"); return 0; }


Reply With Quote

Bookmarks