Original Post
Ok, so I am working on this for school. I am building a model business application in the console using C++.
The application is modeled as a database/cashier program. I have a class called BookData that is supposed to hold a number of character arrays and a few other variables.
Here are my private members:
char _isbn[14];
char _title[51];
char _author[31];
char _publisher[31];
char _date[11];
int _quantity;
double _cost;
double _price;
I am supposed to have public accessor and mutator functions that 'get' and set' each private member of the class. I was surprised to learn this, but apparently you cannot return an array from a function in C++
Normally I know I would write an accessor function for the last three similar to something like this:
double BookData::getCost()
{
return _cost;
}
I am not sure how I should go about doing this for the character arrays. This is for a C++ course and I believe I am supposed to keep the c strings and not use strings from the standard libraries. I cannot remember but I think that you are supposed to use pointers to do this somehow. I tried but the syntax seems clumsy and I am getting errors. Any tips would be most appreciated.
This is supposed to work by booting up and filling a dynamically allocated array of BookData class objects from a delimited data file. I need these 'setter' / 'getter' functions for accessing and manipulating these values to add other functionality. I am going to be working on this for the rest of tonight and all tomorrow. So anyone that can give me any advice on this subject would be most helpful.
The application is modeled as a database/cashier program. I have a class called BookData that is supposed to hold a number of character arrays and a few other variables.
Here are my private members:
char _isbn[14];
char _title[51];
char _author[31];
char _publisher[31];
char _date[11];
int _quantity;
double _cost;
double _price;
I am supposed to have public accessor and mutator functions that 'get' and set' each private member of the class. I was surprised to learn this, but apparently you cannot return an array from a function in C++
Normally I know I would write an accessor function for the last three similar to something like this:
double BookData::getCost()
{
return _cost;
}
I am not sure how I should go about doing this for the character arrays. This is for a C++ course and I believe I am supposed to keep the c strings and not use strings from the standard libraries. I cannot remember but I think that you are supposed to use pointers to do this somehow. I tried but the syntax seems clumsy and I am getting errors. Any tips would be most appreciated.
This is supposed to work by booting up and filling a dynamically allocated array of BookData class objects from a delimited data file. I need these 'setter' / 'getter' functions for accessing and manipulating these values to add other functionality. I am going to be working on this for the rest of tonight and all tomorrow. So anyone that can give me any advice on this subject would be most helpful.