In: Computer Science
7.28 LAB: Artwork label (classes/constructors). Written in C++
Given main(), complete the Artist class (in files Artist.h and Artist.cpp) with constructors to initialize an artist's information, get member functions, and a PrintInfo() member function. The default constructor should initialize the artist's name to "None" and the years of birth and death to 0. PrintInfo() should display Artist Name, born XXXX if the year of death is -1 or Artist Name (XXXX-YYYY) otherwise.
Complete the Artwork class (in files Artwork.h and Artwork.cpp) with constructors to initialize an artwork's information, get member functions, and a PrintInfo() member function. The constructor should by default initialize the title to "None", the year created to 0. Declare a private field of type Artist in the Artwork class.
Ex. If the input is:
Pablo Picasso 1881 1973 Three Musicians 1921
the output is:
Artist: Pablo Picasso (1881-1973) Title: Three Musicians, 1921
If the input is:
Brice Marden 1938 -1 Distant Muses 2000
the output is:
Artist: Brice Marden, born 1938 Title: Distant Muses, 2000
Source Code:
Source code of Artist.h file
#include<iostream>
using namespace std;
class artist
{
public:
string name;
int yearOfBirth;
int yearOfDeath;
artist()
{
name = NULL;
yearOfBirth = 0;
yearOfDeath = 0;
}
void getData()
{
cout<<"Enter Name of Artist:";
cin>>name;
cout<<"Enter Year of Birth:";
cin>>yearOfBirth;
cout<<"Enter year of Death(-1) if not:";
cin>>yearOfDeath;
}
void printInfo()
{
if(yearOfDeath ==-1){
cout<<endl<<"Artist : "<<name<<" Born
"<<yearOfDeath;
}
else
{
cout<<endl<<"Artist : "<<name<<"
("<<yearOfBirth<<" - "<<yearOfDeath<<"
)";
}
}
};
Source Code of main.cpp File
#include<iostream>
#include "Artist.h"
using namespace std;
class Artwork
{
string title;
int yearOfTitle;
artist a;
public:
void getD()
{
a.getData();
if(a.yearOfDeath != -1)
{
cout<<"Enter Title:";
cin>>title;
cout<<"Enter year:";
cin>>yearOfTitle;
}
}
void printInfo()
{
a.printInfo();
cout<<endl<<"Title : "<<title<<" ,
"<<yearOfTitle;
}
};
int main()
{
Artwork a1;
a1.getD();
a1.printInfo();
return 0;
}
OutPut:
If you have any doubt explain in comment section
We will be there to help you.
Thankyou
Thumbs Up