






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to classes, a fundamental concept in object-oriented programming (oop) and c++. Learn about the structure of a class, including data members, member functions, and accessing rights. Discover how to define and use classes through examples, such as the 'date' and 'student' classes.
Typology: Slides
1 / 10
This page cannot be seen from the preview
Don't miss anything!







type
is Allocated
class Class_Name{ private: //Default and Optional data_member_specification_1; : data_member_specification_n; public: data_member_specification_n+1; : data_member_specification_n+m;
}; //Don't forget the semicolon after the closing brace.
/* A Simple Class to Represent a Date */ #define size 50 class date{ private: int day, month, year; char *string_date; public: void set_date( int ip_day,int ip_month,int ip_year); void set_string_date(char *ip_date); };
#include “date.h” /* "today" and "yesterday" are instances of "date" */ main(){ date today, yesterday; today.set_date(19, 06, 1995); today.set_string_date("June 19, 1995"); yesterday.set_date(18, 06, 1995); yesterday.set_string_date("June 18, 1995"); }
% g++ client.cpp date.cpp Later, we’ll learn to write a make file.
class Student{ private: char *name; char *id; char *email; public: void setName(char *studentName); void setId(char *studentId); void setEmail(char *studentEmail); };