Lab Session-6 CSIT221 Fall 2002 - PowerPoint PPT Presentation

About This Presentation
Title:

Lab Session-6 CSIT221 Fall 2002

Description:

Get an array of integers from the system using this pointer. ... (Section 2 will use the assignment submission page located at http://www.cs. ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 9
Provided by: sunyfr
Category:
Tags: csit221 | fall | lab | session | use

less

Transcript and Presenter's Notes

Title: Lab Session-6 CSIT221 Fall 2002


1
Lab Session-6 CSIT221 Fall 2002
  • A Note About Destructors
  • Using Pointers
  • Implementing Stacks

2
Destructors
  • Destructors perform the opposite function of
    constructors
  • A destructor is a member functions of a class and
    it has the same name as the class
  • Destructor runs automatically when an object
    belonging to its class is destroyed. It ensures
    clean up operations
  • See an example source code

3
Example Class Definition
  • include ltiostreamgt
  • using namespace std
  • class menu
  • public
  • menu()
  • bool reserved()
  • void viewseats()
  • menu()
  • private
  • char bus 94

4
Example Member Functions
  • bool menureserved()
  • coutltlt"Reserving....."ltltendl
  • return true
  • void menuviewseats()
  • coutltlt"View seats....."ltltendl

5
Example Constructor and Destructor
  • menumenu()
  • coutltlt"Constructor runs now"ltltendl
  • menumenu()
  • coutltlt"Destructor runs now"ltltendl

6
Example Client Code
  • void main()
  • menu mymenu
  • if (mymenu.reserved())
  • coutltltRuns OKltltendl
  • mymenu.viewseats()

7
Lab Exercise (Demo Not Required)
  • Define a pointer variable. Get an array of
    integers from the system using this pointer.
    Initialize the array to all odd integers from 0
    to 20. Write a for loop to sum the contents of
    the array and produce the result. Delete the
    array (Use delete ptr) and print the sum.

8
Lab Exercise (Demo Due Oct 8th Sec 01 and Oct
9th Sec 02)
  • (Section 2 will use the assignment submission
    page located at http//www.cs.fredonia.edu/zubair
    i/submit_221.html to submit this lab due to the
    start of Fall Break on Oct 10th).
  • Implement a character stack of size 10 using the
    source code in chapter 4 lectures. Push the
    characters FALLltspacegtBREAKS into the stack then
    pop them out and display FALL BREAK on the
    screen. Find the problem in your program and fix
    it so that any illegal push or pop is prevented.
Write a Comment
User Comments (0)
About PowerShow.com