I'm a Cpp newbie and I have a question that i can't find an answer to it. So Im writing this program about Tourist sights using a class. Inside i have name of the sight, addres and distance from the city center. All i've done is the input and output. Now i have no idea how to sort them with InsertionSort. Do I need another array? I want to sort them by distance but have no idea how to write it.
Here is what i have
#include <iostream>
#include <string>
using namespace std;
class Tobekt {
private: string name;
string addres;
int distance;
public:
void input(void);
void output(void);
};
void Tobekt::input(){
cout<<"Landmark name: ";
getline(cin, name);
getline(cin, addres);
cout<<"Addres: ";
getline(cin, addres);
cout<<"Distance from the city center: ";
cin>>distance;
}
void Tobekt::output(){
cout<<endl;
cout<<"Landmark name: "<<name<<endl;
cout<<"Addres: "<<addres<<endl;
cout<<"Distance from the city center: "<<distance<<endl;
}
int main()
{
int n;
cout<<"Tourist landmarks:" ;
cin>>n;
Tobekt *A = new Tobekt[n];
for(int i=0; i<n; i++)
{
A[i].input();
}
for(int i=0; i<n; i++)
{
A[i].output();
}
return 0;
}