lab_mid_02_solution

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

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

View Full Document Right Arrow Icon
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 cswanson@shemp (~/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)
Background image of page 1

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

View Full DocumentRight Arrow Icon
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; } cswanson@shemp (~/spr09/lab_mid) % g++ zone.cpp cswanson@shemp (~/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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online