lab_mid_02_solution

# lab_mid_02_solution - SECTION 2 ANSWER KEY CSci 1113 Spring...

This preview shows pages 1–3. Sign up to view the full content.

1 ***** SECTION 2 ANSWER KEY ***** CSci 1113 Spring 2009 Lab Midterm – 90 Minutes Section 2: Monday 1:25-5:25 A. (30 points) Time Zone Program [email protected] (~/spr09/lab_mid) % cat zone.cpp #include<iostream> using namespace std; int time_zone(int hours, char zone); int main() { int hour, minutes, new_hour; char zone, again; do { cout << "Enter Central hours and minutes: "; cin >> hour >> minutes; cout << "Enter the desired time zone (E, M, P): "; cin >> zone; new_hour = time_zone(hour, zone); cout << zone << " time is " << new_hour << ":" << minutes << endl; // repeat cout << "Another calculation? Y or N: "; cin >> again; } while(again=='Y'); return 0; } int time_zone(int hour, char Z) { int hour2; switch (Z)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 { case 'E': hour2 = hour + 1; break; case 'M': hour2 = hour - 1; break; case 'P': hour2 = hour-2; break; } if(hour2 >= 24) hour2 = hour2-24; else if(hour2 < 0) hour2 = hour2 +24; return hour2; } [email protected] (~/spr09/lab_mid) % g++ zone.cpp [email protected] (~/spr09/lab_mid) % a.out Enter Central hours and minutes: 7 30 Enter the desired time zone (E, M, P): M M time is 6:30 Another calculation? Y or N: Y Enter Central hours and minutes: 23 45 Enter the desired time zone (E, M, P): E
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

### Page1 / 6

lab_mid_02_solution - SECTION 2 ANSWER KEY CSci 1113 Spring...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online