Download presentation
Presentation is loading. Please wait.
2
1 Lab Session-1 CSIT221 Fall 2002 b Refresher slides b Practice Problem b Lab Exercise (Demo Required)
3
2 Pre-Processor Directives for defining classes b #ifndef TIME1_H b #define TIME1_H b Class Time { b.. b Class definition goes here b.. b }; b #endif
4
3 Building Class Definition b The class definition will consist of public and private sections. By default, everything is private. However, we should explicitly label the sections as such to avoid confusion b The function prototypes and the data items are included in the definition of a class. However, data items cannot be initialized here. Initialization takes place in a constructor
5
4 Constructor b Once the class definition is completed, Start building up the source code for all the member functions in the implementation file b The first one to be written is the constructor. The default constructor accepts no arguments and executes by default when an object of this class is declared
6
5 How Many Files? b Class definition in a header file (e.g. Time.h) b Class implementation in a C++ source code file (e.g. Time.cpp) b Class driver code in a C++ source code file (e.g. driver.cpp) b All these files are part of your project
7
6 Be Careful b Use the keyword void in the implementation file before starting to implement any void member function b If parameters are being passed to a member function, specify their data types and local names b The order of inserting files may influence the number of compiling errors
8
7 Practice Problem for Handling Classes b A TV studio hires you to write a program for generating weekly weather report. This report should contain minimum and maximum temperatures and rain/snowfall amounts recorded for one week. The program should produce a display showing temperatures during last 7 days, total rain/snowfall amounts and average maximum and minimum temperatures.
9
8 Lab Exercise: (Due Sep 3 rd Sec01 Sep 5 th Sec02) Lab Exercise: (Due Sep 3 rd Sec01 Sep 5 th Sec02) b Develop a class tictactoe to allow playing TicTacToe game. Define a 3X3 array as a private data member. Store a 1 in an appropriate square (array location) if player 1 has moved and store a 2 if player 2 moved. After each move, evaluate if the game has been won. Moves can be organized by allowing each player to be located at location [0,0] at the beginning. Players can move with typing l,r,u or d keys. If the destination or current square is busy, players must be warned about it.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.