The given program defines a Painting class and creates an object using the constructor. Fix the code so that the constructor tak | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

The given program defines a Painting class and creates an object using the constructor. Fix the code so that the constructor tak

Prompt: The given program defines a Painting class and creates an object using the constructor. Fix the code so that the constructor takes the name as the argument and outputs it. Sample Input Ocean Sample Output Ocean My Code: #include <iostream> #include <string> using namespace std; class Painting { public: Painting() { cout << name; } void setPainting(string x) { name = x; } string getPainting(string name) { return name; } private: string name; }; int main() { string name; cin >> name; Painting painting(name); return 0; }

8th Mar 2021, 7:56 PM
Zhar
Zhar - avatar
6 Answers
+ 5
#include <iostream> #include <string> using namespace std; class Painting { public: //define the constructor Painting(string name){ cout << name; } void setPainting(string x){ name = x; } string getPainting(){ return name; } private: string name; }; int main() { string name; cin >> name; Painting painting(name); return 0; }
30th Aug 2021, 6:49 AM
Pathum Malinga
Pathum Malinga - avatar
+ 2
So, what is your problem with this simple task? Your code is almost done already, you just need to pass argument into constructor
8th Mar 2021, 9:58 PM
Michal Doruch
+ 2
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; class Painting{//base class public: string name; //constructor Painting(string name){ cout<<name<<endl; } //to access private->use setter and getter func. void setPainting(string x){ name=x; } //To access a private attribute, use public "get" and "set" methods: string getPainting(){ return name; } }; int main() { string name; cin >> name; Painting painting(name); return 0; } Good Luck
25th Jan 2022, 5:48 PM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
+ 1
// TITLE: test.cpp #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; class Painting{//base class public: string name; //constructor Painting(string name){ cout<<name<<endl; } //to access private->use setter and getter func. void setPainting(string x){ name=x; } //To access a private attribute, use public "get" and "set" methods: string getPainting(){ return name; } }; int main() { string name; cin >> name; Painting painting(name); return 0; }
3rd May 2021, 7:22 AM
Shakil
+ 1
#include <iostream> #include <string> using namespace std; class Painting { private: string name; public: Painting(string paintingName) { cout << paintingName << endl; name = paintingName; } }; int main() { string name; cin >> name; Painting painting(name); return 0; }
7th Dec 2023, 5:02 AM
pinky patel
pinky patel - avatar
0
Now you can directorate your house with beautiful wall painting. Here you get an attractive and unique design wall painting. Visit the seven colours for more information: https://thesevencolours.com/
14th Feb 2023, 5:27 PM
rajralox