Step 3: Refactor your sort function as a member function of a Class Template that has a data store. Your Class Template must have member functions to add data, display data, and sort data. Your data store can consist of an array of fixed length using an index (such as top in a Stack Implementation). Other data store implementations are acceptable. Step 4: Test your Class Template using at least two template objects with at least 5 data elements for each object. Menu-driven implementation (i.e. using design patterns from Assignments 1 & 2 for example) are also acceptable. A simple main implementation would be as follows: int main ()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need help  solving this c++ problem as I need to create a sorting class template of the programming base on the instruction of the assignment. In short-term how I can solve this coding problem and creating Menu-driven implementation.

### Step 3: Refactor Your Sort Function

Refactor your sort function as a member function of a Class Template that has a data store. Your Class Template must have member functions to add data, display data, and sort data. Your data store can consist of an array of fixed length using an index (such as top in a Stack Implementation). Other data store implementations are acceptable.

### Step 4: Test Your Class Template

Test your Class Template using at least two template objects with at least 5 data elements for each object. Menu-driven implementation (i.e., using design patterns from Assignments 1 & 2, for example) are also acceptable. A simple main implementation would be as follows:

```cpp
int main() 
{
    Stack<double> numbers;
    numbers.push(212);
    numbers.push(315);
    numbers.push(175);
    numbers.push(258);
    numbers.push(110);
    numbers.display();
    numbers.sort();
    numbers.display();

    Stack<string> names;
    names.push("Frodo");
    names.push("Eowyn");
    names.push("Sauron");
    names.push("Bilbo");
    names.push("Galadriel");
    names.display();
    names.sort();
    names.display();

    return 0;
}
```

This example demonstrates testing with both numeric (double) and string data types using the `Stack` template.
Transcribed Image Text:### Step 3: Refactor Your Sort Function Refactor your sort function as a member function of a Class Template that has a data store. Your Class Template must have member functions to add data, display data, and sort data. Your data store can consist of an array of fixed length using an index (such as top in a Stack Implementation). Other data store implementations are acceptable. ### Step 4: Test Your Class Template Test your Class Template using at least two template objects with at least 5 data elements for each object. Menu-driven implementation (i.e., using design patterns from Assignments 1 & 2, for example) are also acceptable. A simple main implementation would be as follows: ```cpp int main() { Stack<double> numbers; numbers.push(212); numbers.push(315); numbers.push(175); numbers.push(258); numbers.push(110); numbers.display(); numbers.sort(); numbers.display(); Stack<string> names; names.push("Frodo"); names.push("Eowyn"); names.push("Sauron"); names.push("Bilbo"); names.push("Galadriel"); names.display(); names.sort(); names.display(); return 0; } ``` This example demonstrates testing with both numeric (double) and string data types using the `Stack` template.
**Assignment 6 – Sorting with Class Templates**

**CSIS 123A – Duffie (f2020)**

---

**Executive Summary:** For Assignment 6, implement a sort algorithm as part of a Class Template. Test your Class Template in the main function by inputting, sorting, and displaying data of at least two types (one string, and one numeric). Insertion sort was covered in class and can be used for this assignment. Candidate sort algorithms for this assignment also include Selection Sort, Merge Sort, and Quick Sort. Extra credit consideration will be given for implementations that use alternate or multiple sort algorithms (other than insertion), or implementations that read data from a file (implementations that read from a file do not need an addItem or push method).

---

**Implementation Notes:**

**Step 1:** It is suggested that you start by implementing a sort algorithm as a simple program in main(). Try to understand how the algorithm works, and take some time to consider how the code would need to change in order to accommodate other primitive types (i.e., double, string, etc.), as well as a variable number of items.

```cpp
// Insertion Sort
int main()
{
    int values[] = { 10,50,40,30,20,60,70,90,100,80 };

    int hold = 0;
    int search = 0;
    for (int current = 1; current < 10; current++)
    {
        hold = values[current];
        for (search = current - 1; search >= 0 && hold < values[search]; search--)
            values[search + 1] = values[search];
        values[search + 1] = hold;
    }

    for (int x = 0; x < 10; x++)
        cout << values[x] << endl;

    return 0;
}
```

**Step 2:** Implement and test your sort routine as a simple function. Consider implementing as a Function Template as a stepping-stone to implementing a Class Template.
Transcribed Image Text:**Assignment 6 – Sorting with Class Templates** **CSIS 123A – Duffie (f2020)** --- **Executive Summary:** For Assignment 6, implement a sort algorithm as part of a Class Template. Test your Class Template in the main function by inputting, sorting, and displaying data of at least two types (one string, and one numeric). Insertion sort was covered in class and can be used for this assignment. Candidate sort algorithms for this assignment also include Selection Sort, Merge Sort, and Quick Sort. Extra credit consideration will be given for implementations that use alternate or multiple sort algorithms (other than insertion), or implementations that read data from a file (implementations that read from a file do not need an addItem or push method). --- **Implementation Notes:** **Step 1:** It is suggested that you start by implementing a sort algorithm as a simple program in main(). Try to understand how the algorithm works, and take some time to consider how the code would need to change in order to accommodate other primitive types (i.e., double, string, etc.), as well as a variable number of items. ```cpp // Insertion Sort int main() { int values[] = { 10,50,40,30,20,60,70,90,100,80 }; int hold = 0; int search = 0; for (int current = 1; current < 10; current++) { hold = values[current]; for (search = current - 1; search >= 0 && hold < values[search]; search--) values[search + 1] = values[search]; values[search + 1] = hold; } for (int x = 0; x < 10; x++) cout << values[x] << endl; return 0; } ``` **Step 2:** Implement and test your sort routine as a simple function. Consider implementing as a Function Template as a stepping-stone to implementing a Class Template.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education