Create a Painting class that holds the painting title, artist name, and value. All Paintings are valued at $400 unless they are FamousPaintings. Include a display function that displays all fields. The FamousPainting subclass overrides the Painting value and sets each Painting’s value to $25,000.

Respuesta :

Answer:

#include<iostream>

#include<string>

#define N 10

#define M 4

using namespace std;

class Painting

{

protected:

string title;

string author;

int value;

public:

Painting(string Title="", stringAuthor="",int Value=400) {title=Title;author=Author;value=Value;}

void setTitle(string newTitle){title=newTitle;}

void setAuthor(string newAuthor){author=newAuthor;}

void display() {cout<<"Title:"<<title<<endl; cout<<"Author:

"<<author<<endl<<"Value:

"<<value<<endl;}

};

class FamousPainting:public Painting

{

public:

FamousPainting(string Title, stringAuthor, int Value=25000): Painting(Title,Author,Value){}

};

int main()

{

Painting *paintings=new Painting[N];

stringfamous[M]={"Degas","Monet",

"Picasso","Rembrandt"};

string title, author;

int i,k,j;

for(i=0;i<N;i++)

{

cout<<"Input title: ";

getline (cin, title);

cout<<"Input author: ";

getline (cin, author);

k=-1;

for(j=0;j<M;j++)

if(famous[j]==author)

{

k=j;

break;

}

if(k>=0)

paintings[i]=FamousPainting(title,author);

else

paintings[i]=Painting(title,author);

}

for(i=0;i<N;i++)

{

cout<<"Painting#"<<i<<":"<<endl;

paintings[i].display();

}

return 0;

}

Explanation: