Creating class with default constructor + constructor with parameter

I need to create a class (named: Lamp) with a default constructor, a constructor with parameters for each data member, and the following public data members:
"style, which is a string (initialize to "Plain")
color, which is a character (initialize to 'N').
wattage, which is a floating point value (initialize to 0).
bulbs, which is an integer value (initialize to 1)."
My second constructor also need to take all data member variables as input in the order they are specified above.

this is my code, it builds but the auto grader says it's not right

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  class Lamp
{
public:
    string style;
    char color;
    float wattage;
    int bulbs;
 
public:
    Lamp() : style("Plain"), color('N'), wattage(0), bulbs(1)
    {

    }
 
};


any ideas people?
closed account (E0p9LyTq)
Your assignment requirement mention TWO constructors.

The default constructor is fine, where/what is the parameterized constructor?
So do I just put this in the public method?

1
2
3
4
5
6
7
        Lamp(string s, char c, float w, int b)
        {
            style = s;
            color = c;
            wattage = w;
            bulbs = b;
        }
Last edited on
closed account (E0p9LyTq)
Unless you don't want to be able to use/call the parameterized constructor it should be declared as public.
Got it right! Thank you so much!!!
closed account (E0p9LyTq)
You could rewrite your parameterized constructor to be similar to your default constructor:

1
2
3
   Lamp(string s, char c, float w, int b) :
      style(s), color(c), wattage(w), bulbs(b)
   {}
Topic archived. No new replies allowed.