I am new to programming and have to admit that I am lost on a simple assignment that can be fixed quickly but I am stumped and over looking the problem.
Classes are definitely not my favorite, yet I know I must get use to them since they are in fact everywhere.
Here is my problem:
I have to create a Person class that includes fields for last name, first name, and zip code. Then I must include a default constructor that initializes last name, first name, and zip code to "X" if there are no arguements supplied as well as a display function. The main program has to instantiate and display two Person objects; one for default values and the other one for which you supply your own values.
I am having the problem with the char.
Here is the code:
The errors do have to do with the char and again I am completely lost. Can someone help? Please recommend something to get this thing running error free...I'm lostCode:#include<iostream.h> #include<conio.h> #include<string.h> class Person { private: char lastName[15]; char firstName[15]; char zip; public: Person(); void setValues(char lastName2[], char firstName2[], int zip2); void displayValues(); }; Person::Person() { lastName = "Jefferson"; firstName = "Thomas"; zip = "X"; }; void Person::displayValues() { cout<<"The first name is "<<firstName<<"and the last name is "<<lastName<<endl; cout<<firstName<<lastName<< " 's zip code is "<<zip<<endl; }; void Person::setValues(char lastName2[], char firstName2[], int zip2) { lastName = lastName2; firstName = firstName2; zip = zip2; }; void main() { Person adult; cout<<"Before setting values with setValues()"<<endl; adult.displayValues(); adult.setValues("Miller", "Bobby", 92807); cout<<"After setting values with setValues()"<<endl; adult.displayValues(); getch(); };![]()



LinkBack URL
About LinkBacks




