Вы находитесь на странице: 1из 1

A simple example We consider a simple example which shows how to create a simple class and define the class's

member functions. // SimpleClass.cpp // A program to demonstrate creation and use of a simple class for dates #include <iostream> using namespace std; // Declaration of Date class class Date { public: void set(int, int, int); void print(); private: int year; int month; int day; }; int main() { // Create a Date object called today Date today; // Call Date member function set() today.set(1,9,1999); cout << "This program was written on "; today.print(); cout << endl; return 0; } // Date member function definitions void Date::set(int d, int m, int y) { if(d>0 && d<31) day = d; if(m>0 && m<13) month = m; if(y>0) year =y; } void Date::print() { cout << day << "-" << month << "-" << year << endl; }

Вам также может понравиться