I am trying to overload enum types so that I can get input and show output using these enum types...
My program bombs out when I run it, please help.
Here is an example of what I am trying to do (a rock classification program):
#include <iostream>
#include "classify.h"
using namespace std;
enum RockKind{Igneous, Metamorphic, Sedimentary, KindError};
enum RockTexture{Coarse, Intermediate, Fine, TextureError};
enum RockName{Basalt, Dolomite, Granite, Limestone, Marble, Obsidian, Quartzite, Sandstone, Shale, Slate, NameError};
RockKind Kind(RockName Rock){
switch(Rock){
case Basalt: case Granite: case Obsidian: return Igneous;
case Marble: case Quartzite: case Slate: return Metamorphic;
case Dolomite: case Limestone: case Sandstone: case Shale: return Sedimentary;
default: std::cerr << "\n*** Invalid Rock name ***\n";
}
return KindError;
}
RockTexture Texture(RockKind Kind){
switch(Kind){
case Igneous: return Coarse;
case Metamorphic: return Intermediate;
case Sedimentary: return Fine;
default: std::cerr << "\n***No Kind found ***\n";
}
return TextureError;
}
class overload{
public:
RockName Rock; //create enum variable
friend ostream& operator<<(ostream& os, RockName& Rock); //overload ostream
friend istream& operator>>(istream& is, RockName& Rock); //overload istream
};
overload ov; //create object
istream& operator>> ( istream& is, RockName& name )
{
is >> ov.Rock;
return is;
}
ostream& operator<< ( ostream& os, RockName& name )
{
os << Kind(ov.Rock);
return os;
}
int main()
{
char Answr;
do{
cout << "Enter the name of the rock: " << endl;
cin >> ov.Rock;
cout << endl << ov.Rock
<< " is classified as a(n) " << Kind(ov.Rock)
<< " rock and \nits texture is "
<< Texture(Kind(ov.Rock)) << endl;
cout << "Enter 'c' to continue, anything else to quit: ";
cin >> Answr;
cout << endl;
}while(Answr == 'c');
return 0;
}