// winter_olympics.cpp (c) Copyright Kari Laitinen // http://www.naturalprogramming.com // 1998-??-?? File created. // 2010-10-04 Last modification. #include #include "useful_constants.h" using namespace std ; class Olympics { protected: int olympic_year ; char olympic_city[ 30 ] ; char olympic_country[ 20 ] ; public: Olympics( int given_olympic_year, char given_olympic_city[], char given_olympic_country[] ) { olympic_year = given_olympic_year ; strcpy( olympic_city, given_olympic_city ) ; strcpy( olympic_country, given_olympic_country ) ; } int get_year() { return olympic_year ; } void print_olympics_data() { cout << "\n In " << olympic_year << ", Winter Olympics were held in " << olympic_city << ", " << olympic_country << ".\n" ; } } ; Olympics olympics_table[] = { Olympics( 1924, "Chamonix", "France" ), Olympics( 1928, "St. Moritz", "Switzerland" ), Olympics( 1932, "Lake Placid", "United States" ), Olympics( 1936, "Garmisch-Partenkirchen", "Germany" ), Olympics( 1948, "St. Moritz", "Switzerland" ), Olympics( 1952, "Oslo", "Norway" ), Olympics( 1956, "Cortina d'Ampezzo", "Italy" ), Olympics( 1960, "Squaw Valley", "United States" ), Olympics( 1964, "Innsbruck", "Austria" ), Olympics( 1968, "Grenoble", "France" ), Olympics( 1972, "Sapporo", "Japan" ), Olympics( 1976, "Innsbruck", "Austria" ), Olympics( 1980, "Lake Placid", "United States" ), Olympics( 1984, "Sarajevo", "Yugoslavia" ), Olympics( 1988, "Calgary", "Canada" ), Olympics( 1992, "Albertville", "France" ), Olympics( 1994, "Lillehammer", "Norway" ), Olympics( 1998, "Nagano", "Japan" ), Olympics( 2002, "Salt Lake City", "United States" ), Olympics( 2006, "Turin", "Italy" ), Olympics( 9999, "end of table", "end of table" ) } ; int main() { int given_year ; cout << "\n This program can tell you where the Winter Olympic " << "\n Games were held in a given year. Please, give a year " << "\n using four digits: " ; cin >> given_year ; int olympics_index = 0 ; int table_search_status = SEARCH_NOT_READY ; while ( table_search_status == SEARCH_NOT_READY ) { if ( olympics_table[ olympics_index ].get_year() == given_year ) { olympics_table[ olympics_index ].print_olympics_data() ; table_search_status = SEARCH_IS_READY ; } else if ( olympics_table[ olympics_index ].get_year() == 9999 ) { cout << "\n\n Sorry, no Olympic Games were held in " << given_year << ".\n" ; table_search_status = SEARCH_IS_READY ; } else { olympics_index ++ ; } } }