+ 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; }
6 ответов
+ 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;
}
+ 2
So, what is your problem with this simple task? Your code is almost done already, you just need to pass argument into constructor
+ 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
+ 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;
}
+ 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;
}
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/