CPP OO{S 3-GEtters And Setters

Here 2 functions have been taken “getprice()” and setprice() so that negative values are not printed.
My question is why not create just one function for that?

hi Divyam “getprice()” and “setprice()” can be combined into one. but here the functionality of both the functions is different one is used to set the price according to the constraints we want and another is just used to display. as there maybe a case where we only want to update not display and somewhere case could be to only display the current value that’s why two different functions are made

1 Like