programming WarmUp Exercises to 12 deal with an array repres

programming Warm-Up Exercises to 12 deal with an array representing the inventory for an art gallery. Using the same representation, write a C++ program that reads the gallery\'s inventory from a file called art. dat into the array. Then allow the user to look up the art by specifying any field in the record. As a reminder, here are the fields: Artist (string) Title string) Medium (oil, watercolor, pastel, acrylic, print, color photo, black-and-white photo) Size (struct) Height (int) Width (int) Room where it is hung (main, green, blue, north, south, entry, balcony) Price (float) The user should be able to specify a field, and a value for that field, and the program then returns all artworks that match those criteria. For example, the user may specify Artist and Smithely, and the program will output all of the information concerning every work in the gallery by that artist.

Solution

Here is the code for you:

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
//Artist (string) Title string) Medium (oil, watercolor, pastel, acrylic, print, color photo, black-and-white photo)
//Size (struct) Height (int) Width (int) Room where it is hung (main, green, blue, north, south, entry, balcony) Price (float)
typedef struct Size
{
int Height;
int Width;
}Size;
typedef struct Art
{
string Artist;
string Title;
string Medium;
Size size;
string RoomColor;
float Price;
}Art;
void printArtDetail(Art artGallery[], int pos)
{
cout<<\"Artist: \"<<artGallery[pos].Artist<<endl;
cout<<\"Title: \"<<artGallery[pos].Title<<endl;
cout<<\"Medium: \"<<artGallery[pos].Medium<<endl;
cout<<\"Size: \"<<artGallery[pos].size.Height<<\" x \"<<artGallery[pos].size.Width<<endl;
cout<<\"Room Color: \"<<artGallery[pos].RoomColor<<endl;
cout<<\"Price: \"<<fixed<<setprecision(2)<<artGallery[pos].Price<<endl<<endl;
}
int main()
{
//Reads the gallery\'s inventory from a file called art. dat into the array.
ifstream fin;
fin.open(\"art.dat\");
Art artGallery[100];
string artistName, title, medium, color;
float price;
int searchCriteria;
int count = 0;
while(!fin.eof())
{
fin>>artGallery[count].Artist;
fin>>artGallery[count].Title;
fin>>artGallery[count].Medium;
fin>>artGallery[count].size.Height;
fin>>artGallery[count].size.Width;
fin>>artGallery[count].RoomColor;
fin>>artGallery[count].Price;
count++;
}
while(true)
{
cout<<\"Search Criteria:\"<<endl;
cout<<\"1. Artist.\"<<endl;
cout<<\"2. Title.\"<<endl;
cout<<\"3. Medium.\"<<endl;
cout<<\"4. RoomColor.\"<<endl;
cout<<\"5. Price.\"<<endl;
cout<<\"Enter your search criteria (0 to exit.): \";
cin>>searchCriteria;
switch(searchCriteria)
{
case 0:   return 0;
case 1:   cout<<\"Enter the artist name: \";
           cin>>artistName;
           for(int i = 0; i < count; i++)
           if(artGallery[i].Artist == artistName)
              printArtDetail(artGallery, i);
           break;   
case 2:   cout<<\"Enter the title: \";
           cin>>title;
           for(int i = 0; i < count; i++)
           if(artGallery[i].Title == title)
              printArtDetail(artGallery, i);
           break;   
case 3:   cout<<\"Enter the medium of art: \";
           cin>>medium;
           for(int i = 0; i < count; i++)
           if(artGallery[i].Medium == medium)
              printArtDetail(artGallery, i);
           break;   
case 4:   cout<<\"Enter the room color: \";
           cin>>color;
           for(int i = 0; i < count; i++)
           if(artGallery[i].RoomColor == color)
              printArtDetail(artGallery, i);
           break;   
case 5:   cout<<\"Enter the price: \";
           cin>>price;
           for(int i = 0; i < count; i++)
           if(artGallery[i].Price == price)
              printArtDetail(artGallery, i);
           break;   
default: cout<<\"Invalid Search Criteria.\"<<endl;
}
}
}

If you need any refinements, just get back to me.

programming Warm-Up Exercises to 12 deal with an array representing the inventory for an art gallery. Using the same representation, write a C++ program that re
programming Warm-Up Exercises to 12 deal with an array representing the inventory for an art gallery. Using the same representation, write a C++ program that re

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site