Question: Add a constructor initializer list to the default constructor Color() to initialize name with Unavailable and intensities with a vector of size 3. Ex: If
Add a constructor initializer list to the default constructor Color() to initialize name with "Unavailable" and intensities with a vector of size 3.
Ex: If the input is bisque 255 228 196, then the output is:
Color: Unavailable, 3 intensities: 0, 0, 0 Color: bisque, 3 intensities: 255, 228, 196
#include
class Color { public: Color(); void ReadName(); void ReadIntensities(); void Print() const; private: string name; vector
Color::Color() /* Your code goes here */ { }
void Color::ReadName() { cin >> name; }
void Color::ReadIntensities() { int i; for (i = 0; i < intensities.size(); ++i) { cin >> intensities.at(i); } }
void Color::Print() const { int i; cout << "Color: " << name << ", "; if (intensities.size() == 0) { cout << "No intensities" << endl; } else { cout << intensities.size() << " intensities: "; for (i = 0; i < intensities.size() - 1; ++i) { cout << intensities.at(i) << ", "; } cout << intensities.at(intensities.size() - 1) << endl; } }
int main() { string name; Color myColor;
myColor.Print();
myColor.ReadName(); myColor.ReadIntensities(); myColor.Print(); return 0; }
c++ and please please make it correct
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
