1 Lab Session-1 CSIT221 Fall 2002 b Refresher slides b Practice Problem b Lab Exercise (Demo Required)

Slides:



Advertisements
Similar presentations
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Advertisements

Container Classes A container class is a data type that is capable of holding a collection of items. In C++, container classes can be implemented as.
CSE 303 Lecture 16 Multi-file (larger) programs
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
1 Classes Object-oriented programming: Model the problem as a collection of objects that have certain attributes and interact with one another and/or the.
Classes and Objects Systems Programming.
Chapter 11 Separate Compilation and Namespaces Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
1 Lab Session-2 CSIT221 Spring 2003 b Intro to Object Oriented Programming b Practice Problem b Lab Exercise (Demo Required)
1 Lab Session-9 CSIT221 Fall 2002 Lab Exercise Based on operator overloading (Demo Required)
1 Lab Session-1 CSIT221 Spring 2003 b Group Programming Challenge b Individual Lab Exercise (Demo Required)
1 Lab Session-XII CSIT121 Fall 2000 b Namespaces b Will This Program Compile ? b Master of Deceit b Lab Exercise 12-A b First Taste of Classes b Lab Exercise.
Specification and Implementation Separating the specification from implementation makes it easier to modify programs. Changes in the class’s implementation.
1 Lab Session-3 CSIT221 Spring 2003 b Group Worksheet 3 Exercise (Demo Required) b No new lab demo will be assigned to allow you to focus on HW#1.
1 Lab Session-XIV CSIT121 Spring 2002 b Namespaces b First Class Travel b Lab Exercise 14 (Demo) b Lab Exercise b Practice Problem.
C++ data types. Structs vs. Classes C++ Classes.
1 Lab Session-5 CSIT221 Spring 2003 Default and Parameterized Constructors Destructors Programming Exercise for building a template based class (demo required)
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 1.
1 Lab Session-3 CSIT 121 Fall 2004 Section-3 should finish Lab-1 Exercise first Division rules Operator precedence rules Lab Exercise.
1 Lab Session-9 CSIT-121 Fall 2003 w Random Number Generation w Designing a Game.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Lab Session-11 CSIT 121 Fall 2003 Using arrays in functions Programming Exercise.
More C++ Classes Systems Programming. Systems Programming: C++ Classes 2 Systems Programming: 2 C++ Classes  Preprocessor Wrapper  Time Class Case Study.
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
CSE 250: Data Structures Week 3 January 28 – February 1, 2008.
1 Abstract Data Type (ADT) a data type whose properties (domain and operations) are specified (what) independently of any particular implementation (how)
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
Chapter 6: Functions.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved. Note: C How to Program, Chapter 22 is a copy of C++ How to Program Chapter.
1 Further C  Multiple source code file projects  Structs  The preprocessor  Pointers.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
More C++ Classes Systems Programming. C++ Classes  Preprocessor Wrapper  Time Class Case Study –Two versions (old and new)  Class Scope and Assessing.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13: Introduction to Classes.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Compilation & Linking Computer Organization I 1 November 2009 © McQuain, Feng & Ribbens The Preprocessor When a C compiler is invoked, the.
Classes Representing Non-Trivial Objects. Problem Write a program that reads a temperature (either Fahrenheit or Celsius), and displays that same temperature.
C++ Classes and Data Structures Jeffrey S. Childs
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templates.
1 Announcements Note from admins: Edit.cshrc.solaris instead of.tcshrc Note from admins: Do not use delta.ece.
CLASSES : A DEEPER LOOK Chapter 9 Part I 1. 2 OBJECTIVES In this chapter you will learn: How to use a preprocessor wrapper to prevent multiple definition.
Chapter 9 Classes: A Deeper Look, Part I Part II.
Flow of Control and Program Style n Nested if statements n C++ struct n Program Style n Lab Exercise.
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
CS Introduction to Data Structures Spring Term 2004 Franz Hiergeist.
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
1 CSE 2341 Object Oriented Programming with C++ Note Set #5.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 13: Introduction to Classes.
Programming Fundamentals1 Chapter 7 INTRODUCTION TO CLASSES.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-1 Learning Objectives  Classes  Constructors  Principles of OOP  Class type member.
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
Introduction to Classes and Objects CS-2303, C-Term C++ Program Structure Typical C++ Programs consist of:– main –A function main –One or more classes.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Object Access m1.write(44); m2.write(m2.read() +1); std::cout
Pointer to an Object Can define a pointer to an object:
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
© 2017 Pearson Education, Hoboken, NJ. All rights reserved
A First C++ Class – a Circle
Classes Object-oriented programming: Example: Bank transactions
Functions Separate Compilation
Chapter Structured Types, Data Abstraction and Classes
More about OOP and ADTs Classes
C++ Classes C++ Interlude 1.
More about OOP and ADTs Classes
C++ data types.
More C++ Classes Systems Programming.
Classes and Objects Systems Programming.
Presentation transcript:

1 Lab Session-1 CSIT221 Fall 2002 b Refresher slides b Practice Problem b Lab Exercise (Demo Required)

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

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

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

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

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

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.

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.