Any assistance that can be provided on writing this program would be great. Than
ID: 650051 • Letter: A
Question
Any assistance that can be provided on writing this program would be great. Thank you.
You are taking a geology class, and the professor wants you to write a 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 names of all the periods that overlap that range.
Each time the output is done the user is asked if they want to continue to enter another range. The goal of this exercise is for the student to try to figure out when each period began, so that he or she can make a chart of geological time.
You should create a function that given a starting and ending time in millions of years will print a list of all periods that overlap that range. Be carefull with your logic in this exercise. If the user inputs 200 and 65 the program the program should output: Triassic, Jurassic, Cretaceous, Paleogene. It includes Triassic because this period was from 225 to 192 million years ago and the range 200 to 65 overlaps part of that. It includes Jurassic and Cretaceous because both fall completely within the 200-65 range. It includes Paleogene because the end of the 200-65 range does reach the beginning of that time. You must also pay attention to the special cases of a number being less than 23 (start of Neogene) and greater than 4500 (also Precambrian).
The periods of geological time are given as:
Use functional decomposition to solve this problem. Be sure to use good coding style and documentation. The prompts and error messages that are output to the user should be clear and informative.
Explanation / Answer
#include <iostream>
using namespace std;
bool coincides(int l,int r,int x,int y)
{
if(r<=x && l>=y)
return true;
else
return false;
}
void printCoincidingPeriods(int l ,int r)
{
int dates[12]={23,65,136,192,225,280,345,395,435,500,570,4500};
string eras[12]={"Neogene","Paleogene","Cretaceous","Jurassic","Triassic","Permian","Carboniferous","Devonian","Silurian","Ordovician","Cambrian","Precambrian"};
cout<<"The considing periods are : ";
if(r<23)
{
cout<<eras[0]<<", ";
}
for(int i=1;i<12;i++)
{
if(coincides(l,r,dates[i],dates[i-1]))
cout<<eras[i]<<", ";
}
if(r>4500)
cout<<eras[11]<<", ";
cout<<endl;
}
int main()
{
int choice=1;
while(choice=1)
{
cout<<"Enter a range of prehistoric date. Format Eg, 200 65 ";
cout<<"Enter the range in the this ";
int l,r;
cin>>l>>r;
printCoincidingPeriods(l,r);
cout<<"Do you want to to continue to enter another range? Enter y for Yes and n for No ";
char ch;
cin>>ch;
if(ch=='n')
choice=0;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.