I need help to get this done: Write a specification file for the Period class th
ID: 3623327 • Letter: I
Question
I need help to get this done:
Write a specification file for the Period class that has a private field that is an enumeration type, representing the name of the periods. It should have functions that:
• Return the period as a string,
• Increment the period to the next most recent period (if the period is already QUATERNARY, the increment operation should do nothing);
It should have a default constructor that sets the period to PRECAMRIAN, and a constructor with parameter of the enumeration type to allow the user to create a Period object containing any period.
The table of the entire periods is listed below:
Period time Starting date(millions of years)
Quaternary 2.5
Tertiary 65
Cretaceous 136
Jurassic 192
Triassic 225
Permian 280
Carboniferous 345
Devonian 395
Silurian 435
Ordovician 500
Cambrian 570
Precambrian 4500 or earlier
Write the complete implementation file of Period class
Explanation / Answer
please rate - thanks
I don't understant the need for the starting date.
Hope this is better
#include <iostream>
using namespace std;
enum periodName
{PRECAMBRIAN,CAMBRIAN,ORDOVICIAN,SILURIAN,DEVONIAN,CARBONIFEROUS,PERMIAN,
TRIASSIC,JURASSIC,CRETACEOUS,TERTIARY,QUATERNARY};
class Period
{
periodName name;
public:
Period()
{name = PRECAMBRIAN;
}
Period(periodName n)
{name = n;
}
string getName()
{string period[]={"Precambrian","Cambrian","Ordovician","Silurian","Devonian",
"Carboniferous","Permian","Triassic","Jurassic",
"Cretaceous","Tertiary","Quaternary"};
return period[name];
}
void increment()
{
if(name!=QUATERNARY)
name=(periodName)(name + 1);
}
};
int main()
{
Period p1;
Period p2(QUATERNARY);
Period p3(JURASSIC);
cout<<"Period 1 before increment: "<<p1.getName()<<endl;
p1.increment();
cout<<"Period 1 after increment: "<<p1.getName()<<endl;
cout<<"Period 2 before increment: "<<p2.getName()<<endl;
p2.increment();
cout<<"Period 2 after increment: "<<p2.getName()<<endl;
cout<<"Period 3 before increment: "<<p3.getName()<<endl;
p3.increment();
cout<<"Period 3 after increment: "<<p3.getName()<<endl;
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.