Question: 1. Show me the function prototype for a void function named getData whose single parameter is a two-dimensional integer array of size 10 by 100.

1. Show me the function prototype for a void function named getData whose single parameter is a two-dimensional integer array of size 10 by 100. The purpose of the getData function is to fill values into the passed in array.

2. Suppose we want another overloaded getItem() member function of the ShoppingCart class, just like the one declared in line 58, but that returns a C String rather than a string class value. What would the declaration for that function look like?

3.We can tell from the code that this program is depending on at least one use of the Protected scope: what must be declared as Protected for the code to work as shown?

USE PROGRAM BELOW TO ANSWER THE QUESTIONS:

1. //---------------------------------------------------------------------------

2. // CSC160 Test Three - TestThree.cpp

3. //---------------------------------------------------------------------------

4. #include

5. #include "ShoppingCart.h"

6. using namespace std;

7. int main()

8. {

9. cout << "Testing Shopping Cart Class";

10. ShoppingCart testCarts[3];

11. string test1("Golf Clubs"), test2("Golf Bag");

12. try

13. {

14. testCarts[0].addToCart(test1);

15. testCarts[0].addToCart(test2);

16. testCarts[0].addToCart("Golfballs (12)");

17. testCarts[1].addToCart("CD-R (50)");

18. testCarts[1].addToCart("Printer Toner");

19. testCarts[2].addToCart(testCarts[0].getItem("Golf Clubs"));

20. testCarts[2].addToCart(testCarts[1].getItem(0));

21. testCarts[2].addToCart(testCarts[1].getItem(1));

22. cout << " Testing: " << testCarts[2].getItem(0);

23. cout << " Testing: " << testCarts[2].getItem(1);

24. cout << " Testing: " << testCarts[2].getItem(2);

25. cout << " Testing: " << testCarts[2].getItem(3);

26. }

27. catch(ShoppingCartException err)

28. {

29. cout << " Caught error: " << err.errorMessage();

30. }

31. catch(...)

32. {

33. cout << " Caught unexpected error";

34. }

35. return 0;

36. }

37. //---------------------------------------------------------------------------

38. // CSC160 Test Three - ShoppingCart.h

39. //---------------------------------------------------------------------------

40. using namespace std;

41. #ifndef CART_H

42. #define CART_H

43. #include

44. #include "ApplicationException.h"

45. class ShoppingCartException : public ApplicationException

46. {

47. public:

48. ShoppingCartException();

49. ShoppingCartException(string errorMsg);

50. ShoppingCartException(char errorMsg[]);

51. };

52. class ShoppingCart

53. {

54. public:

55. ShoppingCart();

56. void addToCart(string itemDesc) throw(ShoppingCartException);

57. void addToCart(char itemDesc[]) throw(ShoppingCartException);

58. string getItem(string itemDesc) throw(ShoppingCartException);

59. string getItem(char itemDesc[]) throw(ShoppingCartException);

60. string getItem(int itemNumber) throw(ShoppingCartException);

61. private:

62. string *cartItems;

63. int numItems;

64. int allocatedItems;

65. void increaseCartAllocation(int count);

66. };

67. #endif

68. //---------------------------------------------------------------------------

69. // CSC160 Test Three - ShoppingCart.cpp

70. //---------------------------------------------------------------------------

71. #include

72. #include "ShoppingCart.h"

73. using namespace std;

74. const int ALLOCATE_SIZE = 10;

75. // Implementation of the ShoppingCartException class

76. ShoppingCartException::ShoppingCartException(): ApplicationException()

77. { message = "Error Detected in Shopping Cart Class"; }

78. ShoppingCartException::ShoppingCartException(string errorMsg): ApplicationException()

79. { message = errorMsg; }

80. ShoppingCartException::ShoppingCartException(char errorMsg[]): ApplicationException()

81. { message = errorMsg; }

82. // Implementation of the ShoppingCart class

83. ShoppingCart::ShoppingCart()

84. {

85. cartItems = new string[ALLOCATE_SIZE];

86. numItems = 0;

87. allocatedItems = ALLOCATE_SIZE;

88. }

89. void ShoppingCart::addToCart(string item) throw(ShoppingCartException)

90. {

91. if (numItems == allocatedItems)

92. increaseCartAllocation(ALLOCATE_SIZE);

93. numItems++;

94. cartItems[numItems - 1] = item;

95. }

96. void ShoppingCart::addToCart(char item[]) throw(ShoppingCartException)

97. {

98. if (numItems == allocatedItems)

99. increaseCartAllocation(ALLOCATE_SIZE);

100. numItems++;

101. cartItems[numItems - 1] = item;

102. }

103. string ShoppingCart::getItem(string itemDesc) throw(ShoppingCartException)

104. {

105. for (int i = 0; i < numItems; i++)

106. if (cartItems[i] == itemDesc)

107. return cartItems[i];

108. throw ShoppingCartException("Item " + itemDesc + " is not in Shopping Cart");

109. }

110. string ShoppingCart::getItem(char itemDesc[]) throw(ShoppingCartException)

111. {

112. string temp = itemDesc;

113. for (int i = 0; i < numItems; i++)

114. if (cartItems[i] == temp)

115. return cartItems[i];

116. throw ShoppingCartException("Item is not in Shopping Cart");

117. }

118. string ShoppingCart::getItem(int itemNumber) throw(ShoppingCartException)

119. {

120. if (itemNumber > numItems - 1)

121. {

122. ShoppingCartException temp("Item number is too large");

123. throw temp;

124. }

125. else

126. return cartItems[itemNumber];

127. }

128. void ShoppingCart::increaseCartAllocation(int count)

129. {

130. allocatedItems += count;

131. string *temp = new string[allocatedItems];

132. for (int i = 0; i < numItems; i++)

133. temp[i] = cartItems[i];

134. cartItems = temp;

135. }

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!