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 ()

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter13: Overloading And Templates
Section: Chapter Questions
Problem 15PE
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 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 ()
{
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;
}
Transcribed Image Text: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 () { 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; }
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 main 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 and 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.
//Insertion Sort
int main ()
{
int values[]
{ 10,50,40,30,20,60,70,90,100,80};
int hold
0;
int search
0;
%3D
for (int current
1; current < 10; current++)
{
hold = values [current];
for (search
current
1; search >= 0 && hold < values [search]; search--)
values [search];
values [search + 1]
hold;
values [search + 1]
}
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 main 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 and 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. //Insertion Sort int main () { int values[] { 10,50,40,30,20,60,70,90,100,80}; int hold 0; int search 0; %3D for (int current 1; current < 10; current++) { hold = values [current]; for (search current 1; search >= 0 && hold < values [search]; search--) values [search]; values [search + 1] hold; values [search + 1] } 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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning