Question: Class Constructors, C++ Initialization Lists, Function Overloading, Class Responsibility By implementing the following items the main goal of this programming assignment is to demonstrate the

Class Constructors, C++ Initialization Lists, Function Overloading, Class Responsibility

By implementing the following items the main goal of this programming assignment is to demonstrate the application of class constructors, C++ initialization lists and to separate the elements among classes based on class responsibility:

NOTE

You do not need to implement all items. However, the more you will complete, the higher the grade could be.

As input to this programming assignment take resulting source code from the previous programming assignment.

In class Abstraction implement default constructor in which initialization list set all properties to default values. E.g., numerical types initialize to 0, std::string's to "", but enum'erations to ANY.

Replace all function void Abstraction::init(..) definitions with corresponding class constructors and ensure that during the creation of an object, instead of the function init(..), appropriate constructor is called.

In order to emphasize the responsibility of class Abstraction, declare new class AbstractionSpec with the goal to contain class Abstraction objects specification properties.

Move those elements from class Abstraction to class AbstractionSpec (i.e., enum'erations, variables and functions) that rather represent specification of an abstractions object. In class Abstraction leave only elements that are unique to concrete object of an abstraction. In order to decide which properties should be moved to the specification class, think whether there might be specification case that can be related to multiple abstraction instances. For example, for a bicycle abstraction, the class Bicycle might leave only a serial number and a priceproperty and corresponding 'getter' functions. All other properties (type, color, manufacturer, etc.) becomes a part of class BicycleSpec because they rather represent a specification than a particular bicycle instance. I.e., there might be multiple bicycles with the same type, color, manufacturer, etc.:

BicycleSpec.h

::: class BicycleSpec { public: enum class Type { ANY, MTB, STREET, BEACH, BMX }; BicycleSpec::Type get_type() const { return _type; } ::: private: BicycleSpec::Type _type; ::: }; ::: 

Bicycle.h

::: class Bicycle { public: unsigned get_serial() const { return _serial; } double get_price() const { return _price; } ::: private: unsigned _serial; double _price; ::: }; ::: 

In class Abstraction add new private variable _spec of type AbstractionSpec and provide public function that returns _spec value. For example, in case of the bicycle abstraction:

Bicycle.h

#include "BicycleSpec.h" // important! ::: class Bicycle { public: BicycleSpec get_spec() const { return _spec; } ::: private: BicycleSpec _spec; ::: }; ::: 

Ensure that class Abstraction has an overloaded constructor which as parameters take values of all unique properties and a const'ant reference to an object of type AbstractionSpec. For example, in case of the bicycle abstraction:

Bicycle.h

::: class Bicycle { public: Bicycle(unsigned serial, double price, const BicycleSpec & spec) : _serial(serial), _price(price), _spec(spec) { } ::: }; ::: 

Overload function Inventory::add_item(..) so that as parameters it takes values of class Abstraction unique properties and a const'ant reference to object of type AbstractionSpec. Ensure that new object of type Abstraction is created and added to array _items only if there is at least one mismatch among unique and specification properties.

Modify function Inventory::find_item(..) so that as the parameter it takes only a const'ant reference to object of type AbstractionSpec. Ensure that this function works as previously but by comparing only class AbstractionSpec properties.

If required, update functions Abstraction max_property_name(const Inventory & inv) and double avg_property_name(const Inventory & inv) so that they continue to work with the new implementation of class Abstraction.

Demonstrate adding multiple abstraction objects that share the same object of type AbstractionSpec.

Demonstrate the behaviour of the function Inventory::find_item(..) by passing as an argument an object of type AbstractionSpec in which some properties have default values.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!