Design a class art that contain the details of artist, country and class info contain the details of year and art-tyoe(fancy, historic or modern) . Use a function for displaying the details by reading data from class art and info. The function used for displaying is not a member of any class.
#include <iostream>
#include <string>
using namespace std;
class Art
{
private:
string artistName;
int year;
string arttype;
string country;
public:
void read(){
cout<<"Enter artist name: ";
getline(cin,artistName);
cout<<"Enter year: ";
cin>>year;
cout<<"Select art type: (1. Fancy, 2. Historic, 3. Modern): ";
int type;
cin>>type;
if(type==1){
arttype="Fancy";
}
else if(type==2){
arttype="Historic";
}else if(type==3){
arttype="Modern";
}
cin.ignore();
cout<<"Enter country: ";
getline(cin,country);
}
string getArtistName(){
return artistName;
}
int getYear(){
return year;
}
string getArttype(){
return arttype;
}
string getCountry(){
return country;
}
};
void displayArt(Art art)
{
cout << "Artist name: " << art.getArtistName() << endl;
cout << "Year: " << art.getYear() << endl;
cout << "Art-type: " << art.getArttype()<< endl;
cout << "Country: " << art.getCountry()<< endl;
}
int main() {
Art art;
art.read();
displayArt(art);
system("pause");
return 0;
}
Comments
Leave a comment