Page 1 of 1

The question provided below must be done using the C++. There are modules that needs to be created along with a provided

Posted: Mon Jun 06, 2022 5:23 pm
by answerhappygod
The question provided below must be done using the C++.
There are modules that needs to be created along with a provided
code module .cpp
This workshop consists of the following modules:
The solution to Part 1 invokes the first three modules.
Enclose all your source code within the sdds namespace and
include the necessary guards in each header file.
The Collection and Set modules you create in
this workshop must have only a header file. 🗎 Explain in the
reflection why we do not split a module into *.h and *.cpp like you
did in the previous workshops.
In all classes that you create, you are allowed to add any
private members that your design requires (without
changing the specs)!
w3 Module (supplied)
Do not modify this module! Look at the code and
make sure you understand how to instantiate a templated class.
Pair Module
This module represents a value-key pair (like the words
and their definition in a dictionary).
Two objects of type Pair are considered to be equal if they have
the same key.
Collection Module
This module represents a family of collections of elements of
any data type (for example, collection of ints, or collection of
Pairs, etc.).
Design and code a class template named Collection. Your template
manages a statically allocated array of any datatype. The template
parameters in order of their specification are:
Your design keeps track of the current number of elements stored
in the collection (which may differ from the capacity of the
collection). Initially the collection has no elements.
Class Members
Public Members
Add any other private members that your design
requires (without changing the specs above)!
Specialize the dummy object when type T = Pair
and CAPACITY = 100 so the key is "No Key" and the value is "No
Value".
Part 2
The second part of this workshop upgrades your Part 1 solution
by adding a collection named Set that doesn't allow duplicates.
Collection Module
Modify the add() member function in the Collection module to
enable inclusion polymorphism on the hierarchy. For the same
purpose, add an empty body destructor.
No other changes are necessary to this module.
Set Module
Add to your project a new module called Set that represents a
Collection where no item appears more than once.
Derive the Set class template from Collection<T, 100> (the
Set will always have a capacity of 100 items). The Set will have
only one template parameter T.
Public Members
No other members need to be added to this class.
Specializations
for T = double, the function add() should consider that two
numbers are the same if their difference in the absolute value is
smaller or equal to 0.01.
When implementing this specialization, consider the function
std::fabs().
The provided code is:
w3_p2.cpp
The Question Provided Below Must Be Done Using The C There Are Modules That Needs To Be Created Along With A Provided 1
The Question Provided Below Must Be Done Using The C There Are Modules That Needs To Be Created Along With A Provided 1 (43.39 KiB) Viewed 30 times
The Question Provided Below Must Be Done Using The C There Are Modules That Needs To Be Created Along With A Provided 2
The Question Provided Below Must Be Done Using The C There Are Modules That Needs To Be Created Along With A Provided 2 (38.36 KiB) Viewed 30 times
The Question Provided Below Must Be Done Using The C There Are Modules That Needs To Be Created Along With A Provided 3
The Question Provided Below Must Be Done Using The C There Are Modules That Needs To Be Created Along With A Provided 3 (45.01 KiB) Viewed 30 times
The Question Provided Below Must Be Done Using The C There Are Modules That Needs To Be Created Along With A Provided 4
The Question Provided Below Must Be Done Using The C There Are Modules That Needs To Be Created Along With A Provided 4 (7.39 KiB) Viewed 30 times
#include #include #include #include #include "Collection.h" #include "Collection.h" #include "Set.h" #include "Set.h" #include "Pair.h" #include "Pair.h" int cout = 0; // won't compile if headers don't follow convention int main(int argc, char** argv) { std::cout << "Command Line: \n"; " std::cout << -\n"; for (int i = 0; i < argc; i++) std::cout << std::setw(3) << i + 1 << ": << argv << '\n'; std::cout << ------\n\n"; // Data to be used by the template classes long iData[] { 16, 12, 9, 3, 21, 12, 23 }; double dData[] { 1.222, 5.777, 1.223, 51.333, 8.888, 1.221 }; sdds::Pair pData [] { sdds::Pair("static memory", "memory allocated during the compilation time"), sdds::Pair("programmer", "a person who writes code"), sdds::Pair("dynamic memory", "memory allocated during the runtime"), sdds::Pair("client of a class", "a piece of code that uses the class"), sdds::Pair("dynamic memory", "memory allocated with 'new' operator"), sdds::Pair("user", "a person who runs and interracts with the program"), sdds::Pair("array", "a contiguous block of memory storing multiple objects"), sdds::Pair("client of a function", "a piece of code that uses the function"), sdds::Pair("user", "Just John!"), }; { std::cout << *\n"; *\n"; std::cout << "* Testing the Collection of Integers std::cout << *\n"; sdds::Collection colIntegers; for (const auto& item : iData) colIntegers.add (item); std::cout << "Collection size: [" << colIntegers.size() << "]\n"; colIntegers.display(); ******
H std::cout << "Item [0]: << colIntegers[0] << "\n"; std::cout << "Item [5]: std::cout << "Item [9]: std::cout << << colIntegers[5] << "\n"; << colIntegers [9] << "\n"; } { std::cout << std::cout << "* Testing the Set of Integers std::cout << sdds::Collection* setIntegers new sdds::Set(); for (const auto& item : iData) setIntegers->add (item); std::cout << "Set size: [" << setIntegers->size() << "\n"; setIntegers->display(); H std::cout << "Item [0]: << (*setIntegers)[0] << "\n"; 11 std::cout << "Item [5]: << (*setIntegers) [5] << "\n"; std::cout << "Item [9]: << (*setIntegers) [9] << "\n"; std::cout << delete setIntegers; std::cout << ** std::cout << Testing the Collection of Floats std::cout << ****** sdds::Collection colFloats; for (const auto& item : dData) colFloats.add(item); std::cout << "Collection size: [" << colFloats.size() << "\n"; colFloats.display(); H std::cout << "Item [0]: << colFloats[0] << "\n"; std::cout << "Item [5]: << colFloats [5] << "\n"; std::cout << "Item [9]: << colFloats [9] << "\n"; std::cout << } { std::cout << std::cout << "* Testing the Set of Floats std::cout << sdds::Collection* setFloats = new sdds::Set; } { ******: *\n\n"; *\n"; *\n"; **\n"; \n\n"; *\n"; *\n"; *\n"; *\n\n"; *\n"; *\n"; *\n";
} { } { for (const auto& item : dData) setFloats->add (item); std::cout << "Set size: [" << setFloats->size() << "\n"; setFloats->display(); std::cout << "Item [0]: << (*setFloats)[0] << "\n"; std::cout << "Item [5]: << (*setFloats) [5] << "\n"; std::cout << "Item [9]: << (*setFloats) [9] << "\n"; std::cout << *\n\n"; delete setFloats; std::cout << \n"; *\n"; std::cout << "* Testing the Collection of Pairs std::cout << *\n"; sdds::Collection colDictionary; for (const auto& item: pData) colDictionary.add(item); std::cout << "Collection size: [" << colDictionary.size() << "]\n"; colDictionary.display(); std::cout << "Item [0]: [" << colDictionary [0].getKey() << "][" << colDictionary [0].getValue() << "\n"; std::cout << "Item [8]: [" << colDictionary [8].getKey() << "][" << colDictionary [8].getValue() << "\n"; std::cout << "Item [9]: [" << colDictionary [9].getKey() << "][" << colDictionary [9].getValue() << "\n"; std::cout << std::cout << std::cout << "* Testing the Set of Pairs *\n"; *\n"; ***\n"; std::cout << sdds::Collection* setDictionary = new sdds::Set(); for (const auto& item : pData) setDictionary->add (item); std::cout << "Set size: [" << setDictionary->size() << "]\n"; setDictionary->display(); std::cout << "Item [1]: [" << (*setDictionary) [1].getKey() << "][" << (*setDictionary) [1].getValue() << "\n"; std::cout << "Item [4]: [" << (*setDictionary) [4].getKey() << "][" *\n\n";
} << (*setDictionary) [4].getValue() << "\n"; std::cout << "Item [11]: [" << (*setDictionary) [11].getKey() << "][" << (*setDictionary) [11].getValue() << "\n"; Ặc x\n\n"; std::cout << "**** delete setDictionary; } return cout;