+ 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
7 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
0
South Delhi, an enclave of affluence and sophistication, stands as the epitome of luxury living in the capital. The term "luxury" in this context transcends mere opulence; it embodies a lifestyle defined by exclusivity, prime locations, and unparalleled amenities. This guide delves into the nuances of luxury property in South Delhi, offering a comprehensive overview for discerning buyers and investors. Key areas like Vasant Vihar, Golf Links, Jor Bagh, and Defence Colony are synonymous with prestige. Vasant Vihar, known for its sprawling bungalows and verdant surroundings, offers a serene retreat amidst the city's hustle. Golf Links, adjacent to the Delhi Golf Club, boasts some of the most coveted addresses, attracting high-profile individuals and families. Jor Bagh, with its historical significance and elegant residences, exudes timeless charm. Defence Colony, a hub of upscale boutiques and restaurants, provides a vibrant yet sophisticated lifestyle. Luxury properties in these areas encompass a range of architectural marvels, from sprawling bungalows with expansive gardens to meticulously designed penthouses offering panoramic city views. Farmhouses, often situated on the outskirts, provide a tranquil escape with ample space and privacy. These residences are characterized by features such as private pools, home theaters, state-of-the-art security systems, and bespoke interiors crafted from premium materials. The South Delhi luxury property market is dynamic, influenced by factors such as economic conditions, infrastructure developments, and evolving lifestyle preferences. Price fluctuations are common, driven by demand and supply dynamics. Understanding these trends is crucial for making informed investment decisions. The investment potential of luxury properties is substantial, with the prospect of high rental yields and significant capital appreciation. www.casaconsultancy.in/properties-1
9th Apr 2025, 7:00 AM
Casa Consultancy Services
Casa Consultancy Services - avatar