Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please I need help with Workshop 10 https://github.com/Seneca-244200/OOP-Workshops/tree/main/WS10 Look at the code provided in the Collection template module, study it and understand it. The Collection

Please I need help with Workshop 10

https://github.com/Seneca-244200/OOP-Workshops/tree/main/WS10

Look at the code provided in the Collection template module, study it and understand it. The Collection class is a template that works like a dynamic array of objects and resizes itself as objects are added to it. The code snippet below demonstrates how Collection works:

Collection Cdbl; Cdbl.add(1.23); Cdbl.add(2.34); Cdbl.add(3.45); cout << "There are " << Cdbl.size() << " items in the Collection!" << endl; for(int i=0; i< Cdbl.size();i++){ cout << Cdbl[i] << endl; }

Output:

There are 3 items in the Collection! 1.23 2.34 3.45 

Supplied Modules:

  • Collection
  • ReadWrite
  • Employee
  • Student
  • Car

Do not modify these modules! Look at the code and make sure you understand them.

Modules that you will modify (The searchNlist module and the main module)searchNlist module

Implement this module in 'searchNlist.h' header file.

  • "check": to check a value in a compound type array against a given key is a specific index
  • "search": to search through a compound type array (using the check function before) and insert the matches found into a Collection of the same compound type.
  • "listArrayElements": to list elements of an array with a title
  • "sizeCheck": to compare the sizes of two collections of the same compound type.

check function template

Create a function template called check to check a value in a compound type array against a given key in a specific index

  • An array of templated objects; the same type as the Collection type. (template type 1)
  • An integer variable that represents the index to use in the comparison
  • A key templated value to search for, in the array of objects. (template type 2)

The check function is rather simple and will return true or false based on the following condition:

  • if the element at index i of the array equals the key or not Use the "==" operator to check for a match between the objects and the key. This operator is overloaded in each testing class used.

search function template

Create a function template called search that accepts four arguments in any order you prefer:

  • An array of templated objects; the same type as the Collection type. (template type 1)
  • An integer represents the number of elements in the array of objects
  • A key templated value to search for, in the array of objects. (template type 2)
  • A reference to a Collection of templated objects (template type 1). The Collection is defined in Collection.h

The search function template returns a bool that is true only if at least one match to the key is found in the array of objects and false otherwise. The search function goes through all the elements of the array of objects and adds all the matches found to the Collection. You are required to use the check function created above for a match between the object at a specific location and the key

listArrayElements function template

Lists all the elements of an array.

Create a function template called listArrayElements that accepts three arguments in any order you prefer:

  • A const char* for a Title to be printed as the Title of the list.
  • A constant array of templated objects (template type)
  • The number of the elements of the array.

This function first prints the Title and then goes to newline.

Then it will print the row number and then insert each element of the array into cout with a newline attached.

For example, if this function is called for the following array of integers.

int a[]{10,20,30,40};

using the Title value of "INTEGERS" and the number of elements as 4, the output would be like the following.

INTEGERS 1: 10 2: 20 3: 30 4: 40 

sizeCheck function template

Create a function template called sizeCheck that accepts two arguments in any order you prefer:

  • A reference to a Collection of templated objects representing collection 1. The Collection is defined in Collection.h
  • A reference to a Collection of templated objects representing collection 2. The Collection is defined in Collection.h

This function simply compares the sizes of the two collections and return true if the size of the first collection is larger and false otherwise.

Template type requirements

Have a comment section for each function and explain what requirements each type of your templates must have to be able to work with your logic. Then also copy these comments to the part 2 reflection of the workshop.

The main module

In this workshop you are modifying the main module. Make sure to update the comments at the top to reflect your work on the module

Modify the main module and call the search function at the condition of the five if statements in the source code.

See the comments in main.cpp on where to use this function

Modify the main module and call the sizeCheck function at the condition of the specified if statement in the source code.

See the comments in main.cpp on where to use this function

Also, call the listArrayElement function four times before the first three if statements and at the end of the main() function to list the elements of the integer array a.

See the comments in main.cpp on where to use this function

// Workshop 10: // Version: 2.0 // Date: 2021-11-18 // Author: Fardad Soleimanloo // // Description: // This file tests the lab section of your workshop // Modify the main function as stated in the workshop description ///////////////////////////////////////////// #include #include "Car.h" #include "Employee.h" #include "ReadWrite.h" #include "Student.h" #include "Collection.h" #include "searchNlist.h" using namespace std; using namespace sdds; int main() { Car C[7] = { Car("GVFGHI", "Tesla Model S"), Car("ABCDEF", "BMW 320"), Car("CDEFGH", "Ford Festiva"), Car("BCDEFG", "Ford Festiva"),Car("GVDGHI", "Tesla Model 3"), Car("EFGHIJ", "Nissan Maxima"), Car("GVDEFG", "Tesla Model X") }; Student S[6] = { Student(23456, "Lisa Simpson",4.0),Student(45678, "Ralph Wiggum",2.1), Student(56789, "Milhouse Van Houten",4.0), Student(67890, "Todd Flanders", 3.5), Student(34567, "Nelson Muntz",3.0),Student(12345, "Bart Simpson",1.5) }; Employee E[6] = { Employee(213456, "Carl Carlson", 62344.56,111), Employee(122345, "Mindy Simmons", 65432.44,222), Employee(435678, "Lenny Leonard", 43213.22,111), Employee(546789, "Waylon Smithers", 654321.55,333), Employee(657890, "Frank Grimes", 34567.88,333), Employee(364567, "Homer Simpson", 55432.11,111) }; //these collections will hold the results of the searches Collection Cres1; Collection Cres2; Collection Sres; CollectionEres; // Call the listArrayElements to list all cars in the array C, Title: "All the cars:", size is 7 listArrayElements(......................); cout << "Searching for Tesla cars: " << endl; // Call the search function to search the array C // and store the matches in Cres1 passing "a" as the key argument if (search(......................)) { cout << Cres1.size() << " match" << (Cres1.size() == 1 ? "" : "es") << " found:" << endl; for (int i = 0; i < Cres1.size(); i++) { cout << (i + 1) << ": " << Cres1[i] << endl; } } else { cout << "No matches found!" << endl; } cout << endl; // Call the search function to search the array C // and store the matches in Cres2 passing "b" as the key argument if (search(......................)) { cout << Cres2.size() << " match" << (Cres2.size() == 1 ? "" : "es") << " found:" << endl; for (int i = 0; i < Cres1.size(); i++) { cout << (i + 1) << ": " << Cres1[i] << endl; } } else { cout << "No matches found!" << endl; } cout << endl; //call the function sizeCheck and pass the resulted collections from the previous two searches // print "Collection 1 got more results!!", "Collection 2 got more results!!" or "equal results" if (sizeCheck(......................)) cout << "Collection 1 got more results!!" << endl; else cout << "Collection 1 got less than or equal collection 2 results!!" << endl; cout << endl; // Call the listArrayElements to list all the students, Title: "All students:" listArrayElements(......................); cout << "Searching for students with 4.0 Gpa:" << endl; // Call the search function to search the array S // and store the matches in Sres passing 4.0 as the key argument if (search(......................)) { cout << Sres.size() << " match" << (Sres.size() == 1 ? "" : "es") << " found:" << endl; for (int i = 0; i < Sres.size(); i++) { cout << (i + 1) << ": " << Sres[i] << endl; } } else { cout << "No matches found!" << endl; } cout << endl; // Call the listArrayElements to list all the employees, Title: "All employees:" listArrayElements(......................); cout << "Searching for employees who share office number 111:" << endl; // Call the search function to search the array E // and store the matches in Eres passing 111 as the key argument if (search(......................)) { cout << Eres.size() << " match" << (Eres.size() == 1 ? "" : "es") << " found:" << endl; for (int i = 0; i < Eres.size(); i++) { cout << (i + 1) << ": " << Eres[i] << endl; } } else { cout << "No matches found!" << endl; } cout << endl; cout << "Searching for employees who share office number 555:" << endl; // Call the search function to search the array E // and store the matches in Eres passing 555 as the key argument if (search(......................)) { cout << Eres.size() << " match" << (Eres.size() == 1 ? "" : "es") << " found:" << endl; for (int i = 0; i < Eres.size(); i++) { cout << (i + 1) << ": " << Eres[i] << endl; } } else { cout << "No matches found!" << endl; } cout << endl; int a[]{ 10,20,30,40,50,60 }; // Call the listArrayElements to list all the integers in the array a // Title: "INTEGERS" listArrayElements(......................); return 0; }

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions