Hi, in this code i am trying to call the function "issueTicket" from class "ticket", in the the function "reserveCabin" in another class called "cruise".

Also, i think it is the same problem, i am trying to call function "calTicket" from class "booking", in the function "issueTicket" from class "ticket". im not exactly sure how to go about this, i have looked at ways of doing so. the best example i came across is in this thread:
http://www.daniweb.com/forums/thread261407.html
the error says:
"in member function 'void cruise::reserveCabin()':"
"aggregate 'ticket tik1' has incomplete type and cannot be defined"

for all the parameters it has this error:

"expected primary-expression before" and then the name of the parameters

it has the same error message for the second function i wish to call.

the errors are on the lines: 266,267, and 299, jst to save u the time of looking through the code.

#include<iostream>
#include<fstream>
#include<string>
//#include"booking.h"

using namespace std;

class cruise 
{
      private:
              char cabin[52][3][13][4];
              int num, Rb, Rw, Ri;
              char res,templ,tempc,tempr;
      public:
             int cru, lvl, row, col;
             friend class ticket;
             friend class booking;             
 
void cruise::readInformation()
{
ifstream indata;
indata.open("littleswandb.txt");
if(!indata)
{
   cout << "File could not be opened" << endl;
   system("pause");
   return;
}
for(int a=0;a<52;a++)
{
   for(int l=0;l<3;l++)
   {
      for(int r=0;r<13;r++)
      {
         for(int c=0;c<4;c++)
         {
            indata >> cabin[a][l][r][c];             
         }                  
      }
   }
}
indata.close();
}

void cruise::writeInformation()
{
ofstream outdata("littleswandb.txt");
for(int b=0; b<52; b++)
{              
   for(int x=0; x<3; x++)//Levels
   {
      for(int y=0; y<13; y++)//Rows
      {
         for(int z=0; z<4; z++)//Columns
         {                
            outdata << cabin[b][x][y][z];
         }
      }
   }
}
system("pause");
outdata.close();
}

void cruise::showAvailability()
{
   Rb=0;
   Rw=0;
   Ri=0;
   cru=0;
   while((cru<1)||(cru>52))
   {
      cout << "What is the cruise number of the cabins you wish to see? 1-52" << endl;
      cin >> cru;
   }
   cout << "-----Cabin Distribution-----" << endl << endl;
   cru = cru-1;
      for(int l=0;l<3;l++)
      {
         for(int r=0;r<13;r++)
         {
            for(int c=0;c<4;c++)
            {
               if((r<6) && (c==0)||(c==3))
               {
                  if(cabin[cru][l][r][c]=='X')
                     Rb++; 
               }
               else if((r>5) && (c==0)||(c==3))
               {
                  if(cabin[cru][l][r][c]=='X')
                     Rw++;
               }
               else if((c==1)||(c==2))
               {
                  if(cabin[cru][l][r][c]=='X')
                     Ri++;
               }
               else
                  cout << "Error";
               cout << cabin[cru][l][r][c];
            }
         cout << endl;
         }
      cout << endl;
      }
      cru= cru+1;
      cout << "-----Availability-----" << endl << endl;
      cout << "Total Number of Cabins: 156" << endl;
      cout << "Total Reserved: " << Rb + Rw + Ri << endl;
      cout << "Total Free: " << (156 -( Rb + Rw + Ri)) << endl << endl;
      cout << "Balcony Cabins: 30" << endl;
      cout << "Reserved Balcony: " << Rb << endl;
      cout << "Free Balcony: " << 30 - Rb << endl << endl;
      cout << "Window Cabins:" << 48 << endl;
      cout << "Reserved Window: " << Rw << endl;
      cout << "Free Window: " << 48 - Rw << endl << endl;
      cout << "Inside Cabins: 78" << endl;
      cout << "Reserved Inside: " << Ri << endl;
      cout << "Free inside: " << 78 - Ri << endl;
      writeAvailability();
}
void cruise::writeAvailability()
{
     ofstream outava("Availability.txt");
     Rb=0;
     Rw=0;
     Ri=0;
     for(int a=0;a<52;a++)
     {
        for(int b=0;b<3;b++)
        {
           for(int c=0;c<13;c++)
           {
              for(int d=0;d<4;d++)
              {
                  if((c<6) && (d==0)||(d==3))
               {
                  if(cabin[a][b][c][d]=='X')
                     Rb++; 
               }
                  else if((c>5) && (d==0)||(d==3))
               {
                  if(cabin[a][b][c][d]=='X')
                     Rw++;
               }
               else if((d==1)||(d==2))
               {
                  if(cabin[a][b][c][d]=='X')
                     Ri++;
               }
              }
           }
        }
      outava << "-----Availability-----" << endl;
      outava << "Cruise number: " << a+1 << endl;
      outava << "Total Number of Cabins: 156" << endl;
      outava << "Total Reserved: " << Rb + Rw + Ri << endl;
      outava << "Total Free: " << (156 -( Rb + Rw + Ri)) << endl << endl;
      outava << "Balcony Cabins: 30" << endl;
      outava << "Reserved Balcony: " << Rb << endl;
      outava << "Free Balcony: " << 30 - Rb << endl << endl;
      outava << "Window Cabins:" << 48 << endl;
      outava << "Reserved Window: " << Rw << endl;
      outava << "Free Window: " << 48 - Rw << endl << endl;
      outava << "Inside Cabins: 78" << endl;
      outava << "Reserved Inside: " << Ri << endl;
      outava << "Free inside: " << 78 - Ri << endl;
      outava << endl << endl;
     Rb=0;
     Rw=0;
     Ri=0;
     }
outava.close();              

}
void reserveCabin()
{
     string name;
     string ctype;
     int numpass;
     numpass=0;
      cout << "Would you like to make a reservation? Y/N" << endl;
      cin >> res;
      while ((res == 'Y') || (res == 'y'))
      {
          cout << "What is your name?" << endl;
          cin >> name;
          cout << endl;
          while((numpass>4)||(numpass<1))
          {
             cout << "How many passengers? 1-4" << endl;
             cin >> numpass;
             cout << endl;
             if((numpass>4)||(numpass<1))
                cout << "Number of passengers must be between 1 and 4" << endl;
          }
          
          while((cru>52)||(cru<1))
          {
             cout << "Which cruise whould you like to reserve? 1-52" << endl;
             cin >> cru;
             cout << endl;
             if((cru>52)||(cru<1))
                cout << "Cruise must be between 1 and 52" << endl;
          }
          while((lvl>3)||(lvl<1))//repeat until user has input a level between 1-3
          {
             cout << "Which Level Would you like to reserve? 1-3" << endl;
             cin >> lvl;
             cout << endl;
             if((lvl>3)||(lvl<1))//if user input a number not between 1-3
                cout << "Level must be between 1 and 3, or you did not enter a number" << endl;
          }
          while((row>13)||(row<1))
          {
             cout << "Which Row Would you like to reserve? 1-13" << endl;
             cin >> row;
             cout << endl;
             if((row>12)||(row<1))
                cout << "Row must be between 1 and 13" << endl;
          }
          while((col>4)||(col<1))
          {
             cout << "Which Column Would you like to reserve? 1-4" << endl;
             cin >> col;
             cout << endl;
             if((col>4)||(col<1))
                cout << "Column must be between 1 and 4" << endl;
          }

          lvl = lvl -1; //Minus 1 for array
          row = row -1; //Minus 1 for array
          col = col -1; //Minus 1 for array
          cru = cru -1; //Minus 1 for array

          if (cabin[cru][lvl][row][col] != 'X')
          {
             cabin[cru][lvl][row][col] = 'X';
             //cout << cabin[cru][lvl][row][col] << endl;
             lvl = lvl + 1; //Plus 1 after array use
             row = row + 1; //Plus 1 after array use
             col = col + 1; //Plus 1 after array use
             cru = cru + 1; //Plus 1 after array use
             cout << "You have booked the Cabin on Level: " << lvl
                  << " Row: " << row
                  << " Colunm: " << col << endl;
             
             if((row<6) && (col==1)||(col==4))
               {
                    cout <<"Row less then 6, col =1 or col 4" << endl;
                    ctype = "Balcony"; 
               }
                  else if((row>5) && (col==1)||(col==4))
               {
                    cout <<"Row greater then 6, col =1 or col 4" << endl;                       
                    ctype = "Window";
               }
               else if((col==2)||(col==3))
               {
                    cout <<"col = 2 or col = 3" << endl;
                    ctype = "Inside";
               }

             writeInformation();
             ticket tik1;
             tik1.issueTicket(string name, int cru, int lvl, int row, int col, string cabtype, int passno);
          }  
       else
           cout << "That cabin is already booked" << endl;
           cout << "Would you like to try another cabin? Y/N" << endl;
           cin >> res;
           cout << endl;
           cru=0;
           lvl=0;
           col=0;
           row=0;
      }                
}
};//class cruise ends

class ticket
{
      private:
              int cruNo, level, row, col;
              string cabtype;
              string cusname;
              int passno;
              float total;
              friend class booking;
              friend class cruise;
      public:  
                  
void issueTicket(string name, int cru, int lvl, int row, int col, string cabtype, int passno)
{
     float cost;
     booking book1;
     cost = book1.calTicket(passno,cabtype);
   cout << "-----Issue Ticket-----" << endl;
     cout << "Name: " << name << endl;
     cout << "Cruise Number: " << cru << endl;
     cout << "Level: " << lvl << endl 
          << "Row  " << row  << endl
          << "Column: " << col << endl;
     cout << "Cabin Type: " << cabtype << endl;
     cout << "Number of Passengers: " << passno << endl;
     cout << "Cost: " << cost << endl;
     
   ofstream ticket("ticket.txt");
     ticket << "-----Ticket-----" << endl;
     ticket << "Name: " << name << endl;
     ticket << "Cruise Number: " << cru << endl;
     ticket << "Level: " << lvl << endl 
            << "Row:  " << row  << endl
            << "Column: " << col << endl; 
     ticket << "Cabin Type: " << cabtype << endl;
     ticket << "Number of Passengers: " << passno << endl;    
     ticket << "Cost: " << cost << endl;                 
   ticket.close();
}
};//class ticket ends

class booking
{
      public:
       
float calTicket(int numpass, string ctype)
{
     float total;
     float multi;
     total = 0.0;
     multi = 1.0;
     cout << "Cal Ticket" << endl;
     if(numpass == 2)
        multi = 0.6;
     else if(numpass == 3)
        multi = 0.5;
     else if(numpass == 4)
        multi = 0.4;
     else
        cout << "Multi error" << endl;
     
     if(ctype == "Balcony")
     {                   
                total = 2500*2*multi*numpass;
     }
     else if(ctype == "Window")
     {
                total = 2500*1.6*multi*numpass;
     }
     else if(ctype == "Inside")
     {
                total = 2500*multi*numpass;
     }  
    return total;          
}
};//class booking ends

A couple of things: first, you are mixing your class definition and method implementations together. You need to separate these into a header file for the class definition, and a code file for the method implementations. A short example (using your "booking" class):

New booking.h file:

#include <string>
using namespace std;
class booking
{
public:
booking(); /* constructor */
float calTicket(int numpass, string ctype);
};

New booking.cpp file:

#include "booking.h"

float booking::calTicket(int numpass, string ctype)
{
// Stuff the method is supposed to do...
}

Once you have that all separated, you should be a lot better off (code will be much more readable, too). Also, you don't need the "Friend" declarations. In your code, you just need to include the proper header, then just declare an instance of the class you want to use.

i have done as u have said, and i am getting one error now:
[Linker Error] undefined reference to 'ticker::issueTicket(std::string, int, int, int, int, std::string, int)'
id returned 1 exit status

when i comment out this line my program runs:

tik1.issueTicket(name, cru, lvl, row, col, ctype, numpass);

i dont know wat else you will need to solve this problem, as i havnt came across it before

If you can send the reorganized .cpp and .h files maybe we can help easier.

i jst got it working although, the class definition and class functions are in the same file, this is the way it worked 4 me. thanks to mcriscolo for your help

how did you manage to fix it?

i'm trying to do a similar program and came across the same error.

also, i was using :
void cruise::readInformation()
{
ifstream indata;
indata.open("cabinDistribution.txt");
if(!indata)
{
cout << "File could not be opened" << endl;
system("pause");
return;
}

for(int cabinLevel=0;cabinLevel<3;cabinLevel++)
{
for(int roomNumber= 0;roomNumber<13;roomNumber++)
{
for(int c=cabinColumn;cabinColumn<4;cabinColumn++)
{
indata >> rooms[cabinLevel][cabinColumn][roomNumber];
}
}
}

to write out instead. but this doesn't seem to work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.