



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




EEL 3801 Lab # Laboratory Assignment # EEL 3801 Introduction to Computer Engineering Topic: Objects and Classes. Turn in: .CPP files with screen output. Objects and Classes Objects and classes are what really make C++ different from C. They form the basis for object- oriented programming. Classes and objects provide features that are unknown to C programmers, and provide significant power and flexibility, even if they are not used in object-oriented programming. This assignment introduces you to this powerful paradigm.
1. Structures in C++: Classes in C++ are similar in many ways (but not all) to structures in C, and are declared in the same way as structures - by simply replacing the word struct with the word class. Take the following structure and re-declare it as a class with name date1. struct date { int day; // Day of the Month int month; // Month of the year int year; // Year }; 2. Objects: Objects are nothing more than variables, which, in turn, are nothing more than instances of a class. The class is the template, and the object is an instance of the class, or in other words, a copy of the template that has its own identity. Perform the following tasks. 1. Make objects today and tomorrow of type class date1 in a main () program. 2. Instantiate a C data type using the C structure date shown above, and call this variable yesterday. 3. Compile this new configuration and print out the .CPP file for step #2. 4. TURN IN: .CPP file. 3. Data Hiding in classes: Setting the values of members in C++ classes is one difference between classes and structures. For the purpose of hiding data in classes, C++ differentiates between private and public members of a class. Public members of a class are equivalent to those of structures. That is, they can be accessed and changed by external functions in the program (the "." operator for variable, and the "->" operators for pointers). Private members, however, cannot be so changed. By default, all members of a class instance are considered private.
EEL 3801 Lab # Perform the following tasks:
EEL 3801 Lab # cout << "Independence Day is on: "; cout << date1.get_month() << "/" << date1.get_day(); cout << "/" << date1.get_year() << "\n"; cout << "New Year parties begin on "; cout << date2.get_month() << "/" << date2.get_day(); cout << "/" << date2.get_year() << "\n"; }
EEL 3801 Lab # could be to check for errors in data entry. This further tends to make the objects as self- sufficient as possible, which is one of the main objectives of object-oriented programming. Perform the following tasks: