Question

In: Computer Science

7.27 LAB: Artwork label (classes/constructors) Given main(), complete the Artist class (in files Artist.h and Artist.cpp)...

7.27 LAB: Artwork label (classes/constructors)

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

________________________________________

Given code:

___________________________________

Main.cpp

#include "Artist.h"
#include "Artwork.h"
#include <iostream>
#include <string>
using namespace std;

int main(int argc, const char* argv[]) {
string userTitle, userArtistName;
int yearCreated, userBirthYear, userDeathYear;

getline(cin, userArtistName);
cin >> userBirthYear;
cin.ignore();
cin >> userDeathYear;
cin.ignore();
getline(cin, userTitle);
cin >> yearCreated;
cin.ignore();

Artist userArtist = Artist(userArtistName, userBirthYear, userDeathYear);

Artwork newArtwork = Artwork(userTitle, yearCreated, userArtist);

newArtwork.PrintInfo();
}

_____________________________________________

Artist.h

#ifndef ARTISTH
#define ARTISTH

#include <string>
using namespace std;

class Artist{
public:
Artist();

Artist(string artistName, int birthYear, int deathYear);

string GetName() const;

int GetBirthYear() const;

int GetDeathYear() const;

void PrintInfo() const;

private:
// TODO: Declare private data members - artistName, birthYear, deathYear

};

#endif

___________________________________________________

Artist.cpp

#include "Artist.h"
#include <iostream>
#include <string>
using namespace std;

// TODO: Define default constructor

// TODO: Define second constructor to initialize
// private fields (artistName, birthYear, deathYear)

// TODO: Define get functions: GetName(), GetBirthYear(), GetDeathYear()

// TODO: Define PrintInfo() function
// If deathYear is entered as -1, only print birthYear

________________________________________________________________

Artwork.h

#ifndef ARTWORKH
#define ARTWORKH

#include "Artist.h"
#include <string>
using namespace std;

class Artwork{
public:
Artwork();

Artwork(string title, int yearCreated, Artist artist);

string GetTitle();

int GetYearCreated();

void PrintInfo();

private:
// TODO: Declare private data members - title, yearCreated

// TODO: Declare private data member artist of type Artist

};

#endif

________________________________________________

Artwork.cpp

#include "Artist.h"

// TODO: Define default constructor

// TODO: Define second constructor to initialize
// private fields (title, yearCreated, artist)

// TODO: Define get functions: GetTitle(), GetYearCreated()

// TODO: Define PrintInfo() function

Solutions

Expert Solution

Main.cpp

#include "Artist.h"

#include "Artwork.h"

#include <iostream>

#include <string>

using namespace std;

int main(int argc, const char* argv[]) {

string userTitle, userArtistName;

int yearCreated, userBirthYear, userDeathYear;

getline(cin, userArtistName);

cin >> userBirthYear;

cin.ignore();

cin >> userDeathYear;

cin.ignore();

getline(cin, userTitle);

cin >> yearCreated;

cin.ignore();

Artist userArtist = Artist(userArtistName, userBirthYear, userDeathYear);

Artwork newArtwork = Artwork(userTitle, yearCreated, userArtist);

newArtwork.PrintInfo();

}

Artist.h

#ifndef ARTISTH

#define ARTISTH

#include <string>

using namespace std;

class Artist{

public:

Artist();

Artist(string artistName, int birthYear, int deathYear);

string GetName() const;

int GetBirthYear() const;

int GetDeathYear() const;

void PrintInfo() const;

private:

// TODO: Declare private data members - artistName, birthYear, deathYear

string artistName;

int birthYear;

int deathYear;

};

#endif

Artist.cpp

#include "Artist.h"

#include <iostream>

#include <string>

using namespace std;

// TODO: Define default constructor

Artist::Artist()

{

artistName="None";

birthYear=0;

deathYear=0;

}

// TODO: Define second constructor to initialize

// private fields (artistName, birthYear, deathYear)

Artist::Artist(string artistName,int birthYear,int deathYear)

{

this->artistName=artistName;

this->birthYear=birthYear;

this->deathYear=deathYear;

}

// TODO: Define get functions: GetName(), GetBirthYear(), GetDeathYear()

string Artist::GetName() const

{

return this->artistName;

}

int Artist::GetBirthYear() const

{

return this->birthYear;

}

int Artist::GetDeathYear() const

{

return this->deathYear;

}

void Artist::PrintInfo() const

{

if(this->GetDeathYear()==-1)

cout<<this->GetName()<<", born "<<this->GetBirthYear()<<endl;

else

cout<<this->GetName()<<" ("<<this->GetBirthYear()<<"-"<<this->GetDeathYear()<<")"<<endl;

}

// TODO: Define PrintInfo() function

// If deathYear is entered as -1, only print birthYear

Artwork.h

#ifndef ARTWORKH

#define ARTWORKH

#include "Artist.h"

#include <string>

using namespace std;

class Artwork{

public:

Artwork();

Artwork(string title, int yearCreated, Artist artist);

string GetTitle();

int GetYearCreated();

void PrintInfo();

private:

// TODO: Declare private data members - title, yearCreated

// TODO: Declare private data member artist of type Artist

string title;

int yearCreated;

Artist artist;

};

#endif

Artwork.cpp

#include "Artwork.h"

#include "Artist.h"

#include <iostream>

using namespace std;

// TODO: Define default constructor

Artwork::Artwork()

{

this->title="None";

this->yearCreated=0;

}

Artwork::Artwork(string title,int yearCreated,Artist artist)

{

this->title=title;

this->yearCreated=yearCreated;

this->artist=artist;

}

string Artwork::GetTitle()

{

return this->title;

}

int Artwork::GetYearCreated()

{

return this->yearCreated;

}

void Artwork::PrintInfo()

{

this->artist.PrintInfo();

cout<<"Title: "<<this->GetTitle()<<", "<<this->GetYearCreated()<<endl;

}

// TODO: Define second constructor to initialize

// private fields (title, yearCreated, artist)

// TODO: Define get functions: GetTitle(), GetYearCreated()

// TODO: Define PrintInfo() function

Output


Related Solutions

7.28 LAB: Artwork label (classes/constructors). Written in C++ Given main(), complete the Artist class (in files...
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...
9.9 LAB: Artwork label (classes/constructors) Define the Artist class with a constructor to initialize an artist's...
9.9 LAB: Artwork label (classes/constructors) Define the Artist class with a constructor to initialize an artist's information and a print_info() method. The constructor should by default initialize the artist's name to "None" and the years of birth and death to 0. print_info() should display Artist Name, born XXXX if the year of death is -1 or Artist Name (XXXX-YYYY) otherwise. Define the Artwork class with a constructor to initialize an artwork's information and a print_info() method. The constructor should by...
7.26 LAB: Nutritional information (classes/constructors) Given main(), complete the FoodItem class (in files FoodItem.h and FoodItem.cpp)...
7.26 LAB: Nutritional information (classes/constructors) Given main(), complete the FoodItem class (in files FoodItem.h and FoodItem.cpp) with constructors to initialize each food item. The default constructor should initialize the name to "None" and all other fields to 0.0. The second constructor should have four parameters (food name, grams of fat, grams of carbohydrates, and grams of protein) and should assign each private field with the appropriate parameter value. Ex: If the input is: M&M's 10.0 34.0 2.0 1.0 where M&M's...
In Java Please!! 6.21 LAB: Artwork label (modules) Define the Artist class in Artist.py with a...
In Java Please!! 6.21 LAB: Artwork label (modules) Define the Artist class in Artist.py with a constructor to initialize an artist's information. The constructor should by default initialize the artist's name to "None" and the years of birth and death to 0. Define the Artwork class in Artwork.py with a constructor to initialize an artwork's information. The constructor should by default initialize the title to "None", the year created to 0, and the artist to use the Artist default constructor...
Given main(), complete the Car class (in files Car.h and Car.cpp) with member functions to set...
Given main(), complete the Car class (in files Car.h and Car.cpp) with member functions to set and get the purchase price of a car (SetPurchasePrice(), GetPurchasePrice()), and to output the car's information (PrintInfo()). Ex: If the input is: 2011 18000 2018 where 2011 is the car's model year, 18000 is the purchase price, and 2018 is the current year, the output is: Car's information: Model year: 2011 Purchase price: 18000 Current value: 5770 Note: printInfo() should use three spaces for...
7.24 LAB: Triangle area comparison (classes) Language: C++ Given class Triangle (in files Triangle.h and Triangle.cpp),...
7.24 LAB: Triangle area comparison (classes) Language: C++ Given class Triangle (in files Triangle.h and Triangle.cpp), complete main() to read and set the base and height of triangle1 and of triangle2, determine which triangle's area is larger, and output that triangle's info, making use of Triangle's relevant member functions. Ex: If the input is: 3.0 4.0 4.0 5.0 where 3.0 is triangle1's base, 4.0 is triangle1's height, 4.0 is triangle2's base, and 5.0 is triangle2's height, the output is: Triangle...
8.16 LAB: Mileage tracker for a runner Given the MileageTrackerNode class, complete main() to insert nodes...
8.16 LAB: Mileage tracker for a runner Given the MileageTrackerNode class, complete main() to insert nodes into a linked list (using the InsertAfter() function). The first user-input value is the number of nodes in the linked list. Use the PrintNodeData() function to print the entire linked list. DO NOT print the dummy head node. Ex. If the input is: 3 2.2 7/2/18 3.2 7/7/18 4.5 7/16/18 the output is: 2.2, 7/2/18 3.2, 7/7/18 4.5, 7/16/18 _____________________________ The given code that...
9.11 LAB: Winning team (classes) Complete the Team class implementation. For the class method get_win_percentage(), the...
9.11 LAB: Winning team (classes) Complete the Team class implementation. For the class method get_win_percentage(), the formula is: team_wins / (team_wins + team_losses) Note: Use floating-point division. Ex: If the input is: Ravens 13 3 where Ravens is the team's name, 13 is the number of team wins, and 3 is the number of team losses, the output is: Congratulations, Team Ravens has a winning average! If the input is Angels 80 82, the output is: Team Angels has a...
Create 2 derived classes from Clothing class: Pants class Write only necessary constructors Override the wash()...
Create 2 derived classes from Clothing class: Pants class Write only necessary constructors Override the wash() method to indicate that pants are dry clean only. Include additional method hang() Add to your driver/tester file to make and print new pants objects and test it. Shirt class Include additional property of type string called sleeves. Write necessary constructors For sleeves only allow it to be set to {"short", "long", "none"} For size, only allow {"S","M","L"} Override the wash() method to indicate...
C++ MAIN remains same Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp,...
C++ MAIN remains same Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor copy constructor destructor addSong(song tune) adds a single node to the front of the linked list no return value displayList() displays the linked list as formatted in the example below no return value overloaded assignment operator A description of all of these functions is available in the textbook's...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT