How to WRITE
A class Person in C++ with attributes name, date of birth and residence address. Data type for name and address should be char*
How to WRITE
A class Person in C++ with attributes name, date of birth and residence address. Data type for name and address should be char*
Start by making a class, then name that class Person. Add member variables for name, date of birth and address with appropriate types.
I would suggest using string instead of char*, since the C++ string class is easier to use and safer than C style strings that are stored with char *'s, especially in classes. If your "boss" requires char*, then that "boss" isn't teaching you very well, but at least you know what the types are supposed to be so you have one step accomplished.
There are tons of examples of classes, just do some searching, or look in your C++ book or tutorial.
Code:class Person { public: Person(); char name(); double DOB(); char Address(); void Properties(); }; #endif
OK, but this class needs data members (a private section with them). What you have are member functions.
Also, do you really think a single char would be enough for storing the name and address and that a double would be a suitable data-type for date of birth?
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
That's a good start. Do you know what the #endif is for? It's part of a header include guard. If that code is in a header, you are missing the rest. If it is not, then remove the #endif part.
Your class has a constructor and four other functions. It does not have any member variables. You should probably change those four functions to variables.
Your name and address use type char, but char holds only a single character. I'd strongly advise switching to std::string (and #include <string>) but if you are required to use char* then don't forget the *, or make them character arrays with a max size. If you aren't familiar with character arrays, time for another trip to the book/tutorial/search engine.
Also note that #endif is not part of the class, but is a pre-processor directive (it matches a #ifdef or similar somewhere above).
Sorry ... Agreed...
1) I will remove endif .or beter, may be add a header :-)
2) How to change function to variables ?
3) char name(); to std::string name(); with a header as #include <string>
3) is good, but it's still a function.
Do you know the difference between a function declaration and a variable declaration?
function declaration and a variable declaration : No I guess
You should REALLY go look at the tutorials provided on this very site. It will walk you through the basics if you are up to a little reading and A LOT of practice.