Class Constructors, C++ Initialization Lists, Function Overloading, Class Respon
ID: 3845054 • Letter: C
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 application of class constructors, C++ initialization lists and to separate the elements among classes based on class responsibility:
NOTE
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 object’s specification properties.
Move those elements from class Abstraction to class AbstractionSpec (i.e., enum'erations, variables and functions) that rather represent specification of an abstraction’s 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
Bicycle.h
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
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
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.
NOTE
You do not need to implement all items. However, the more you will complete, the higher the grade could be.Explanation / Answer
#include <iostream>
using namespace std;
void print(int i) {
cout << " Here is int " << i << endl;
}
void print(double f) {
cout << " Here is float " << f << endl;
}
void print(char* c) {
cout << " Here is char* " << c << endl;
}
int main() {
print(05);
print(05.10);
print("ten");
return 0;
} #include <iostream>
using namespace std;
void print(int i) {
cout << " Here is int " << i << endl;
}
void print(double f) {
cout << " Here is float " << f << endl;
}
void print(char* c) {
cout << " Here is char* " << c << endl;
}
int main() {
print(05);
print(05.10);
print("ten");
return 0;
}