I understand it from your point of view. I read up on classes and well didn't really get them a while ago either. In the beginning classes seemed kind of tedious and well pointless for otherwise simple things. However, after I read up more and more and started to use them more and go more and more in depth I found them very important, useful, and overall awesome.
Classes pretty much allow you to define your own specialized type/object. With that specialized object you'd have special functions for the user. With that you can make specialized objects and use them multiple times, and pretty much everywhere without having to copy paste, except for the header file of course... Not only that but like I said using them multiple times, you could have an array of your special type so for this question an array of customer_info each storing their own specialized data. There especially great for thinks such as containers or just to store large amounts of important data. Think about the vector type in the STL. It is in class, particulary a template class but no matter it is in a class. And within that class it defines many functions for your ease and use just for you. Another thing would be if you wanted to make your own superINT class which could store HUGE, beyond 64 bit numbers in one or way or another depending on how you implenented it. Or what if you wanted to make your own specialized linked list class just for your self. Not only that but classes have super cool features such as inheritance, operator overloading, virtual functions, etc. With those you can customize your class even more. Thus with classes you can have your very own special type with its very own important, versatile purpose. Whilst classes may not seem a whole lot important right here, trust me they will be in the future and they will save from which may seem like tedious things to otherwise simple and cool things.
Anyways here how you would use a class in this particular situation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
class customer_info { /* Here we define our very own special type customer_info */
private: //Contain and prevent other from accidently or purposing modifying bypassing our functions below. Usually implement variables here.
string firstname, lastname;
string phoneNumber;
string address; //Declare our member variables for our customers info
string CCard;
string expdate;
string cid;
public: //Here we will have our public interface of which the user can pick and choose from. Usually implement specialized functions.
void setfirstname(string newfirstname) { //Public function to set the first name.
firstname = newfirstname; //Initialize our member function to a new name
}
string getfirstname() { //Public function to retrieve the first name of this particular customer.
return firstname; //Return back to the user this customers name.
}
};
|
NOTE:
You are going to have to implement more functions for the rest of the variables/info so just see what and how I did it.
Also make sure to make your class object in main or whatever function it will be present in order to use it.
customer_info customer; and then use and access the functions within the class via the dot operator
customer.setfirstname("some string");
Also I assume your in a c++ class so I'm not sure if he isn't allowing you to have these member variables public. Otherwise In that case change them to public and you won't even need these functions although this is the more not really correct in a sense but definitely more proper and safe way.
Anyways good luck man and I hope you finish the rest of this program in no time!