Assume you have the following enumeration type: enum AutoType {SEDAN, COUPE, OTH
ID: 3615028 • Letter: A
Question
Assume you have the following enumeration type:enum AutoType {SEDAN, COUPE, OTHER);
Write a user defined specialization of the GetData (see exercise 6)that accommodates the AutoType type. For input, the usershould type the character s for sedan, c for coupe, and o (oranything else) otherwise.
Exercise 6 is listed below for reference... please do the quesitonabove, thank you.
Exercise 6 (for reference only)
Write a function tempate for a void function, GetData, thatreceives a string through the parameter list, uses that string toprompt the user for input, reads a value from the keyboard, andreturns that value (as a reference parameter) through the parameterlist. The data type of the input value can be any type forwhich the >> operator is defined.
Explanation / Answer
using namespacestd;
enum AutoType {SEDAN,COUPE, OTHER};
void GetData(strings,AutoType &a)
{
int i;
char ch;
cout<<s;
cin>>ch;
switch(ch)
{
case 's':
a = SEDAN;
break;
case 'c':
a = COUPE;
break;
case 'o':
a = OTHER;
break;
default:
cout<<"Invalid choice";
}
}
int main(){
AutoType a;
string s="Enter your choice s:SEDAN, c:COUPE, o:OTHER: ";
GetData(s,a);
cout<<"You choose:"<<a<<endl;
system("pause");
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.