Printing several arrays by calling 1 array!

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

30 Replies - 1093 Views - Last Post: 02 October 2012 - 09:03 PM Rate Topic: -----

#16 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,391
  • Joined: 25-December 09

Re: Printing several arrays by calling 1 array!

Posted 30 September 2012 - 02:47 PM

Here is your code posted into code tags:
#include <iostream>
#include <iomanip>
#include <string>
 
using namespace std;
/////////////////////////////Struct Levels/////////////////////////////////////
struct FlightType{ 
        string id; //array id
        CarrierType aCarrier; //error line1,2 & 3
};
 
struct CarrierType{
        string carrier; //array carrier
        int capacity; //array capacity
        string destination; //array destination
        TimeType aTime; //erro line 3,5 & 6
}; 
 
struct TimeType{
        CarrierType aCarrier;
        string departure; //array departure
        string arrival; //array arrival
        //int date; //current date or machine date to compare to departure or arrival
};
///////////////////////////////Global Variable///////////////////////////////////////////////
//Global variable for datatype struct array
//#1 priority error I want a global variable to determine the element number of the struct array FlightType. Notice the difference between plural & single. Plural is global & single is the local
FlightsType Flights[] = FlightType[1000]; //error, This line simply creates a global variable to use the array of structs. Problem is global variable is not detected its an error!
int Flightno = 0;  //global counter
//////////////////////////////////Display Menu////////////////////////////////////////////
void DislayMenu(){
        cout<<"---------------------------------------------------------"<<endl;
        cout<<"Flight Management System (CSC301, Fall2012)"<<endl;
        cout<<"---------------------------------------------------------"<<endl;
        cout<<"1- Create a new flight"<<endl;
        cout<<"2- Delete a flight"<<endl;
        cout<<"3- List all flights"<<endl;
        cout<<"4- Check if a flight exists based on its ID"<<endl;
        cout<<"0- Quit"<<endl;
        cout<<"---------------------------------------------------------"<<endl;
}
 
int UserMenuChoice(){
        int choice = 1000;
        while(choice > 4) {
                cout<<"Your choice (0, 1, 2, 3, 4)?";
                cin>>choice;
        }
        return choice;
}
//////////////////////////////Create Flight/////////////////////////////////////////////////
//This simply adds values to the array so when this is executed flightno will be incremented noting that this is ticket 1.
void CreateFlight(FlightsType Flights){//error
        cout<<"=================================================================";
        cout<<"==                          NEW  FLIGHT                        ==";
        cout<<"=================================================================";
        FlightType aFlight;
        cout<< setw(20)<<"ID: "; 
        cin>>aFlight.id;
        cout<<setw(20)<<"Capacity: ";
        cin>>aFlight.aCarrier.capacity;
        cout<<setw(20)<<"Destination: ";        
        cin>>aFlight.aCarrier.destination;
        cout<<setw(20)<<"Departure: ";  
        cin>>aFlight.aCarrier.aTime.departure;
        cout<<setw(20)<<"Arrival: ";    
        cin>>aFlight.aCarrier.aTime.arrival;
        Flights[Flightno] = aFlight;
        Flightno++;
}
 
///////////////////////////////////Delete Flight///////////////////////////////////////////////////
//This function lets the user input the id of the flight then it will determine the location then it will delete entire flights data with similar location like destination, arrival etc
//Its like a ticket if a Flight has been canceled then entire ticket is useless so the time & destination are canceled as well so this simply deletes the entire ticket.
void DeleteFlight(/*FlightsType[] aFlight*/){
        FlightsType[] aFlight;  //error, I tried to put it up in the brackets or down here it still doesn't work because it did not understand the global variable.
        //node that FlightType is different from FlighsType. The plural is the global the single is the local.
        string id;
        cin>>id;
        bool found = false;
        int location=0
        for (; (location<aaFlight.length) && (!found); location++) //error problem with for loop
                if (id == (aFlight[location].id)) found = true;
        if (found) {
                aFlight[location] = aFlight[length - 1];//error since it did not detect global
                length--;
        }
}
 
/////////////////////////////////////List Flight///////////////////////////////////////////////////////////
//This lists all flights by calling the print function until the end of the array which is determined by flightno. Flightno is similar to int size, it is merely used as a counter.
void ListFlights(FlightsType Flights[], Flightno){//error,  global var still not detected
        cout<<"=================================================================";
        cout<<"==                         FLIGHT  LIST                        ==";
        cout<<"=================================================================";
        cout<<"please select available flights destination:";
        for (int i=0;i< Flightno; i++){
        PrintFlightData(Flights[i]);/////error, This should print all students but this doesn't work since it did not detect global var.
        }
}
void PrintFlightData()//print fuction is fine
{
        FlightType aFlight;
        cout <<"__________________________________________________________" << endl;
        cout << setw(25)<< "ID #: " << aFlight.id <<endl;
        cout << setw(25)<< "Capacity: " << aFlight.aCarrier.capacity <<"Destination: "<< aFlight.aCarrier.destination<<endl;
        cout << setw(25)<< "School and Major: "<<aFlight.aCarrier.aTime.departure << "Age: " << aFlight.aCarrier.aTime.arrival <<endl;
        cout << "__________________________________________________________" << endl;
}
 
////////////////////////////////Search Flight/////////////////////////////////////////////////////////
//this simply searches the function by id so if I type the id the print function will execute once & it will only print the ticket that has the same id.
void SearchFlight(){
                cout<<"=================================================================";
                cout<<"==                          CHECK  FLIGHT                      ==";
                cout<<"=================================================================";
                cout<<"please type ID of flight to check if it exists:";
                FlightType aFlight;
                bool moreToSearch;
                int location=0;
                bool found;
                found = false;
                int id;
                cin>>id;
                moreToSearch = (location < length);//error, I want it to search for every element within the array until the last location which is determined by the length. I have no idea.
                while (moreToSearch && !found)  {
                        if (id == aFlight[location].id) { //error
                        found = true; 
                        PrintFlightData(aFlight[location].id) //errorI did try aFlight.id[location] but my friend said its incorrect! since id is not an array but the whole struct is an array.
                } else {
                        location++;
                        moreToSearch = (location<length);//error btw I have no idea how to decide the length I tried length only I tried aFlight.length did not work 
                }
        }
}
//////////////////////main/////////////////////////////////////////
int main(int argc, char* argv[])
{
        int userChoice;
        do {
                system("cls");
                DislayMenu();
                userChoice = UserMenuChoice();
                switch (userChoice) {
                        case 1: 
                                CreateFlight(); 
                                break;
                        case 2: 
                                DeleteFlight(); 
                                break;
                        case 3: 
                                ListFlights(); 
                                break;
                        case 4: 
                                SearchFlight(); 
                                break;
                        default:  cout<<"Thanks for using CSC301's Flight Managenment System. Good Bye.";
                }
        }while (userChoice != 0);
        return 0;
}
 
 


And the error messages you show:

Quote

prog.cpp:9: error: ‘CarrierType’ does not name a type
prog.cpp:16: error: ‘TimeType’ does not name a type
prog.cpp:28: error: ‘FlightsType’ does not name a type
prog.cpp:53: error: variable or field ‘CreateFlight’ declared void
prog.cpp:53: error: ‘FlightsType’ was not declared in this scope
prog.cpp: In function ‘void DeleteFlight()’:
prog.cpp:76: error: ‘FlightsType’ was not declared in this scope
prog.cpp:76: error: expected primary-expression before ‘]’ token
prog.cpp:76: error: expected `;' before ‘aFlight’
prog.cpp:82: error: expected ‘,’ or ‘;’ before ‘for’
prog.cpp:82: error: ‘aaFlight’ was not declared in this scope
prog.cpp:82: error: expected `;' before ‘)’ token
prog.cpp:85: error: ‘aFlight’ was not declared in this scope
prog.cpp:85: error: ‘length’ was not declared in this scope
prog.cpp: At global scope:
prog.cpp:92: error: variable or field ‘ListFlights’ declared void
prog.cpp:92: error: ‘FlightsType’ was not declared in this scope


The first error is referring to line 9. What line does the CarrierType definition begin? Remember the compiler must know what this type is before you can use it.

It also appears that you have a circular dependency issue. You will need to rethink your class definitions.


Jim

This post has been edited by jimblumberg: 30 September 2012 - 02:50 PM

Was This Post Helpful? 0
  • +
  • -

#17 busta5000  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: -7
  • View blog
  • Posts: 147
  • Joined: 08-March 08

Re: Printing several arrays by calling 1 array!

Posted 30 September 2012 - 03:06 PM

I actually didn't face this problem when I used it in a lower hierarchy
I used to type the code in this order:
/////////////////////////////Struct Levels/////////////////////////////////////
struct FlightType{ 
        string id; //array id
};
 
struct CarrierType{
        string carrier; 
        int capacity;
        string destination;
        FlightType aFlight;
};
 
struct TimeType{
        CarrierType aCarrier;
        string departure
        string arrival[;
       
};


I did not have any problems with this order but then I thought about it & I also asked few who suggested the order of hierarchy is illogical. The order should be from the top to bottom. The father(FlightType) has 1 child(CarrierType) which also has a child(TimeType). So this is what I did. This error occurs I think because I cannot type CarrierType without defining it as a struct before. I did define it but after that line. well If I flip the order I think it will work!
* Ok this problem has been removed I think I was right.
/////////////////////////////Struct Levels/////////////////////////////////////
struct TimeType{
	string departure; //array departure
	string arrival; //array arrival
	//int date; //current date or machine date to compare to departure or arrival
};
struct CarrierType{
	string carrier; //array carrier
	int capacity; //array capacity
	string destination; //array destination
	TimeType aTime; //erro line 3,5 & 6
}; 

struct FlightType{ 
	string id; //array id
	CarrierType aCarrier; //error line1,2 & 3


This post has been edited by busta5000: 30 September 2012 - 03:10 PM
Reason for edit:: Removed unnecessary quote

Was This Post Helpful? 0
  • +
  • -

#18 busta5000  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: -7
  • View blog
  • Posts: 147
  • Joined: 08-March 08

Re: Printing several arrays by calling 1 array!

Posted 30 September 2012 - 03:16 PM

The global variable is the current problem

FlightsType Flights[] = FlightType[1000];

Error Log for this line

Quote

Error 1 error C2146: syntax error : missing ';' before identifier 'Flights' d:\courses\csc301\csc301_assig1\csc301_assig1\assig1\assig1.cpp 27 1 Assig1
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\courses\csc301\csc301_assig1\csc301_assig1\assig1\assig1.cpp 27 1 Assig1
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\courses\csc301\csc301_assig1\csc301_assig1\assig1\assig1.cpp 27 1 Assig1
Error 4 error C2275: 'FlightType' : illegal use of this type as an expression d:\courses\csc301\csc301_assig1\csc301_assig1\assig1\assig1.cpp 27 1 Assig1

This post has been edited by busta5000: 30 September 2012 - 03:18 PM

Was This Post Helpful? 0
  • +
  • -

#19 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,391
  • Joined: 25-December 09

Re: Printing several arrays by calling 1 array!

Posted 30 September 2012 - 03:18 PM

Look at the difference between your first set of structures and your second set. In your first set of structures you don't have a CarrierType in your FlightType. By placing the CarrierType in both FlightType and TimeType you have created a circular dependency. CarrierType requires a TimeType and TimeType requires a CarrierType. You need to eliminate one of these from one of these classes. Does TimeType actually need to know anything about a CarrierType?

Jim
Was This Post Helpful? 0
  • +
  • -

#20 busta5000  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: -7
  • View blog
  • Posts: 147
  • Joined: 08-March 08

Re: Printing several arrays by calling 1 array!

Posted 30 September 2012 - 03:29 PM

View Postjimblumberg, on 30 September 2012 - 03:18 PM, said:

Look at the difference between your first set of structures and your second set. In your first set of structures you don't have a CarrierType in your FlightType. By placing the CarrierType in both FlightType and TimeType you have created a circular dependency. CarrierType requires a TimeType and TimeType requires a CarrierType. You need to eliminate one of these from one of these classes. Does TimeType actually need to know anything about a CarrierType?

Jim

a requirment for this code is to have a 3 level nested structs that inherit no circular dependency should accure though.

FlightType -> CarrierType -> TimeType
I do not think my latest fix has a circular dependency its simply just following a straight line.
/////////////////////////////Struct Levels/////////////////////////////////////

struct TimeType{//Has no child
	string departure;
	string arrival;
	//int date; 
};
struct CarrierType{ //is 1 child called TimeType
	string carrier;
	int capacity; 
	string destination;
	TimeType aTime; 
}; 

struct FlightType{ //Father has 1 child called CarrierType
	string id; 
	CarrierType aCarrier;
};

Was This Post Helpful? 0
  • +
  • -

#21 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,391
  • Joined: 25-December 09

Re: Printing several arrays by calling 1 array!

Posted 30 September 2012 - 03:41 PM

That looks better as far as the circular dependency issue. But you don't have any inheritance. See this link for information on inheritance.

Jim
Was This Post Helpful? 0
  • +
  • -

#22 busta5000  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: -7
  • View blog
  • Posts: 147
  • Joined: 08-March 08

Re: Printing several arrays by calling 1 array!

Posted 30 September 2012 - 03:45 PM

View Postjimblumberg, on 30 September 2012 - 03:41 PM, said:

That looks better as far as the circular dependency issue. But you don't have any inheritance. See this link for information on inheritance.

Jim

I meant inheritance(phrase just to explain) as nested levels not actual inheritance I know what inheritance means sorry for the confusion.

This post has been edited by busta5000: 30 September 2012 - 07:42 PM

Was This Post Helpful? 0
  • +
  • -

#23 busta5000  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: -7
  • View blog
  • Posts: 147
  • Joined: 08-March 08

Re: Printing several arrays by calling 1 array!

Posted 01 October 2012 - 07:08 PM

Ok I fixed my code all by simply relying on myself I am disappointed in a way that nobody even cared to even just point to what I meant by this line
FlightsType Flights[] = FlightType[1000];


I have changed it to
FlightType = allFlights[1000];



Anyways I have fixed everything in the code it works as its instructed. Here is the code for your convenience.

DataType 3 level nested Structures

Quote

FlightType->CarrierType->TimeType

FlightType is the grandfather it only has 1 attribute & has 1 son that is CarrierType.
CarrierType has 2 attributes & it has 1 son that is TimeType.
TimeType has 2 attributes.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
/////////////////////////////Struct Levels/////////////////////////////////////
struct TimeType{
        string departure;
        string arrival;
};
struct CarrierType{
        int capacity;
        string destination;
        TimeType aTime;
        
}; 
 
struct FlightType{
        string id;
        CarrierType aCarrier;
};



Global Variable
This creates aFlight which is part how we retrieve id & other children but we cannot type it in the structure since it will create a circular dependency level since its the grandfather.
allFlights is used to declare array size. If you look at Create Flight function at the end there is a line where it associates allFlights with aFlight.
FlightNo is a counter it is used to find the location of the array
///////////////////////////////Global Variable///////////////////////////////////////////////
 
FlightType allFlights[20], aFlight;
int FlightNo = 0;



This is simply the menu display to choose the functions

//////////////////////////////////Display Menu////////////////////////////////////////////
void DislayMenu(){
        cout<<"---------------------------------------------------------"<<endl;
        cout<<"Flight Management System"<<endl;
        cout<<"---------------------------------------------------------"<<endl;
        cout<<"1- Create a new flight"<<endl;
        cout<<"2- Delete a flight"<<endl;
        cout<<"3- List all flights"<<endl;
        cout<<"4- Check if a flight exists based on its ID"<<endl;
        cout<<"0- Quit"<<endl;
        cout<<"---------------------------------------------------------"<<endl;
        
        cout<<"---------------------------------------------------------"<<endl;
}
 
int UserMenuChoice(){
        int choice = 1000;
        while(choice > 4) {
                cout<<"Your choice (0, 1, 2, 3, 4)?";
                cin>>choice;
        }
        return choice;
}



Create Function
If you look at the code you will see that in order to cin the ticket you need to type all the parents of that datatype
aFlight.aCarrier.aTime.arrival IF you look at the 3 level nested structured datatype you will realize that arrival is the son of CarrierType & FlightType is his grandfather. So this will know its location in the array but the most essential part is the one before the last allFlights[FlightNo]=aFlight this will notify that when creating the cins that it is part of an array & that its location is FlightNo which is a counter that is used to find the location that is incremented everytime you execute this function.
//////////////////////////////Create Flight/////////////////////////////////////////////////
void CreateFlight(){
        system("cls");
        cout<<"=================================================================\n";
        cout<<"==                          NEW  FLIGHT                        ==\n";
        cout<<"=================================================================\n";
        cout<< setw(20)<<"\nID: "; 
        cin>>aFlight.id;
        cout<<setw(20)<<"\nCapacity: ";
        cin>>aFlight.aCarrier.capacity;
        cout<<setw(20)<<"\nDestination: ";      
        cin>>aFlight.aCarrier.destination;
        cout<<setw(20)<<"\nDeparture: ";        
        cin>>aFlight.aCarrier.aTime.departure;
        cout<<setw(20)<<"\nArrival: ";  
        cin>>aFlight.aCarrier.aTime.arrival;
        allFlights[FlightNo]=aFlight;
        FlightNo++;
}



Delete Function
This function deletes the flight by id. It tries to compare all the array of allFlights[].id with the cin if it finds the location it will delete the entire ticket.
To further explain delete look at the Create FLight function you will see that at the end of the line is FlightNo++.
Flight number is merely a counter for the ticket so when you create your first flight with id, destination, etc... You will be creating all these attributes that are part of an array allFlights. So you have created 1 ticket, when you try to view or print FlightNo it will associate it as the length of the array. So when you want to delete an entire ticket this is the proper way to do it by using the counter as the length.
///////////////////////////////////Delete Flight///////////////////////////////////////////////////
void DeleteFlight(){
        system("cls");
                cout<<"=================================================================\n";
                cout<<"==                          Delete  FLIGHT                     ==\n";
                cout<<"=================================================================\n";
        string x;
        cout<<"ID of flight:";
        cin>>x;
        bool found = false;
        int location=0;
        for (; (location<FlightNo) && (!found); location++)
        if (x == (allFlights[location].id)) found = true;
        if (found) {
                allFlights[location] = allFlights[FlightNo - 1];
                FlightNo--;
        }
}



List Function
The list function simply views all flights that are saved.
This function has also the print function but it simply loops the print function depending on the array length.
Its better if you create a local variable for the PrintFlightData like pFlight.
/////////////////////////////////////List Flight///////////////////////////////////////////////////////////
void ListFlights(){
        system("cls");
        cout<<"=================================================================\n";
        cout<<"==                         FLIGHT  LIST                        ==\n";
        cout<<"=================================================================\n";
        if (FlightNo == 0) {cout<<"No flights";
                system("pause");}
        else {
                for (int loc=0;loc < FlightNo; loc++){
                        cout << setw(25)<< "\nID #: " << allFlights[loc].id;
                        cout << setw(25)<< "\nCapacity: " << allFlights[loc].aCarrier.capacity<<"\nDestination: "<< allFlights[loc].aCarrier.destination;
                        cout << setw(25)<< "\nDeparture: "<<allFlights[loc].aCarrier.aTime.departure << "\nArrival: " << allFlights[loc].aCarrier.aTime.arrival;
                        cout << "\n__________________________________________________________" << endl;
        }
        system("pause");}
}
void PrintFlightData(FlightType pFlight)
{
        cout <<"__________________________________________________________" << endl;
        cout << setw(25)<< "\nID #: " << pFlight.id;
        cout << setw(25)<< "\nCapacity: " << pFlight.aCarrier.capacity <<"\nDestination: "<< pFlight.aCarrier.destination;
        cout << setw(25)<< "\nDeparture: "<<pFlight.aCarrier.aTime.departure << "\nArrival: " << pFlight.aCarrier.aTime.arrival;
        cout << "\n__________________________________________________________" << endl;
}



SEARCH FUNCTION
The Search function searches a flight by id so if you type the id it will provide the ticket of that flight.
////////////////////////////////Search Flight/////////////////////////////////////////////////////////
void SearchFlight(){
        system("cls");
                cout<<"=================================================================\n";
                cout<<"==                          CHECK  FLIGHT                      ==\n";
                cout<<"=================================================================\n";
                cout<<"please type flight ID:";
                bool moreToSearch;
                int location=0;
                bool found;
                found = false;
                string x;
                cin>>x;
        
                moreToSearch = (location < FlightNo);
                while (moreToSearch && !found)  {
                        if (x == allFlights[location].id) {
                                cout<<x;
                        found = true; 
                        PrintFlightData(allFlights[location]);
                }
                        else {
                        location++;
                        moreToSearch = (location<FlightNo);
                        }
                        
                }
                if (!found) cout<< "No flight with that ID";
                system("pause");
}



//////////////////////main/////////////////////////////////////////
int main(int argc, char* argv[])
{
        int userChoice;
        do {
                system("cls");
                DislayMenu();
                userChoice = UserMenuChoice();
                switch (userChoice) {
                        case 1: 
                                CreateFlight(); 
                                break;
                        case 2: 
                                DeleteFlight(); 
                                break;
                        case 3: 
                                ListFlights(); 
                                break;
                        case 4: 
                                SearchFlight(); 
                                break;
                        default:  cout<<"Thanks for using CSC301's Flight Managenment System. Good Bye.";
                }
        }while (userChoice != 0);
        return 0;
}


Was This Post Helpful? 0
  • +
  • -

#24 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,391
  • Joined: 25-December 09

Re: Printing several arrays by calling 1 array!

Posted 01 October 2012 - 08:19 PM

View Postbusta5000, on 01 October 2012 - 09:08 PM, said:

[size="3"]Ok I fixed my code all by simply relying on myself I am disappointed in a way that nobody even cared to even just point to what I meant by this line
FlightsType Flights[] = FlightType[1000];


I have changed it to
FlightType = allFlights[1000];



And exactly what do you think that change is doing? FlightType is a type of variable, you can't assign a value to a type.

You need to post the entire code if you really want not just snippets. You also need to ask specific questions about the code posted.

Jim
Was This Post Helpful? 0
  • +
  • -

#25 busta5000  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: -7
  • View blog
  • Posts: 147
  • Joined: 08-March 08

Re: Printing several arrays by calling 1 array!

Posted 01 October 2012 - 08:59 PM

What do you mean!!!!! I actually said it look at post #18

View Postbusta5000, on 30 September 2012 - 03:16 PM, said:

The global variable is the current problem

FlightsType Flights[] = FlightType[1000];

Error Log for this line

Quote

Error 1 error C2146: syntax error : missing ';' before identifier 'Flights' d:\courses\csc301\csc301_assig1\csc301_assig1\assig1\assig1.cpp 27 1 Assig1
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\courses\csc301\csc301_assig1\csc301_assig1\assig1\assig1.cpp 27 1 Assig1
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\courses\csc301\csc301_assig1\csc301_assig1\assig1\assig1.cpp 27 1 Assig1
Error 4 error C2275: 'FlightType' : illegal use of this type as an expression d:\courses\csc301\csc301_assig1\csc301_assig1\assig1\assig1.cpp 27 1 Assig1


View Postjimblumberg, on 01 October 2012 - 08:19 PM, said:

And exactly what do you think that change is doing? FlightType is a type of variable, you can't assign a value to a type.

You need to post the entire code if you really want not just snippets. You also need to ask specific questions about the code posted.

Jim

Was This Post Helpful? -1
  • +
  • -

#26 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,391
  • Joined: 25-December 09

Re: Printing several arrays by calling 1 array!

Posted 02 October 2012 - 12:45 AM

This is what I mean, you only supply snippets of your code, this is not always enough to tell what the error messages are talking about. When you get error messages you need to post the complete error messages, all of them, and the complete code that generated these messages. These error messages must be worked on from the top down. One error may be causing multiple errors.

And again you didn't answer the question from my last post.
Look at the following code!
FlightType = allFlights[1000];

Now please answer the question!

Quote

And exactly what do you think that change is doing?


That above statement is still wrong!

Jim
Was This Post Helpful? 0
  • +
  • -

#27 busta5000  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: -7
  • View blog
  • Posts: 147
  • Joined: 08-March 08

Re: Printing several arrays by calling 1 array!

Posted 02 October 2012 - 01:14 AM

View Postjimblumberg, on 02 October 2012 - 12:45 AM, said:

This is what I mean, you only supply snippets of your code, this is not always enough to tell what the error messages are talking about. When you get error messages you need to post the complete error messages, all of them, and the complete code that generated these messages. These error messages must be worked on from the top down. One error may be causing multiple errors.

And again you didn't answer the question from my last post.
Look at the following code!
FlightType = allFlights[1000];

Now please answer the question!

Quote

And exactly what do you think that change is doing?


That above statement is still wrong!

Jim


You didn't have to give me a -1! anyways The thing is you always change your mind! I wrote the entire code but I split then in order. So the first snippit of my earlier posts in page 2 has level struct & the global variable. The thing is you didn't look at the first error nor asked about the first code snippet other than the structure of nests.
I made the simple snipppet because you ignored that part!

The difference between
FlightsType Flights[] = FlightType[1000]/*Notice Flights[] Data type of struct that already exist*/;


and
FlightType = allFlights[1000];/*new array but it will be implemented for aFlights in CreateFlight();*/


Is that the first format is incorrect format & it generates an syntex error asking ; before [].

This post has been edited by busta5000: 02 October 2012 - 01:17 AM

Was This Post Helpful? 0
  • +
  • -

#28 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,391
  • Joined: 25-December 09

Re: Printing several arrays by calling 1 array!

Posted 02 October 2012 - 06:19 AM

FlightType = allFlights[1000];/*new array but it will be implemented for aFlights in CreateFlight();*/

You can not assign something to a type. FlightType is a structure, or more commonly called a User Defined Type.

Since you insist that your program is correct this will be my last post on this topic.

Jim
Was This Post Helpful? 1
  • +
  • -

#29 busta5000  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: -7
  • View blog
  • Posts: 147
  • Joined: 08-March 08

Re: Printing several arrays by calling 1 array!

Posted 02 October 2012 - 08:08 PM

View Postjimblumberg, on 02 October 2012 - 06:19 AM, said:

FlightType = allFlights[1000];/*new array but it will be implemented for aFlights in CreateFlight();*/

You can not assign something to a type. FlightType is a structure, or more commonly called a User Defined Type.

Since you insist that your program is correct this will be my last post on this topic.

Jim



I hope for for this last post I write for this subject. In order to know its correct you need to run it. I already have tested the code:

Quote

1.CreateFlight: [ID:QR123 Destination:FR Arrival:1400 Destination:1600] FlightNo=1
1.CreateFlight: [ID:QR435 Destination:IT Arrival:1600 Destination:1800] FlightNo=2

3.ListFlights:
ID:QR123
Destination:FR
Arrival:1400
Destination:1600
____________________
ID:QR435
Destination:IT
Arrival:1600
Destination:1800
_______________________________

3.DeleFlight:
Please Type ID:QR123

_______________________________

2.ListFlights:

ID:QR435
Destination:IT
Arrival:1600
Destination:1800
_______________________________

I hope this shows you that the code exactly how I want it deletes the array by searching of id & finding the length that is FlightNo. It deletes the entire ticket or details within aFlight structs & his children.
That is what I wanted I hope you see that the code is working.

I can actually give you screenshots or even you can run the code to see if it works or not but I have tested it my instructor thought my code is great it achieved what he wanted.

This post has been edited by Skydiver: 02 October 2012 - 08:17 PM
Reason for edit:: Fixed quote.

Was This Post Helpful? 0
  • +
  • -

#30 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3548
  • View blog
  • Posts: 10,989
  • Joined: 05-May 12

Re: Printing several arrays by calling 1 array!

Posted 02 October 2012 - 08:19 PM

Okay, now try entering 3 flights, and delete the first flight. See what happens when you list your flights after the delete.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3