Please compelete this in c++, make it runable in codeblocks ide and explain what
ID: 3798876 • Letter: P
Question
Please compelete this in c++, make it runable in codeblocks ide and explain what you are doing in comment form.
make this as basic as possible I want to be able to understand it not just get an answer.
please follow al the innstructions
Thanks in advance!
1 In this lab you will implement a dynamically allocated array-based keyed-collection class keyed collection . In a keyed collection , values are stored and retrieved using a key. There can be at most one value at a given key.
The best way to understand a keyed collection is through examples. In the example below we will use strings for keys and ints for values.
k e y e d c o l l e c t i o n b o o k s ;
b o o k s . s e t ( ” f i c t i o n ” , 2 0 0 ) ; / / n ot e : k e y i s ” f i c t i o n ” value is 200
b o o k s . s e t ( ” s c i e n c e ” , 9 8 ) ;
b o o k s . s e t ( ” h i s t o r y ” , 3 1 9 ) ;
c o ut << b o o k s . g e t s i z e ( ) << e n dl ; / / 3
c o ut << b o o k s . g e t ( ” f i c t i o n ” ) << e n dl ; / / 200
c o ut << b o o k s . g e t ( ” h i s t o r y ” ) << e n dl ; / / 319
c o ut << b o o k s . g e t ( ” s c i e n c e ” ) << e n dl ; / / 98
c o ut << b o o k s . h a s k e y ( ” s c i e n c e ” ) << e n dl ; / / t r u e ( 1 )
c o ut << b o o k s . h a s k e y ( ” m y sti ci sm ” ) << e n dl ; / / f a l s e ( 0 )
b o o k s . s e t ( ” f i c t i o n ” , 1 9 5 ) ; / / u p d at e s f i c t i o n e n t r y
c o ut << b o o k s . g e t s i z e ( ) << e n dl ; / / 3
c o ut << b o o k s . g e t ( ” f i c t i o n ” ) << e n dl ; / / 195
b o o k s . remove ( ” f i c t i o n ” ) ;
c o ut << b o o k s . g e t s i z e ( ) << e n dl ; / / 2
entry : : k e y t y p e k e y s = c . g e t k e y s ( ) ;
f o r ( s i z e t i = 0; i < b o o k s . g e t s i z e ( ) ; i ++ ) {
c o ut << k e y s [ i ] << e n dl ;
}
/ / loop a bove out puts history and science ( but maybe not in that order )
b o o k s . s e t ( ” c r a f t i n g ” , 1 2 1 ) ;
c o ut << b o o k s << e n dl ; / / { science : 98, crafting : 121 , history : 319}
2 Getting Started Create the classes named keyed collection and entry and a file for your unit tests keyed collection tests.cpp. Place your classes inside a namespace called monster. Note: Please stick with the file names, namespace names, class names and method signatures used in this document.The following sections describe these classes. As you build the class, write a thorough set of unit tests for it.
3 The entry class Each entry in a keyed-collection has a key and a value. Add two typedefs to your entry class: one for the key type (call it key type and set it to string ) and one for the value type (call it value type and set it to int). Add two instance variables, one for the key and one for the value. Create “getters” and “setters” for both of these instance variables. Provide a constructor that takes two arguments, key and value, and stores them in the appropriate instance variables. Do not provide an “empty” (zero argument) constructor.
4 The keyed collection class’s instance variables Your keyed collection class should have the following instance variables:
• std :: size t capacity – the capacity of the entries array
• std :: size t used – the number of elements in the entries array that are being used.
• entry entries – an dynamically allocated array of pointers to entry objects
5 The keyed collection class’s methods Implement the following methods:
• keyed collection ( std :: size t initial capacity =30) – construct an empty keyed collection with the speci- fied capacity (default to 30).
• bool has key( key type key) const – return true if there is an entry with the specified key, false otherwise.
• void set ( key type key, value type value ) – add an entry mapping key to value. If there is already an entry with the specified key, this one must replace it.
• bool remove(key type key) – remove the entry with the specified key, if there is one. Return true if an entry was removed, false otherwise.
• value type get ( key type key) const – return the value for the specified key. Fail an assertion if there is no entry with the specified key. (You do not need to test the failed assertion case.)
• std :: size t get size () const – return the number of entries 2
• key type get keys () const – return a dynamically allocated array of the keys (it must have get size () elements). Note: the order of the keys may not be related to the order in which they were inserted.
• std :: ostream& operator<<(std::ostream& out, const keyed collection & c) – print the keyed collection on the supplied stream. Use the format {key1: value1 , key2: value2 , key3: value3 ...} . If the collection is empty, simply print {}.
• void operator+=(const keyed collection & other ) – member function! add all of the key,value pairs that are in other into this collection. Any duplicates (keys that appear in both this collection and other ) will be overridden by other.
• keyed collection operator+(const keyed collection & kc1, const keyed collection & kc2) – free function! produce a keyed collection that contains all of the key,value pairs from kc1 and kc2. If there are keys in common between kc1 and kc2, the values in kc2 take precedence.
Note: Your collection will need to dynamically re-size itself once its capacity is reached as new entries are added with the set method. Include a private resize () method to perform this operation.
6 Before you turn in your solution You will receive a substantial point deduction if your solution does not compile. Suppose, for example, that you did not complete the last two operators and that their code is causing your class to fail to compile. Comment them out and indicate (in the comment) that they are not compiling. Similarly comment out your corresponding tests of those methods.
Explanation / Answer
#ifndef KyedDATABASE_H
#define KyedDATABASE_H
using namespace std;
class KyedDatabase
{
public:
~KyedDatabase();
void print_team() const;
KyedDatabase& operator=(const KyedDatabase&);
KyedDatabase(const KyedDatabase&);
KyedrDatabase();
void load_team(ifstream&);
void print_team();
virtual void get_Kyedcollection){};
private:
int operator_count;
BaseKyed* operator[100];
int totalcollection;
float totalcollection;
};
#endif
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.