In: Computer Science
Using C++
Create the UML, the header, the cpp, and the test file for an ArtWork class.
The features of an ArtWork are:
Artist name (e.g. Vincent vanGogh or Stan Getz)
Medium (e.g. oil painting or music composition)
Name of piece (e.g. Starry Night or Late night blues)
Year (e.g. 1837 or 1958)
UML
ArtWork.h
#ifndef ARTWORK_H
#define ARTWORK_H
class ArtWork
{
public:
ArtWork(char *name, char *med, char *piece, int yr); //Parameterized Constructor
//Data Members or Attributes
char *artistName;
char *medium;
char *nameOfPiece;
int year;
void showArtWork();
};
#endif // ARTWORK_H
ArtWork.cpp
#include "ArtWork.h"
#include<iostream>
using namespace std;
ArtWork::ArtWork(char *name, char *med, char *piece, int yr) //Parameterized Constructor
{
artistName=name;
medium=med;
nameOfPiece=piece;
year=yr;
}
void ArtWork::showArtWork() //Function to display all the values of data members or attributes
{
cout<<"Artist Name : "<<artistName<<endl;
cout<<"Medium : "<<medium<<endl;
cout<<"Name of Piece : "<<nameOfPiece<<endl;
cout<<"Year : "<<year<<endl;
}
Tester : main.cpp
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include "ArtWork.h"
using namespace std;
int main()
{
char name[30],med[30],piece[30];
int yr;
//Gathering required data from the User by taking input
cout<<"Enter Artist Name : ";
cin.getline(name,30);
cout<<"Enter Medium : ";
cin.getline(med,30);
cout<<"Enter Name of Piece : ";
cin.getline(piece,30);
cout<<"Enter Year : ";
cin>>yr;
ArtWork aw1(name,med,piece,yr); //Declaring object using Parameterized Constructor
cout<<"\nShowing Art Work : \n";
aw1.showArtWork();
return 0;
}
OUTPUT