C++ Programming Assignment: Inheritance and Design Philosophies

Verified

Added on  2022/10/10

|6
|1020
|171
Homework Assignment
AI Summary
This C++ programming assignment explores fundamental concepts such as protected access, inheritance, and polymorphism. It delves into the usage and implications of the protected keyword in C++, including who can access protected members and the impact of inheritance on access levels. The assignment contrasts "Is a" and "Has a" relationships, explaining their differences in the context of C++ programming. Furthermore, it examines polymorphism in C++ and compares its implementation with C#. The assignment also explores the goals of C++ designers, how C++ handles exceptions using try, catch, and throw keywords, and compares the design philosophies of Smalltalk, C++, and C#. Two types of inheritance, multilevel and hybrid, are defined. Finally, it compares the OO 'purity' of Smalltalk and Eiffel, and it also addresses a programming principle that Eiffel does not support.
Document Page
Running head: PROGRAMMING
PROGRAMMING
Name of the Student:
Name of the University:
Author Note:
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
1PROGRAMMING
Table of Contents
Document Page
2PROGRAMMING
Tutorial 7
When is the protected access used in C++? Who can access protected members of class?
The protected keyword specifically provisions with the access to all of the members
existing within the class down the list of members until the next access specifier or might as
well be the reach towards the end of the definition belonging to the class. All of the members
belonging to the class when declared as protected can be utilized by the following mentioned
below. These are,
Member functions belonging to the class that had been originally declared by all of
these members.
Friends of this particular class that had been originally declared by all of these
members.
Classes that have been derived from the public or the protected access from the
originally existing class that have been declared by this specific group of members.
The direct classes that have been derived privately also having the inclusion of the
private access to that of the protected members.
Protected members of the class are very much considered to be similar to that of the
private members as a reason of the fact that they cannot be accessed from the outside of the
class. However, they can be very much accessed by the classes that have been derived or
might as well be accessed from the child classes to be specific.
When deriving a class from a protected class, what is the level of access of the
public/protected members of the base class in the derived class?
The private members existing within the class carry the provision to be inherited but
however cannot be accessed directly from the classes that have been derived. They can be
Document Page
3PROGRAMMING
easily accessed by the usage of the public or the protected methods related to the base class.
This specific mode of inheritance specifies how all of the data that is private as well as
protected can be particularly accessed by the derived classes.
What is the difference between a "Is a" relationship and a "Has a" relationship?
“Has a” commonly refers to a dynamic form of binding while on the other hand the
inheritance “Is a” refers to the static form of binding that is specifically existing.
How is polymorphism implemented in C++? Is this different from the way it is
implemented in C#?
Polymorphism in C++ means the procedure for calling a member function that will
specifically cause a differently existing function that needs to be executed entirely depending
upon the specific type of object that invokes a particular function.
However, on the other hand polymorphism in C# is specifically implemented through
the usage of inheritance as well as through the usage of the “virtual” keyword. The classes
that have been derived inherit all of the base members of the class, keeping apart the
constructors that are completely based upon the levels of accessibility.
What were goals of the designers of C++?
The primary goals of the designers who had developed this language was to
successfully implement as well as develop an efficient code for the system that will carry the
potential to control the existing complexity. In addition to this, to write elegant as well as
efficient sets of codes along with the provisioning of direct access to all of the hardware as
well as the zero – overhead abstraction.
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
4PROGRAMMING
How does C++ handle exceptions?
Handling of exceptions in C++ is mainly built upon the primary three keywords
namely, try, catch as well as throw. A specific program throws a particular exception
whenever a specific problem shows up. This is all done with the individual usage of a throw
keyword. Another program catches the exception with the usage of an exception handler at
the spot where the problem has been identified.
Compare the design philosophy of Smalltalk, C++ and C#.
Smalltalk- has the inclusion of well factored designs through the usage of
inheritance. Every single existing class inherits some or the other behavior from that of its
specific superclass.
C++ on the other hand refers to a light – weight abstraction language built for the
purpose of programming specifically for the building as well as the efficient along with
elegant abstractions. In addition to this, it offers both of the hardware with that of the access
as well as abstraction completely based upon C++.
Name and describe two types of inheritance.
Inheritances can be classified into five primary types. Two types of inheritance are,
Multilevel Inheritance- refers to a special type of inheritance, which has the inclusion
of a super class, a sub class as well as an intermediate class.
Hybrid inheritance- Refers to a combination of two primary inheritances namely,
hierarchical inheritance and the multilevel inheritance.
Document Page
5PROGRAMMING
Compare and contrast the OO ‘purity’ of Smalltalk and Eiffel.
Eiffel is considered to be purely Object – Oriented as a programming language. On
the other hand, Smalltalk is also considered to be a programming language that is purely
Object – Oriented.
Is there a programming principle that Eiffel does not support? If so, state the principle and
– with the help of an example – explain why Eiffel does not support it.
The basic programming principle that Eiffel does not support in particular is the Goto,
break as well as equivalent.
This can be supported with the evidence that it specifically encourages the
programmer to think much more clearly regarding the procedure related to the
implementation. Secondly, the source code is read a number of times more than the times it is
written.
chevron_up_icon
1 out of 6
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]