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.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...
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...
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files....
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files. Use include guard in class header files to avoid multiple inclusion of a header. Tasks: In our lecture, we wrote a program that defines and implements a class Rectangle. The source code can be found on Blackboard > Course Content > Classes and Objects > Demo Program 2: class Rectangle in three files. In this lab, we will use class inheritance to write a...
How to combine these 2 main functions of c++ files in 1 main class? //SinglyLinkedList int...
How to combine these 2 main functions of c++ files in 1 main class? //SinglyLinkedList int main() { SinglyLinkedList<std::string> list; list.Add("Hello"); list.Print(); list.Add("Hi"); list.Print(); list.InsertAt("Bye",1); list.Print(); list.Add("Akash"); list.Print(); if(list.isEmpty()){ cout<<"List is Empty "<<endl; } else{ cout<<"List is not empty"<<endl; } cout<<"Size = "<<list.Size()<<endl; cout<<"Element at position 1 is "<<list.get(1)<<endl; if(list.Contains("X")){ cout<<"List contains X"<<endl; } else{ cout<<"List does not contain X"<<endl; } cout<<"Position of the word Akash is "<<list.IndexOf("Akash")<<endl; cout<<"Last Position of the word Akash is "<<list.LastOf("Akash")<<endl; list.RemoveElement("Akash"); cout<<"After removing Akash...
9.7 LAB: Inserting an integer in descending order (doubly-linked list) Given main() and an IntNode class,...
9.7 LAB: Inserting an integer in descending order (doubly-linked list) Given main() and an IntNode class, complete the IntList class (a linked list of IntNodes) by writing the insertInDescendingOrder() method to insert new IntNodes into the IntList in descending order. Ex. If the input is: 3 4 2 5 1 6 7 9 8 -1 the output is: 9 8 7 6 5 4 3 2 1 Sortedlist.java import java.util.Scanner; public class SortedList { public static void main (String[] args)...
10.5 LAB: Air-traffic control (queue using a linked list) Given a partial main() and PlaneQueue class,...
10.5 LAB: Air-traffic control (queue using a linked list) Given a partial main() and PlaneQueue class, write the push() and pop() methods for PlaneQueue. Then complete the main() to read in whether flights are arriving or have landed at an airport. An "arriving" flight is pushed onto the queue. A "landed" flight is popped from the front of the queue. Output the queue after each plane is pushed or popped. Entering -1 exits the program. Ex: If the input is:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT