Class C++

Write your question here.
I have problems with setcode and getcode method. Could someone help me? This is what i have done so far.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  class Bill
{
private:
	char _code[8];//code have 7 characters.
	string _name;
	float _price;
public:
	string getName();
	float getPrice();
	
	void setName(string);
	void setPrice(float);
	
	Bill();
	~Bill();
};
string Bill::getName()
{
	return _name;
}
float Bill::getPrice()
{
	return _price;
}

void Bill::setName(string s)
{
	_name = s;
}

void Bill::setPrice(float price)
{
	_price = price;
}




Hi,

for your setcode() you may use strcpy
for getcode() you may use pointers

if you really have to use char array (and not string) using vectors would be better IMO

further reading

http://www.cplusplus.com/reference/cstring/strcpy/
http://www.cplusplus.com/doc/tutorial/pointers/
http://www.cplusplus.com/reference/vector/vector/

hope it helps

Thanks
OP: If you can use std::string for name why not for code as well? Life is much simpler that way
Topic archived. No new replies allowed.