Please help with my question

Can someone please help me with the following question? I'm stuck!

Consider the following class definition.

class Flower
{
private:
string color;
double cost;

public:
Flower()
{
color = “red”;
cost = 0.0;
}
Flower(string c)
{
color = c;
cost = 0.0;
}

void setColor(string c)
{
color = c;
}
void setCost(int amount)
{
cost = amount;
}
}

Which of the following is/are true?

(i) The attribute cost can be set to a new value, by a user
of this class
(ii) You can write cout<<”The flower is: “ << Flower.setColor();
(iii) A default constructor is provided.


i.
ii
Only i and iii
None are true
All are true
Last edited on
closed account (o3hC5Di1)
Hi there,

I'll rephrase the questions for you:

(i) Does the cost data member have a scope type that makes it directly accessible from outside the class? Look at what scope-keyword is used for that data member and you have your answer.

(ii) Again, this boils down to the matter of scope - is this member function accessible from outside the class, a look at the scope keyword under which this function is defined should give you the answer.

(iii) Default constructors are constructors which take no arguments. Is that provided in the listing?

Hope that helps.

All the best,
NwN
NwN, surely ii) is not about scope but about the function itself? The function is void and so does not return anything that can be outputted.
Topic archived. No new replies allowed.