1. Write C++ statements that do the following: a. Define an enum type, courseTyp
ID: 3841546 • Letter: 1
Question
1. Write C++ statements that do the following:
a. Define an enum type, courseType, with the values ALGEBRA,
BEGINNING_SPANISH, ASTRONOMY, GENERAL_CHEMISTRY, PHYSICS,
and LOGIC.
b. Declare a variable newClass of the type courseType.
c. Assign ASTRONOMY to the variable newClass.
d. Advance newClass to the next value in the list.
e. Output the value of the variable newClass.
f. Input value in the variable newClass.
2. Suppose that the enum courseType is as defined in the previous problem. Write a C++
function that can be used to input a value in a variable of type courseType
.
Explanation / Answer
Here is the solution as per the given criteria, please go through it throughly:-
Part A:-
// Declare a new enumeration named CourseType
enum CourseType
{
// Here are the enumerators
// These define all the possible values this type can hold
// Each enumerator is separated by a comma, not a semicolon
CourseType_Algebra, // assigned 0
CourseType_BegginningSpanish, // assigned 1
CourseType_Astronomy, // assigned 2
CourseType_GeneralChemistry, // assigned 3
CourseType_Physics, // assigned 4
CourseType_Logic // assigned 5
// see note about trailing comma on the last enumerator below
}; // however the enum itself must end with a semicolon
==============================================================
Part B:-
// declaring variables:
int newClass;
==============================================================
Part C-
// Define a newClass variables of enumerated type CourseType
CourseType newClass = CourseType_Astronomy;
==============================================================
Part D:-
Increase the value of the variable so that it is equal to the next class (unless you set special variable values for each enum, then you should be able to get the result you want by adding +1 to the variable)
==============================================================
Part E:-
std::cout << newClass;
//The cout statement above prints the value newClass variable i.e, assigned 2
==============================================================
Part F:-
std::cin >> inputnewClass;
//The cin statement above input the value in newClass variable
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.