1 / 10

Lab Session-13 CSIT-121 Spring 2005

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.

zagiri
Download Presentation

Lab Session-13 CSIT-121 Spring 2005

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab Session-13 CSIT-121 Spring 2005 • Struct data type • Group Lab Exercise

  2. 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

  3. Flight group example • struct flight • { • int SNo; • char name[40]; • char aisle; • int seat; • char status; • };

  4. 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

  5. Flight group example • For Example: • toparis.seat=24; toparis.aisle=‘F’; • toparis.status=‘K’; (K means OK)

  6. 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

  7. 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!!

  8. 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

  9. 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);

  10. 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

More Related