- Tags:
- Show more
- Pages:
- 2
- Words:
- 550
Programming Using Structures and Classes Firstname Lastname University Name Programming Using Structures and Classes The report answers a few questions related to programming using structures and classes. Under What Circumstances Must You Use Classes? Classes can be used in systems where there is a need to represent real world objects that have certain features and perform a certain behavior. For instance, a class student with name, age, gender, id, etc. and the student can enroll to a course, take an exam, mark attendance, etc. Classes can be used in designing real world systems inheritance that defaults to private access need to be defined between real world objects or the data needs to be encapsulated i.e. hidden from a user. In classes, as the object’s features (data members) are private by default, they can only be altered through the interfaces called member functions. Why do you use a class instead of a structure? Are they interchangeable? Explain your answer. Structures and classes are essentially the same and can be used interchangeably. Both provide the features of data encapsulation and inheritance. In case of structures, the ‘private’ access specifier is exclusively mentioned, while in the case of classes, the ‘public’ access specifier is mentioned. In both the cases, functions are used to access private data. As a general C++ programming convention, structures are used by programmers when representing plain old data with backward compatibility. Classes are used instead of structures in cases where backward compatibility is not required. Secondly, in real world systems, when we need the access specifiers and inheritance to default to
Leave feedback