Documente Academic
Documente Profesional
Documente Cultură
CT025-3-2
Learning Outcomes
By the end of this session, you should be able to:
create, debug and run a simple C++ programs using the concept of preprocessor wrapper, constant member objects, functions,friend functions, friend classes, static class members
Preprocessor wrapper
//Time.h #ifndef TIME_H preprocessor wrapper prevents multiple inclusions #define TIME_H of header file class Time { public: Time( ); void setTime(int, int, int); void printUniversal( ); void printStandard( ); private: int hour; int minute; int second; }; preprocessor wrapper #endif
CT025-3-2-PCPP (Programming Concepts in C++) Classes and Objects Slide 5 (of 35)
Constant objects
keyword const used
to specify that an object is not modifiable any attempt to modify the object should result in compilation error const Time noon (12, 0, 0); declares a const object noon of class Time and initializes it to 12 noon
delete
to deallocate or release memory to return the memory to the free store delete timePtr;
CT025-3-2-PCPP (Programming Concepts in C++) Classes and Objects Slide 30 (of 35)
without [ ] only the first object in the array will receive the destructor call
CT025-3-2-PCPP (Programming Concepts in C++) Classes and Objects Slide 32 (of 35)
Follow up Assignment
Create two classes. The first holds customer data
specifically, a customer number and zip code. The second, a class for cities, holds the city name, state and zip code.