change value in class using set?

HELLO!
Please, could someone help me how to change price of book in that program using method set2?
Many thanks if it is possible

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
40
41
  #include<iostream>
using namespace std;
 
 
class product {
 
public:
int ID;
string name;
double price;
void set(int, string, double);
int getID(){return ID;};
string get_name(){return name;};
double get_price(){return price;}
 
};
 
void product::set (int a, string b, double c) {
ID = a;
name = b;
price=c;
}
 
 
int main(){
 
product toy;
product book;
product dress;
 
toy.set (1, "Toy", 11.22);
book.set (2, "Book", 22.33);
dress.set (3, "Dress", 33.44);
 
cout<<toy.ID<<endl<<toy.name<<endl<<toy.price<<endl<<endl<<book.ID<<endl<<book.name<<endl<<book.price<<endl<<endl<<dress.ID<<endl<<dress.name<<endl<<dress.price<<endl;
cout<<endl;
cout<<toy.getID()<<" "<<book.getID()<<" "<<dress.getID()<<endl;
cout<<toy.get_name()<<" "<<book.get_name()<<" "<<dress.get_name()<<endl;
cout<<toy.get_price()<<" "<<book.get_price()<<" "<<dress.get_price()<<endl;
return 0;
 
Not exactly sure what you mean, it looks like you're already doing that?
Hello!
I have set price of the toy to 11.22 andnow I woull like to change it to 11.11.


Is there a way to do it using method set2?

Many thanks!
Topic archived. No new replies allowed.