Hello. 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.I've done the input output, but i have some errors that I can't understand.
Can you guys tell me where am I mistaking and how to fix it?
Here is what i have done
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include <iostream>
#include <string>
using namespace std;
class Tobekt {
private: string name;
string addres;
double distance;
int size;
public:
Tobekt_array();
~Tobekt_array();
double GetDistance(void);
void InsertionSort(void);
void input(void);
void output(void);
};
Tobekt::Tobekt_array(){
cout<<"Tourist landmarks:" ;
cin>>size;
Tobekt *A = new Tobekt[size];
}
Tobekt::~Tobekt_array()
{
delete[] A;
}
double Tobekt::GetDistance(){
return distance;
}
void Tobekt::InsertionSort()
{
for (int i = 1; i<size; i++)
{
Tobekt index = A[i];
int dec = i;
while (dec>0 && A[dec - 1].GetDistance() >= index.GetDistance())
{
A[dec] = A[dec - 1];
--dec;
}
}
}
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;
}
|
and here are the errors:
main.cpp:19:16: error: ISO C++ forbids declaration of ‘Tobekt_array’ with no type [-fpermissive]
Tobekt_array();
^
main.cpp:20:16: error: expected class-name before ‘(’ token
~Tobekt_array();
^
main.cpp:26:22: error: ISO C++ forbids declaration of ‘Tobekt_array’ with no type [-fpermissive]
Tobekt::Tobekt_array(){
^
main.cpp:31:22: error: expected class-name before ‘(’ token
Tobekt::~Tobekt_array()
^
main.cpp:31:23: error: definition of implicitly-declared ‘Tobekt::~Tobekt()’
Tobekt::~Tobekt_array()
^
main.cpp: In member function ‘void Tobekt::InsertionSort()’:
main.cpp:44:18: error: ‘A’ was not declared in this scope
Tobekt index = A[i];
^