Question: Created a fully templatized map. . It should have two template variables, one for the key and one for the dat I am referring to

Created a fully templatized map.

. It should have two template variables, one for the key and one for the dat I am referring to them as KEY and DATA both here and in the starting code.

a. This can just be two parallel arrays, one for the keys and one for the data.

b. Create a constant k_max to indicate the maximum # of data entries in your map. k_max should be between 5 and 2000. Small is perfectly fine.

c. The following methods must exist for this map:

. A default constructor. This constructor zeros any indexes and then stops.

i. A find function that returns the index where the KEY is found.

0. You will need create the find function first before you do the insert function below.

1. You should use the == operator to determine if it's found. This will allow part 3 to work.

ii. An insert function that takes a KEY and a DATA.;

0. This function will not insert if the map is full or the key already exists. It will print an error message. (On your own time you can play with try's and catches with this.)

1. This function will print what it is trying to insert.

iii. A constructor that takes a single KEY and a single DATA. It should initialize the index to zero and then call the insert function for that key and data.

iv. A function that loops through the map and prints it.

d. I provided a testing function for your map - test_insert;

2.

#include

3.

#include

4.

6.

using std::string;

7.

9.

// I have a standardized to-do where I ask you to create a variable using your

10.

// template class. It is:

11.

// todo: VAR {variable name} : KEY -> datatype, DATA -> datatype

12.

// ie VAR: {solar} - KEY -> string, DATA -> int

13.

// which means: create a map variable "solar" that takes the key that is a string

14.

// and data that is an int

15.

17.

void test_insert();

18.

void test_my_class();

19.

21.

int main()

22.

{

23.

std::cout

24.

// you can add your own tests between this start and stop.

25.

std::cout

26.

28.

std::cout

29.

31.

test_insert();

32.

34.

test_my_class();

35.

37.

std::cout

38.

}

39.

41.

void test_insert()

42.

{

43.

std::cout

44.

//// uncomment this when you are ready and follow the instruction

45.

//// todo: var: {solar} - key -> string, data -> int

46.

//// create a map variable "solar" that takes the key that is a string and data that is an int

47.

49.

// solar; // update this line to make your variable "solar" as described above.

50.

std::cout

51.

//// don't change these lines other then to uncomment them.

52.

std::cout

53.

// solar.insert("moon", 238900);

54.

// solar.insert("mars", 33900000);

55.

// solar.insert("leo satellite", 1200);

56.

std::cout

57.

std::cout

58.

std::cout

59.

// solar.print();

60.

std::cout

61.

std::cout

62.

std::cout

63.

65.

// solar.insert("moon", 238900);

66.

std::cout

67.

69.

std::cout

70.

}

71.

73.

void test_my_class()

74.

{

75.

std::cout

76.

std::cout

77.

79.

// chocolate test[k_max]{ {"dark"},{"swiss"},{"semi-sweet"}, {"Marou "},{"Krakakoa"} };

80.

////ToDo: change the line above to be an array of your class, and initialize appropriately.

81.

//// My class was called chocolate. Change it to yours.

82.

//// Note: this array shouldn't use your default constructor more then once otherwise

83.

//// you'll get a duplicate key error below.

84.

86.

//// todo: VAR {intkey} - : KEY -> int , DATA -> your class

87.

89.

std::cout

90.

//// Uncomment the loop below. (Don't change it after)

91.

//for (int i = 0; i

92.

// intkey.insert(i, test[i]);

93.

//intkey.print();

94.

//// leave this loop alone

95.

std::cout

96.

98.

100.

//// todo: VAR {classkey} - : KEY -> your class , DATA -> int

101.

103.

//// Uncomment the loop below. (Don't change it after)

104.

std::cout

105.

//for (int i = 0; i

106.

// classkey.insert(test[i], i);

107.

// // note: this also tests your overloaded

108.

//classkey.print();

109.

std::cout

110.

//// leave this loop alone

111.

std::cout

112.

114.

//// Note: this also tests your overloaded == operator. :)

115.

//// you will get either a full error or a duplicate error. Doesn't matter which.

116.

//classkey.insert(test[0], 0);

117.

std::cout

118.

std::cout

}

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 Programming Questions!