How to use a "SET" function

My "get" functions:

1
2
3
4
5
6
	//get functions:
	char* getAvtor(){return avtor;}
	char* getDello(){return dello;}
	int  getGod(){return god;}
	float getCena(){return cena;}
	char* getPonuduvac(){return ponuduvac;}


How to use them in this function?
How should my GET functions be declared and used?


1
2
3
4
5
6
7
8
9
	void OfferPrice(float price, char* name)
	{
		if(price>u.getPrice())
	{
		setPrice(price);
		setName( ...

		}
	}


I think you can use a C++ class, just like this:
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
class goods
{
      public:
             void nameSet(char* );
             char * Getname();
             void priceSet(double);
             double Getprice();
     private:
             double price;
             char  name[20];
};
goods::goods()
{
     price=0;
     name=NULL;
}
goods::~goods()
{}
void goods::nameSet(char *  names)
{
       strcpy(name,names);
}
char* goods::Getname()
{
       return name;
}

and some other operation...
And I'f I would like to call the functions from the main section, for

goods g;

(and I'd like to set "g.name", and after thet get(read) "g.name), how would that look?
Yes,but you should make the name be public not private,and that's not safe,
everybody could change the value of name.
everybody could change the value of name.
¿so why did you put a 'set' method then?
that's why I'm using set/get methods to do so. the thing that I don't know is how to calm the from the main function.

How should I get the name, for example of: "g.name", using the GET function?

is that g.name.getAvtor();
or ..?
Anyone please?
If your name is public defined, you can use g.name=" your name", otherwise you should get it by function Getname()
Last edited on
Topic archived. No new replies allowed.