Like Tree2Likes
  • 2 Post By jimblumberg

Homework: Program to work out geological ages

This is a discussion on Homework: Program to work out geological ages within the C++ Programming forums, part of the General Programming Boards category; Write a program to help students learn the periods of geologic time. The program should let the user enter a ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    1

    Homework: Program to work out geological ages

    Write a program to help students learn the periods of geologic 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 he or she wants to continue. The goal of the exercise is for the student to try to figure out when each period began, so that he or she can make a chart of geologic 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 geologic time are given here:

    Period Name Starting Date (millions of years)
    Neogene 23
    Paleogene 65
    Cretaceous 136
    Jurassic 192
    Triassic 225
    Permian 280
    Carboniferous 345
    Devonian 395
    Silurian 435
    Ordovician 500
    Cambrian 570
    Precambrian 4500 or earlier

    Use functional decomposition 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.
    Code:
    #include <iostream>
    
    #include <string>
    
    using namespace std;
    
    void printResults(int);
    
    void getRange();
    
    enum Periods {NEOGENE, PALEOGENE, CRETACEOUS, JURASSIC, TRIASSIC, PERMIAN, CARBONIFEROUS,
    
    DEVONIAN, SILURIAN, ORDOVICIAN, CAMBRIAN, PRECAMBRIAN};
    
    int main() 
    
    {
    
    bool goAgain = true;
    
    Periods finRange;
    
    int range[2];
    
    while(goAgain) {
    
    range = getRange();
    
    printResults(range);
    
    goAgain = askAgain();
    
    }
    
    system ("pause");
    
    return 0;
    
    }
    
    void printResults(int finRange);
    
    {
    
    cout << "The geologic period of your input is " << finRange << ".";
    
    return getRange;
    
    }
    
    void getRange()
    
    {
    
    int range > x.Hm << "Please enter the year (in BC) to see the time period." << endl;
    
    cin << range;
    
    if (range >= '23' && range <= '64')
    
    finRange = Neogene;
    
    else if (range >= '65' && range <= '135')
    
    finRange = Paleogene;
    
    else if (range >= '136' && range <= '191')
    
    finRange = Cretaceous;
    
    else if (range >= '192' && range <= '224'
    
    finRange = Jurassic;
    
    else if (range >= '225' && range <= '279')
    
    finRange = Triassic;
    
    else if (range >= '280' && range <= '344')
    
    finRange = Permian;
    
    else if (range >= '345' && range <= '394')
    
    finRange = Carboniferous;
    
    else if (range >= '395' && range <= '434')
    
    finRange = Devonian;
    
    else if (range >= '435' && range <= '499')
    
    finRange = Silurian;
    
    else if (range >= '500' && range <= '569')
    
    finRange = Ordovician;
    
    else if (range >= '570' && range <= '4499')
    
    finRange = Cambrian;
    
    else if (range >= '4500')
    
    finRange = Precambrian;
    
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,701
    And your question/problem is?

    Be sure to use good coding style and documenting comments.
    You may want to start with finding an indentation style and using it.

    Jim
    stahta01 and Salem like this.

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,217
    Write a program to help students learn the periods of geologic time.
    Nah; I don't want to, but you probably should.

    Be sure to use good coding style and documenting comments.
    That's good advice; you should get right on that.

    The prompts and error messages that are output should be clear and informative.
    Wow. You know, that's probably true; it would have been ..... helpful to include those.

    Soma

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,217

    [Completely Unrelated]

    You know, I always find myself wondering why people throw spaghetti at a wall to see if it will stick.

    Soma

  5. #5
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    452
    Quote Originally Posted by phantomotap View Post
    You know, I always find myself wondering why people throw spaghetti at a wall to see if it will stick.

    Soma
    worship the flying spaghetti monster
    Last edited by nimitzhunter; 04-25-2011 at 06:21 PM.
    "All that we see or seem
    Is but a dream within a dream." - Poe

  6. #6
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    Code:
    if (range >= '23' && range <= '64')
    Putting the numbers in single quotes is wrong.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    2,543
    Code:
    enum Periods {NEOGENE
    Code:
    finRange = Neogene;
    C is case sensitive; the above two names are NOT the same.

    Tim S.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help with a Homework program on polynomials
    By m&m in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2010, 12:42 AM
  2. People that take AGES to reply!
    By kevinj in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 02-25-2004, 07:35 AM
  3. Help with program homework!!!
    By skitt12 in forum C++ Programming
    Replies: 4
    Last Post: 10-09-2002, 04:59 PM
  4. Ages
    By Vicious in forum A Brief History of Cprogramming.com
    Replies: 56
    Last Post: 05-19-2002, 07:56 AM
  5. Help Me For My Homework Program
    By paul16 in forum C Programming
    Replies: 8
    Last Post: 10-10-2001, 06:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21