Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Access Specifiers - Advanced Programming - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Advanced Programming and its key important points are: Access Specifiers, Accessing Rights, Member Functions, Derived Classes, Data Members, Thumb Rule, Simple Date Class, Proper Accessing, Simple Class, Member Functions of Friends

Typology: Slides

2012/2013

Uploaded on 03/20/2013

dharmanand
dharmanand 🇮🇳

3.3

(3)

61 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Classes
Access Specifiers
Docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download Access Specifiers - Advanced Programming - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Classes

Access Specifiers

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

Accessing Rights – Example 1 (cont)

  • // date.cpp

#include “date.h”

date::date(char *ip_date){

day = 0; month = 0; year = 0;

string_date = new char [size];

strcpy(string_date, ip_date);}

date::~date() {delete[] (string_date);}

void date::print_date() {cout << "Date is: "

<< string_date << endl;}

Accessing Rights – Example 1 (cont)

  • // client.cpp

#include “date.h” main(){ date today("June 19, 1995"); // ERROR cout << "Date is: " << today.string_date << endl; today.print_date(); //CORRECT }

Accessing Rights – Example 2 ….

  • // student.cpp #include student.h /* Member functions of the “Student" class */ Student ::Student(char *studentName, char *studentId, char *studentEmail){ name = new char[size]; strcpy(name, studentName); id = new char[size]; strcpy(id, studentId); email = new char[size]; strcpy(email, studentEmail); } Student::~Student(){ delete [] name; delete [] id; delete [] email; } void Student::printData(){ cout << “Name: ” << name << endl << “ID : ” << id << endl << “Email : ” << email << endl;}

Accessing Rights – Example 2 ….

  • // client.cpp

#include “student.h”

/* “csStudent1" is an instance of “Student" */

main(){

Student csStudent1 ("Susie Creamchese“,

"screamch@iupui.edu");

csStudent1.printData();