Help with bubble sort and templates

Hello everyone.

For my project I have to sort 5 numbers and 5 names using a template bubble sort. I have one header for the numbers, and one for the names. This is what I have so far for my testing page:

#include "Floatheader.h"
#include "Nameheader.h"
#include <string>

int main ()


myFloat obj1;
myFloat obj2( 2.2, 5.1);
myFloat obj3( 5.8, 12.3);
myFloat obj4( 14.8, 11.9);
myFloat obj5( 1.9, 0.7);

obj1.setX(5.5 );
obj1.setY(6.4);

myName n1;
myName n2("Kyle", "Schutz");
myName n3("Jessica", "Strama");
myName n4("Cindy", "Couch");
myName n5("Thomas", "Van de Walle");

n1.setF("Kevin");
n1.setL("McShane");

n1.getF();
n1.getL();

cout << n1.getF() << endl << n1.getL() << endl;


cout << "\n";


cout << "Test getX and getY:" << endl;

obj1.getX();
obj1.getY();

cout << obj1.getX() << endl << obj1.getY() << endl;
cout << "Now, create 5 myFloat objects with initial values: " << endl;
cout << "\n" ;
cout << "before sort" << endl;
cout << "obj1 is: " << obj1;
cout << "obj2 is: " << obj2;
cout << "obj3 is: " << obj3;
cout << "obj4 is: " << obj4;
cout << "obj5 is: " << obj5;
cout << "\nafter sort:" << endl;
cout << "\nNow, create 5 myName objects with initial names: " << endl;
cout << n1;
cout << n2;
cout << n3;
cout << n4;
cout << n5;

Now, this is what I have for my main cpp file:

#include "Floatheader.h"
#include "Nameheader.h"
#include <string>

myFloat::myFloat()
{
x = 0; y = 0;

}

myFloat::myFloat(float a, float b)
{
x = a; y = b;
}

void myFloat::setX(float a)
{
x = a;
}

void myFloat::setY(float b)
{
y = b;
}

float myFloat::getX() {return x;}
float myFloat::getY() {return y;}

ostream & operator<< (ostream &print, myFloat obj)
{
print << " x = " << obj.getX() << " y = " << obj.getY() << endl;
return print;
}

bool myFloat::operator>(myFloat m)
{
if ( x > m.x )
return true;
if ( x == m.x || y <= m.y)
return true;
return false;
}



myName::myName()
{


}

myName::myName(string f , string l)
{
fn = f;
ln = l;
}

void myName::setF(string f)
{
fn = f;

}

void myName::setL(string l)
{
ln = l;
}

string myName::getF()
{
return (fn);
}

string myName::getL()
{
return (ln);
}

ostream & operator<< (ostream & create, myName obj)
{
create << "Name is: " << obj.getF() << " " << obj.getL() << endl;
return create;

}

Can someone please help me out? I have to create a template to look like this: template<>....with a class inside the arrows. Then, I have to use bubble sort to sort the 5 names and number objects I have created. Can I please get help with sorting the names and numbers and also using templates? Any help would be greatly appreciated! Thanks so much.
A Bubble Sort would be implemented as a function that operates on an array of numbers in your case.

Write the code that handles doubles, then you can think about abstracting the type from what you've written. Bit so far, I see no array and I see no sort function.
Topic archived. No new replies allowed.