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

I need help with this program, could you please help? You are taking a geology c

ID: 3763969 • Letter: I

Question

I need help with this program, could you please help?

You are taking a geology class, and the professor wants you to write a C++ program to help students learn the periods of geological time. The program should let the user enter a range of prehistoric dates (in millions of years), and then output the periods that are included in that range. Each time this output is done, the user is asked if they want to continue. The goal of the exercise is for the student to try to figure out when each period began, so that they can make a chart of geolgical time.

Within the program, represent the periods with an enumeration type made up of their names. You will probably want to create a function that determines the period corresponding to a date, and another function that returns the string corresponding to each identifier in the enumeration. Then you can use a For loop to output the series of periods in the range. The periods of geological time are given here:

Period Name; Starting Date( millions of years)

Neogene; 23

Paleogene; 65

Cretaceous; 136

Jurrasic; 192

Triassic; 225

Permian; 280

Carboniferous; 345

Devonian; 395

Silurian; 435

Ordovcian; 500

Cambrian; 570

Precambrian 4500 or earlier

Use functional decompositon to solve this problem. Be sure to use good coding style and documenting comments. The prompts and error messages that are output should be clear and informative.

Explanation / Answer

#include <iostream>
#include <cctype>
#include <string>

using namespace std;

enum Periods {NEOGENE, PALEOGENE, CRETACEOUS, JURASSIC, TRIASSIC, PERMIAN, CARBONIFEROUS,
DEVONIAN, SILURIAN, ORDOVICIAN, CAMBRIAN, PRECAMBRIAN};

struct Time
{
float fstYear;
float sndYear;
};

Periods GeoTime(struct Time timeRange);
Periods GeoTimeMax(struct Time timeRange);
void Greeting();
void Output(Periods, Periods, string&);

int main()
{

string redu = "";
string output = "";
Periods era;
Periods eramax;

do
{
Time timeRange;

Greeting();
cin >> timeRange.fstYear;
cout << "Enter Ending Date: " << endl;
cin >> timeRange.sndYear;

era = GeoTime(timeRange);
eramax = GeoTimeMax(timeRange);

cout << "The geologic period of your input is ";
while (era <= eramax)
{
Output(era, eramax, output);
cout << output << " ";
era = Periods(era +1);
}
cout << endl << endl;

cout << endl << "Would you like to continue? (Y/N)." << endl;
cin >> redu;
cout << endl << endl << endl;
}
while (toupper(redu[0]) != 'N');

return 0;
}

void Greeting ()
{
cout << "**********************************" << endl;
cout << "*** Welcome to GeoEra ************" << endl;
cout << "**********************************" << endl << endl;
cout << "To get started: enter the starting date of the time period" << endl << "you would like to learn about." << endl;
cout << "Assume that all dates are set before the common era in millions of years." << endl << endl;

cout << "Enter Begining Date: " << endl;
}

Periods GeoTime(struct Time timeRange)
{
Periods era;

if (timeRange.fstYear < 65)
era = NEOGENE;
else if (timeRange.fstYear < 136)
era = PALEOGENE;
else if (timeRange.fstYear < 192)
era = CRETACEOUS;
else if (timeRange.fstYear < 225)
era = JURASSIC;
else if (timeRange.fstYear < 280)
era = TRIASSIC;
else if (timeRange.fstYear < 345)
era = PERMIAN;
else if (timeRange.fstYear < 395)
era = CARBONIFEROUS;
else if (timeRange.fstYear < 435)
era = DEVONIAN;
else if (timeRange.fstYear < 500)
era = SILURIAN;
else if (timeRange.fstYear < 570)
era = ORDOVICIAN;
else if (timeRange.fstYear < 4500)
era = CAMBRIAN;
else if (timeRange.fstYear >= 4500)
era = PRECAMBRIAN;

return era;
}

Periods GeoTimeMax(struct Time timeRange)
{
Periods eramax;

if (timeRange.sndYear <= 64)
eramax = NEOGENE;
else if (timeRange.sndYear <= 136)
eramax = PALEOGENE;
else if (timeRange.sndYear <= 192)
eramax = CRETACEOUS;
else if (timeRange.sndYear <= 225)
eramax = JURASSIC;
else if (timeRange.sndYear <= 280)
eramax = TRIASSIC;
else if (timeRange.sndYear <= 345)
eramax = PERMIAN;
else if (timeRange.sndYear <= 395)
eramax = CARBONIFEROUS;
else if (timeRange.sndYear <= 435)
eramax = DEVONIAN;
else if (timeRange.sndYear <= 500)
eramax = SILURIAN;
else if (timeRange.sndYear <= 570)
eramax = ORDOVICIAN;
else if (timeRange.sndYear <= 4500)
eramax = CAMBRIAN;
else if (timeRange.sndYear >= 4500)
eramax = PRECAMBRIAN;

return eramax;
}

void Output(Periods era, Periods eramax, string& output)
{

switch(era)
{
case PRECAMBRIAN : output = "PRECAMBRIAN";
break;
case CAMBRIAN : output = "CAMBRIAN";
break;
case ORDOVICIAN : output = "ORDOVICIAN";
break;
case SILURIAN : output = "SILURIAN";
break;
case DEVONIAN : output = "DEVONIAN";
break;
case CARBONIFEROUS : output = "CARBONIFEROUS";
break;
case PERMIAN : output = "PERMIAN";
break;
case TRIASSIC : output = "TRIASSIC";
break;
case JURASSIC : output = "JURASSIC";
break;
case CRETACEOUS : output = "CRETACEOUS";
break;
case PALEOGENE : output = "PALEOGENE";
break;
case NEOGENE : output = "NEOGENE";
break;
}
}

output

**********************************
*** Welcome to GeoEra ************
**********************************

To get started: enter the starting date of the time period
you would like to learn about.
Assume that all dates are set before the common era in millions of years.

Enter Begining Date:
Enter Ending Date:
The geologic period of your input is


Would you like to continue? (Y/N).