Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the program you wrote for programming challenge 4 so it defines an enumer

ID: 3543102 • Letter: M

Question

Modify the program you wrote for programming challenge 4 so it defines an enumeratedmdata type for the months. The program should use the enumerated type to step through the elements of an array.

//Libraries

#include <iostream>

#include <string>

using namespace std;

//Structure

struct months

{

float rain;

float high;

float low;

float average;

};

enum time{ January, February, March, April, May, June, July, August, September, October, November, December};

//Main begins here

int main()

{

//Declare variables

time day;

const int month= 12;

months total[month];

float totalRain=0;

int highest = 0;

int lowest = 0;

float totalAve = 0;

string monthName[month]={"January","February","March","April","May","June","July","August",

"September","October","November","December"};

//loop to find rain and temps

for(int i=0; i<12; i++){;

cout << monthName[i]  << endl;

cout << endl;

cout << "Enter total rain for this month: ";

cin >> total[i].rain;

cout << endl;

cout << "Enter the highest temperature for this month: ";

cin >> total[i].high;

//input validation

while(total[i].high<-100||total[i].high>140)

{

cout << endl;

cout<<"Invalid entry-must be between -100 through 140 ";

cout<<"high temperature: ";

cin>>total[i].high;

cout << endl;

}

cout << endl;

cout << "Enter the lowest temperature for this month: ";

cin >> total[i].low;

//Input validation

while(total[i].low<-100||total[i].low>140)

{

cout << endl;

cout<<"Invalid entry-must be between -100 through 140 ";

cout<<"high temperature: ";

cin>>total[i].low;

cout << endl;

}

//Calulate the average temperature

cout << endl;

cout << endl;

total[i].average = (total[i].high+total[i].low)/2;

cout <<"The avearge temperature of this month is: " << total[i].average << " degrees";

cout << endl;

cout << endl;

totalRain+=total[i].rain;

totalAve +=(total[i].average)/12;

if(total[i].high>total[highest].high)

{

highest=i;

}

if(total[i].low <total[lowest].low)

{

lowest=i;}

}

  //output

cout << endl;

cout << "The total rainfall for the year was: " << totalRain <<" inches"<<endl;

cout << "The highest temperature was: "<<total[highest].high <<" degrees" << endl;

cout << "The lowest temperature was: "<< total[lowest].low<< " degrees" <<endl;

cout <<"The average temerature fot the year is: " << totalAve << " degrees" << endl;

?

system("PAUSE");

return 0;

}

?

?

Explanation / Answer

hi...........frd

      C++ includes a variety of built-in or base data types:
short, int, long, float, double, char, etc.
The values are ordered and atomic.
C++ supports several mechanisms for aggregate data types: arrays, structures, classes.
These allow complex combinations of other types as single entities.
C++ also supports other mechanisms that allow programmers to define their own
custom data types: enum types and typedefs.


Enumerated Types


An enumerated type is defined by giving a name for the type and then giving a list of labels,
which are the only values that a variable of that type is allowed to have.
Enumerated types allow the creation of specialized types that support the use of meaningful
labels within a program. They promote code readability with very little overhead in
memory or runtime cost.



enum Month    {JAN, FEB, MAR, APR, MAY, JUN,
JUL, AUG, SEP, OCT, NOV, DEC};
enum Season {WINTER, SPRING, SUMMER, FALL};
enum Hemisphere {NORTH, SOUTH, EAST, WEST};
Month Mon;
Season Period;
Hemisphere Region;
. . .
if (Mon == JAN && Region == NORTH)
Period = WINTER;



An enumerated type is allowed to have up to 256 values and a variable of an enumerated
type will occupy one byte of memory.
It is an error for the same label to be listed as a value for two different enumerated types




Designing with Enumerated Types
Enumerated types provide a mechanism for the abstraction of real world entities.
Enumerated type variables do not contain the character string of the value. The internal
representation uses integer values; it is bad practice to rely on those values.
Since the labels are logically constant values it is common to express them using all
capital letters, just as for named constants.
Enumerated type values cannot be read or (usefully) written directly.
Enumerated type variables and values can be used in relational comparisons, in
assignments and in switch statements as selectors and case labels.
Enumerated type variables can be passed as parameters and used as the return value of a
function.
Good use of enumerated data types make the program more readable by providing a way
to incorporate meaningful labels (thus easier to debug) and they help in selfdocumenting
the program.


enum ParityType {EVEN, ODD}; // file-scoped type definition
ParityType FindParity(int N);
int main() {
int k;
ParityType kParity;
cout << "Please enter an integer: "; // get an integer
cin >> k;
kParity = FindParity(k); // determine its parity
if (kParity == EVEN) // can

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote