100 likes | 202 Views
Lab Session-13 CSIT-121 Spring 2005. Struct data type Group Lab Exercise. Groups fit together in struct types. Examples of logical groups Passenger Name, Flight Number, Seat Number and Status Book Name, Author, Year published, Catalogue Number, Status Student Name, SS#, Current courses.
E N D
Lab Session-13 CSIT-121 Spring 2005 • Struct data type • Group Lab Exercise
Groups fit together in struct types • Examples of logical groups • Passenger Name, Flight Number, Seat Number and Status • Book Name, Author, Year published, Catalogue Number, Status • Student Name, SS#, Current courses
Flight group example • struct flight • { • int SNo; • char name[40]; • char aisle; • int seat; • char status; • };
Flight group example • We have defined a data type by the name flight. • We can now declare variables of this data type • Example: flight toparis; • we can use toparis in our program now
Flight group example • For Example: • toparis.seat=24; toparis.aisle=‘F’; • toparis.status=‘K’; (K means OK)
Group Lab Exercise (Demo Due 5/4) • Write a multi-file program that can simulate a digital clock with alarm and snooze operations • In the program, define a struct data type that can hold hours, minutes, seconds and a char flag for AM or PM
Demo Data • Demo Data is as follows: • Time: Hours: 11, Minutes: 59, Seconds: 0, AM/PM: ‘A’ • Alarm Time: Hours:12, Minutes: 02, Seconds: 05, AM/PM: ‘P’ • The program should display: • 11:59:00 AM • After one minute: • 12:00:00 PM • At 12:02:05, the alarm starts ringing (cout<<" \7F";) • It rings three times with one second gap between each ring. The user is asked “snooze?” enter ‘y’ or ‘n’ (use getch() to pick one char) • If entered ‘y’, alarm is silenced and the time to ring the alarm is incremented by 2 minutes. After 2 minutes, the alarm should ring again. • Throughout the time the alarm is ringing, the clock keeps running • Do your best and come up with a fully working program. Good luck!!
Help: Familiar Format • You may want to waste about one second with this idle loop. Plug it in to your program where you need the delay of one second: • for (int j=0; j<500000000; j++); • system("cls"); //to clear the screen
Help: Unfamiliar Format • Instead of : • #include <iostream> • #include <iomanip> • Using namespace std; • Use the following directives (Old C Style): • #include <stdio.h> • #include <windows.h> • #include <iomanip.h> • Then use the following line to sleep for one second: • Sleep(1000);
Help: Both Formats • You also need the following statements in the beginning to set the format of your output: • cout.setf(ios::fixed | ios::right); • cout.fill('0'); //leading zeroes displayed