Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This worksheet focuses on developing your understanding of class inheritance in C++. A key aspect of this is being able to recognise when inheritance is

This worksheet focuses on developing your understanding of class inheritance in C++. A key aspect of this is being able to recognise when inheritance is a useful tool for a given problem. This worksheet also provides you with some experience of using virtual functions to override behaviour in subclasses. You will be provided with all the resources you need to complete this worksheet.

Please ensure that you create a header file (.h) with header guard (or #pragma once directive) and code file (.cpp) for each class

Task 1: carbon footprints

Governments and companies worldwide are becoming increasingly concerned with carbon footprint (annual release of carbon dioxide into the atmosphere) from buildings burning various types of fuels for heat, vehicles burning fuels for power, and the like. Many scientists blame these greenhouse gases for the phenomenon called global warming. This task involves creating several classes to model this phenomenon using inheritance and polymorphism.

Create three classes (Building, Car and Bicycle) which are initially unrelated by inheritance. Give each class some appropriate attributes and behaviour that it does not have in common with the other classes.

Create an abstract class called CarbonFootprint with only one pure virtual function called getCarbonFootprint().

Make each of your classes inherit from the CarbonFootprint class and implement a getCarbonFootprint() function for each class. Use the internet to find a realistic carbon footprint value for each of them.

Write a small application that creates an instance of each class. Create a vector of pointers to CarbonFootprint objects and add the address of each instance to the vector. Next, iterate over the vector (using the at() function rather than the [] operators) and polymorphically invoke the getCarbonFootprint() function and output the objects carbon footprint.

Task 2: logically that might be true The following UML Class Diagram provides an Object-orientated design for a simple logic-based system capable of performing AND, OR and NOT operations:

This design makes use of inheritance and abstract classes to provide a generic approach to this problem. It would be easy to add extra logic gates to this system such as XOR, NAND or NOR. This task involves creating a set of classes based on this class diagram using single inheritance and pure virtual functions. Write a small application that makes use of the new classes to print out the truth table for the following logic circuit:

Now, add a new XORGate class to your system which inherits from BinaryGate and implement an XOR operation. Use your new XORGate class to validate the truth table you printed out for the logic circuit above.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

12.4 What is goodwill, and how is it created? (Appendix)

Answered: 1 week ago

Question

How free does this public see itself to act on this issue?

Answered: 1 week ago

Question

Discuss the key ambient conditions and their effects on customers.

Answered: 1 week ago

Question

Be familiar with the integrative servicescape model.

Answered: 1 week ago

Question

Understand the role of corporate design in communications.

Answered: 1 week ago