(Each undeclared identifier is reported only once for each function it appears in.)

hey everyone, i have a problem compiling this program and i cant see what the problem is. basically i want to resize an array if it gets to its maximum size but it wont let me because of the error mentioned as the title :( can anyone help? here is the code, the error is in the resizeArray() function:


#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;

class Person
{
public:
Person();
double price;
void deletePassenger();
void addPassenger(Person &passenger);
void printPassenger(Person passenger);
double costOfFlight(string location1, string class1);
Person resizeArray(Person passengers[], int size);
private:
string forename;
string surname;
string passportNum;
string contactNum;
string email;
string location;
string flightNumber;
string passengerClass;

};

Person passenger;

Person::Person()
{}

Person Person::resizeArray(Person passengers[], int size)
{
Person newPassengersData[passengers.size()*2] = new Person();
for (int k = 0; k < size; k++)
{
newPassengersData[k] = passengers[k];
}
delete passengers;
return newPassengersData;
}

double Person::costOfFlight(string location1, string class1)
{

if (class1.compare("E") == 0 || class1.compare("e") == 0)
passenger.price = rand() % 200;
if (location1.compare("Europe") == 0)
{
return passenger.price = passenger.price + 100 + (rand() % 100);
}
else if (location1.compare("North_Africa") == 0)
{
return passenger.price = passenger.price + 250 + (rand() % 150);
}
else if (location1.compare("South_Africa") == 0)
{
return passenger.price = passenger.price + 350 + (rand() % 200);
}
else if (location1.compare("Asia") == 0)
{
return passenger.price = passenger.price + 600 + (rand() % 500);
}
else if (location1.compare("North_America") == 0)
{
return passenger.price = passenger.price + 700 + (rand() % 500);
}
else if (location1.compare("South_America") == 0)
{
return passenger.price = passenger.price + 700 + (rand() % 550);
}
else
{
return passenger.price = passenger.price + 500 + (rand() % 400);
}
}


void Person::addPassenger(Person &passenger)
{
cout << "Enter Passenger Name: ";
cin >> passenger.forename;
cin >> passenger.surname;
cout << endl;
cout << "Passenger phone number: ";
cin >> passenger.contactNum;
cout << endl;
cout << "E-mail address: ";
cin >> passenger.email;
cout << endl;
cout << "Enter Passport Number: ";
cin >> passenger.passportNum;
cout << endl;
cout << "Enter destination: ";
cin >> passenger.location;
cout << endl;
cout << "Passenger flight number: ";
cin >> passenger.flightNumber;
cout << endl;
cout << "Passenger class: ";
cin >> passenger.passengerClass;
cout << endl;
cout << "Total price (including VAT): ";
cout << costOfFlight(passenger.location, passenger.passengerClass) << endl;
}

void Person::deletePassenger()
{
delete &passenger.forename;
delete &passenger.surname;
delete &passenger.passportNum;
delete &passenger.email;
delete &passenger.contactNum;
delete &passenger.location;
delete &passenger.flightNumber;
delete &passenger.passengerClass;
delete &passenger.price;
}

void Person::printPassenger(Person passenger)
{
cout << "Name: \t\t\t\t" << passenger.surname << ", " << passenger.forename << endl;
cout << "Passenger phone number: \t" << passenger.contactNum << endl;
cout << "E-mail address: \t\t" << passenger.email << endl;
cout << "Enter Passport Number: \t\t" << passenger.passportNum << endl;
cout << "Enter destination: \t\t" << passenger.location << endl;
cout << "Passenger flight number: \t" << passenger.flightNumber << endl;
cout << "Passenger class: \t\t" << passenger.passengerClass << endl;
cout << "Total price (including VAT): \t" << passenger.price << endl;
}

int main()
{
string repeat;
string answer;
string name;
int i = 0;
int j;
int size = 1000;
Person passengerDatabase[size];
do
{
cout << "Enter the number to execute the following: \n"
<< "- Press 0 to add a Passenger\n"
<< "- Press 1 to see all Passengers\n"
<< "- Press 2 to delete most recent Passenger\n"
<< "- Press 3 to exit program\n\n"
<< "Number: ";
cin >> j;
switch (j)
{
case 0:
system("cls");
passengerDatabase[i].addPassenger(passenger);
passengerDatabase[i] = passenger;
if (i = size - 1)
{
passenger.resizeArray(passengerDatabase, i);
}
i++;
break;
case 1:
system("cls");
for (int j = 0; j < i; j++)
passengerDatabase[j].printPassenger(passengerDatabase[j]);
break;
case 2:
cout << "Are you sure you want to delete the last person added? (Y/n)";
cin >> answer;
if (answer.compare("N") != 0 || answer.compare("n") != 0)
{

passengerDatabase[i - 1].deletePassenger();
passengerDatabase[i - 2] = passenger;
i--;
cout <<"\nThe most recent person added has been deleted\n";
}
cout << endl;
break;
case 3:
exit(1);
break;
case 4:
system("cls");
cout << "Please Enter the passenger you wish to cancel: ";
cin >> name;
cout << endl;
//cancelPassenger(name, passengerDatabase);
break;
default:
cout << "Please enter an appropriate value!";
}
cout << "Would you like to repeat previous options? (Y/n)";
cin >> repeat;
if (repeat.compare("n") != 1 || repeat.compare("N") != 1)
{
exit(1);
}
cout << endl;
system("cls");
}

while(repeat.compare("n") != 0 || repeat.compare("N") != 0);
return 0;
}


array's can be created with constant's only. so you can't do something like:

int i = 100;
char arr[i];

if you want a dynamically changing array, use pointer's or STL template container's for ease.
Hint: read up on vectors and get rid of arrays! The older and wiser programmers will scoff at this, but for newbies like us, vectors are a gift from heaven. They can do everything an array does and much more.
thanks im using arrays now but have a problem adding elements to it, like an out of bounds error, heres the link if anyone can help :/

http://www.cplusplus.com/forum/beginner/41917/

again thanks for all the help :)
Topic archived. No new replies allowed.