Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

stress_ball.h #include #include #include #include #include #include #include using namespace std; enum class stress_ball_colors { red, blue, yellow, green }; enum class stress_ball_sizes { small,

image text in transcribedimage text in transcribed

stress_ball.h

#include  #include  #include  #include  #include  #include  #include  using namespace std; enum class stress_ball_colors { red, blue, yellow, green }; enum class stress_ball_sizes { small, medium, large }; class stress_ball { private: stress_ball_colors color; stress_ball_sizes size; public: stress_ball() : color(stress_ball_colors(rand() % 4)), size(stress_ball_sizes(rand() % 3)) {} stress_ball(stress_ball_colors c, stress_ball_sizes s) : color(c), size(s) {} stress_ball_colors get_color() const { return color; } stress_ball_sizes get_size() const { return size; } bool operator==(const stress_ball &c) { bool case1 = false; bool case2 = false; if (get_color() == c.get_color()) { case1 = true; } if (get_size() == c.get_size()) { case2 = true; } return case1 && case2; } void print_stress_ball() { switch (get_size()) { case stress_ball_sizes::small: cout  

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

collection.h

#include  #include  #include  #include  #include  #include  #include  #include "stress_ball.h" #include  using namespace std; enum class sort_choice{bubble_sort, insertion_sort, selection_sort}; class Collection : public stress_ball{ private: stress_ball *array; int size; int capacity; void resize(){ capacity = 2 * capacity; if (capacity == 0){ capacity = 4; Collection *temp = new Collection[capacity]; for (int i = 0; i array[i] = array[i]; } array = nullptr; array = temp; } } public: Collection() : size(0), capacity (0), array(nullptr){} Collection(int s) : size(0), capacity(s), array(new stress_ball[capacity]){} Collection(const Collection &c) : size(c.size), capacity(c.capacity), array(new stress_ball[capacity]) { for (int i = 0; i >(istream& is, Collection& c); friend ostream& operator>(istream& is, Collection& c){ stress_ball_sizes size; stress_ball_colors color; string tempSize; string tempColor; is >> tempSize; is >> tempColor; while (is.good()){ if (tempSize == "small"){ size = stress_ball_sizes::small; } else if (tempSize== "medium"){ size = stress_ball_sizes::medium; } else if (tempSize == "large"){ size = stress_ball_sizes::large; } if (tempColor == "yellow"){ color = stress_ball_colors::yellow; } else if (tempColor == "green"){ color = stress_ball_colors::green; } else if (tempColor == "blue"){ color = stress_ball_colors::blue; } else if (tempColor == "red"){ color = stress_ball_colors::red; } c.insert_item(stress_ball(color,size)); is >> tempSize; is >> tempColor; } return is; } ostream& operator c[j+1].get_size()){ stress_ball temp = c[j]; c[j] = c[j+1]; c[j+1] = temp; } } } case sort_choice::insertion_sort: for (i = 1; i = 0 && c[i].get_size() > key.get_size()){ c[j+1] = c[j]; j = j - 1; } c[j+1] = key; } case sort_choice::selection_sort: for(i = 0; i   1. (50 points) Write a templated version of the class Collection with the template parameters: Obj, F1, F2. (a) The templated class Collection and all the templated functions should be in the header file collection.h (the file collection.cpp is not necessary and can be dropped). (b) Test it with the class Stress_ball as Obj, Stress_ball_colors as F1, and Stress_ball_sizes as F2. Use the file stress_ball_test.cpp.  Perform the same operations: make_copy, make_union, swap, and sort_by_size for testing.  Modify the test file from Part 2 to do this. In order not to use long class names, use aliases: using CollectionSB = Collection; using Collection JN = Collection ; (c) The input operator>> can be templated but you need to use a specific version for each template class. So for the class Stress_ball use this approach: istream& operator>>(istream& is, Collection SB & c); where you explicitly use the class Stress_ball (do not use template parameters Obj, F1, or F2). And do not put it in the file collection.h but put in the file stress_ball_test.cpp. 2. (30 points) Write a class Jeans similar to Stress_ball with the same class members: color and size. Feel free to use your own colors and sizes. Suggested colors: white, blue, brown, black, and suggested sizes: small, medium, large, xlarge. (a) Apply the Collection functions to Jeans objects (b) Provide similar testing cases for the templated Collection with Jeans objects.  Use the test file jeans_test.cpp. (c) For the input operator>>, use the class Jeans explicitly (do not use template parameters Obj, F1, or F2): istream& operator>>(istream& is, Collection JN& c); Do not put it in the file collection.h but use it in the file jeans_test.cpp. 3. Here is an example of the file collection_test.cpp but you can modify it. #include  using namespace std; void test_stress_balls(); void test_jeans(); int main() { int answer; cout > answer; if (answer == 0) test_stress_balls(); else if (answer == 1) test_jeans(); else cout ; using Collection JN = Collection ; (c) The input operator>> can be templated but you need to use a specific version for each template class. So for the class Stress_ball use this approach: istream& operator>>(istream& is, Collection SB & c); where you explicitly use the class Stress_ball (do not use template parameters Obj, F1, or F2). And do not put it in the file collection.h but put in the file stress_ball_test.cpp. 2. (30 points) Write a class Jeans similar to Stress_ball with the same class members: color and size. Feel free to use your own colors and sizes. Suggested colors: white, blue, brown, black, and suggested sizes: small, medium, large, xlarge. (a) Apply the Collection functions to Jeans objects (b) Provide similar testing cases for the templated Collection with Jeans objects.  Use the test file jeans_test.cpp. (c) For the input operator>>, use the class Jeans explicitly (do not use template parameters Obj, F1, or F2): istream& operator>>(istream& is, Collection JN& c); Do not put it in the file collection.h but use it in the file jeans_test.cpp. 3. Here is an example of the file collection_test.cpp but you can modify it. #include  using namespace std; void test_stress_balls(); void test_jeans(); int main() { int answer; cout > answer; if (answer == 0) test_stress_balls(); else if (answer == 1) test_jeans(); else cout 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions