Answer to Question #315224 in C++ for Mominul

Question #315224

#include <iostream> using namespace std; #include <string>



class cat



string color="White": string action="sitting"



Your Code Here



int main()



cat cl;



cat c2("Black"):



cat c3("Brown", "jumping");



cat c4("Red", "purring");



cl.print_cat():



c2.print_cat();



c3.print_cat():



c4.print_cat():



cl.change_color("Blue"); c3.change_color("Purple");



cl.print cat();



c3.print_cat():



return 0:



Complete the cat class so the main function above produces the following output:



White cat is sitting



Black cat is sitting Brown cat is jumping



Red cat is purring



Blue cat is sitting Purple cat is jumping

1
Expert's answer
2022-03-22T10:16:35-0400
#include <iostream> 
#include <string>
using namespace std; 

class cat {
public:
    cat(string color="White", string action="sitting")
        : color(color), action(action) {}
    void print_cat() {
        cout << color << " cat is " << action << endl;
    }
    void change_color(string new_color) {
        color = new_color;
    }

private:
    string color;
    string action;    
};


int main()
{
    cat c1;
    cat c2("Black");
    cat c3("Brown", "jumping");
    cat c4("Red", "purring");

    c1.print_cat();
    c2.print_cat();
    c3.print_cat();
    c4.print_cat();

    c1.change_color("Blue"); 
    c3.change_color("Purple");

    c1.print_cat();
    c3.print_cat();

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog