Answer to Question #50462 in C++ for zexy2521

Question #50462
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. Write a main()function that declares an array of 10
Painting objects. Prompt the user to enter the title and artist for each of the 10 Paintings.
Consider the Painting to be a FamousPainting if the artist is one of the following: Degas,
Monet, Picasso, or Rembrandt. Display the 10 Paintings. Save the file as Paintings.cpp.
1
Expert's answer
2015-01-21T02:54:05-0500

#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;
}


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
APPROVED BY CLIENTS