Classes Access Specifiers - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Classes Access Specifiers

Description:

date(char *ip_date); //Constructor ~date(); //Destructor. void print_date(); //Member ... email = new char[size]; strcpy(email, studentEmail); Student::~Student ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 10
Provided by: wallyC
Category:

less

Transcript and Presenter's Notes

Title: Classes Access Specifiers


1
Classes Access Specifiers
Department of Computer and Information
Science,School of Science, IUPUI
CSCI 240
Dale Roberts, Lecturer Computer Science,
IUPUI E-mail droberts_at_cs.iupui.edu
2
Accessing Rights
  • Private Member Functions of the Class and its
    Friends
  • Protected Member Functions and Derived Classes
  • Public Entire World
  • Thumb Rule -- Data Members are Private and Member
    Functions are Public

3
Accessing Rights Example 1
  • // date.h/ A Simple Date Class With a Proper
    Accessing / define size 50 class date
    private int day, month, year char
    string_date public date(char ip_date)
    //Constructor date() //Destructor void
    print_date() //Member Function

4
Accessing Rights Example 1 (cont)
  • // date.cppinclude date.hdatedate(char
    ip_date) day 0 month 0 year 0
    string_date new char size
    strcpy(string_date, ip_date) datedate()
    delete (string_date) void
    dateprint_date() cout ltlt "Date is " ltlt
    string_date ltlt endl

5
Accessing Rights Example 1 (cont)
  • // client.cppinclude date.hmain() date
    today("June 19, 1995") // ERROR cout ltlt
    "Date is " ltlt today.string_date ltlt endl
    today.print_date() //CORRECT

6
Accessing Rights - Example 2
  • // student.h/ A Simple Class to Represent a
    Student /define size 50class Student 
    private char name char id char email 
    public Student(char , char , char
    ) Student() void printData()

7
Accessing Rights Example 2 .
  • // student.cppinclude student.h/ Member
    functions of the Student" class /Student
    Student(char studentName, char studentId,
    char studentEmail) name new charsize
       strcpy(name, studentName) id new
    charsize    strcpy(id, studentId) email
    new charsize    strcpy(email,
    studentEmail)StudentStudent() delete
    name delete id delete
    emailvoid StudentprintData() cout ltlt
    Name ltlt name ltlt endl ltlt ID ltlt id
    ltlt endl ltlt Email ltlt email ltlt endl

8
Accessing Rights Example 2 .
  • // client.cppinclude student.h/
    csStudent1" is an instance of Student"
    /main()    Student csStudent1 ("Susie
    Creamchese, "123456789,
    "screamch_at_iupui.edu") csStudent1.printData()

9
Acknowledgements
  • These slides were originally prepared by Rajeev
    Raje, modified by Dale Roberts.
Write a Comment
User Comments (0)
About PowerShow.com