I hope you understand the code so that I do not need spent most of the time explaining codes I already know.
The problem is simple I want an array to call upon other arrays. I already did a similar function in the getfuncion that has the reference to question label. astudents.id is an example of an array of astudents calling id which is inside the datatype studenttype. Problem is if I want for example to type the id of the function cin>>id; I want it to print or cout all data of data of student like age, major, health, fname, lastname etc.

Re: Printing several arrays by calling 1 array!

Perhaps code organisation is what is holding you back in the real code.

Snoopy.

well thank you for spliting them in files but that does nothing unfortunately. I can organize them but that is not my question nor it could change the result for there are things that headers are restricted to do. Anyways I hope you can help me understand how can I call 1 element from astudent that is id to call upon the rest of the details that are for the same student note that every student has a similar array number so it is easy but I can't figure out how to do it. Reminder I want 1 element that from astudent that is part of the datatype StudentsType that is ID when written in a cin then the output would be the entire array of the student. So if I type the ID the entire data of the student should show I hope I am clear with this my problem is not with organization but with calling out an array to print several arrays fom 1 user.

Re: Printing several arrays by calling 1 array!

Reminder I want 1 element that from astudent that is part of the datatype StudentsType that is ID when written in a cin then the output would be the entire array of the student.

I can see part of the reason for the misunderstanding: incorrect terminology You are using the phrase "entire array of the student" when referring to the the "datatype StudentsType". StudentsType is a struct. I think that your refusal to learn about structs from back in June is still having some lingering echoes. id, firstname, lastname, etc. are called members or member variables.

The second part of the misunderstanding. incorrect concept vs intended code. You said:

Quote

Problem is if I want for example to type the id of the function cin>>id; I want it to print or cout all data of data of student like age, major, health, fname, lastname etc.

cin >> ... is meant to input data, yet you are asking to print out the data. Perhaps you meant to say cout << id ?

Now on to the core problem. There is no easy, sane way to do what you want. Or at least no way to do it and not have your others who read your code, go WTF?!?!? and post your code on thedailywtf.com.

Think for a moment. Given the code:

cin >> id;

How will the compiler magically know that in this case when you are using cin >>, you actually want the code to print out instead of output data?

So let's move on and assume that you actually wrote:

cout << id;

How will the compiler magically know that id is a member of StudentsType struct, and furthermore, also know that it should use the allStudents array? What's supposed to happen if you happened to have:

Re: Printing several arrays by calling 1 array!

Reminder I want 1 element that from astudent that is part of the datatype StudentsType that is ID when written in a cin then the output would be the entire array of the student.

I can see part of the reason for the misunderstanding: incorrect terminology You are using the phrase "entire array of the student" when referring to the the "datatype StudentsType". StudentsType is a struct. I think that your refusal to learn about structs from back in June is still having some lingering echoes. id, firstname, lastname, etc. are called members or member variables.

The second part of the misunderstanding. incorrect concept vs intended code. You said:

Quote

Problem is if I want for example to type the id of the function cin>>id; I want it to print or cout all data of data of student like age, major, health, fname, lastname etc.

cin >> ... is meant to input data, yet you are asking to print out the data. Perhaps you meant to say cout << id ?

Now on to the core problem. There is no easy, sane way to do what you want. Or at least no way to do it and not have your others who read your code, go WTF?!?!? and post your code on thedailywtf.com.

Think for a moment. Given the code:

cin >> id;

How will the compiler magically know that in this case when you are using cin >>, you actually want the code to print out instead of output data?

So let's move on and assume that you actually wrote:

cout << id;

How will the compiler magically know that id is a member of StudentsType struct, and furthermore, also know that it should use the allStudents array? What's supposed to happen if you happened to have:

Definitely code that is worthy of being posted in that website, because why would you jump through all those hoops just to be able to lazily write code that looks like cout << name;;

Sorry for being misunderstood. For the previous post I was supposed to do the project using class only struct was not allowed for the project, I thought I made myself clear last time. This is another project I must only use struct this time. Lets focus on this topic look I apologies again for not being clear. what I meant by cin>>id; is that if you type the id an if statment will compare all id's that have been typed within the execution of the code. So for example this is a method that I assume will work. note that this is part of the entire code so do not ask where did I define the integer or type within this code sample.

Re: Printing several arrays by calling 1 array!

Posted 22 September 2012 - 10:26 AM

Ah! That makes more sense.

Using your array, you can't avoid looping to do the matching. Either you'll have to do the loop to search yourself, or you can use the Standard C++ Library to do the loop for you if you use std::find_if(): http://www.cplusplus...orithm/find_if/

Now on the other hand, if you used std::map<>, you could do something like:

Re: Printing several arrays by calling 1 array!

Posted 22 September 2012 - 10:41 AM

Skydiver, on 22 September 2012 - 10:26 AM, said:

Ah! That makes more sense.

Using your array, you can't avoid looping to do the matching. Either you'll have to do the loop to search yourself, or you can use the Standard C++ Library to do the loop for you if you use std::find_if(): http://www.cplusplus...orithm/find_if/

Now on the other hand, if you used std::map<>, you could do something like:

Re: Printing several arrays by calling 1 array!

Posted 22 September 2012 - 10:51 AM

Yes, the functional effect is the same: you find an item. The implementation is different. The map is implemented as a tree behind the scenes and offers better search performance, than doing a linear search through an array using find_if().

If you used binary_search() you could get the same performance as the map<>, but you'll have to take time to sort your array, as well as jump through some hoops to get the search value and comparator written correctly. http://www.cplusplus.../binary_search/

Given a choice, I'd go with the find_if() as long as the array stays less than 100 elements.

Re: Printing several arrays by calling 1 array!

Posted 29 September 2012 - 06:18 AM

Hey its me again this is the actual code I'm working on which is similar to the previous code.
Objective:
* Have 3 level nested structs.
* Provide a simple c++ application that manages flights it should have the capability to add, delete, search & list flights.
*Beside the errors that I have I want you to confirm the functionality and correctness of my code as well please.

Delete Flight
This deletes a flight by typing the id it checks the array of id then it deletes every other thing related to the same array location.
In order to understand its simple the flight ticket is determined by id so the flight id is unique for every array so it will delete the other arrays that have the same location.

ERROR LOG
BTW ignore the C2059 error regarding the ]. I recently added this error by adding [] just in case I know its wrong but ignore that the [] is there in the error locations. I just wanted to add an array with the size of 50 so I know that in cin>>id[]; should be correct in a way.

Re: Printing several arrays by calling 1 array!

Posted 29 September 2012 - 07:13 AM

Since you are using templates, both the definition and the implementation must be in the same compilation unit, usually in the same file. Where are the implementation for your template class? Many template classes are implemented completely in the header file.

Quote

BTW ignore the C2059 error regarding the ]. I recently added this error by adding [] just in case I know its wrong but ignore that the [] is there in the error locations.

Sorry but you need to fix these errors and then post the new error messages. Many times fixing one error will fix multiple error messages.

Re: Printing several arrays by calling 1 array!

Posted 30 September 2012 - 12:59 PM

Sorry I always seem to change the code but I refused to use gentype since I felt it was unnececery & I could use the functions directly in-staid in deleting & searching. Problems have faced me that I could not determine hope you can explain
btw I am experimenting with my logic of understanding so there are things in which I do not know what to do like how to do a global variable for an datatype struct array. Also I do not know how to type the length of an open array that the size has not been determined.

//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

///////////////////////////////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]; //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

//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.

///////////////////////////////////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; //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++) //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--;
}
}

//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.

//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.

////////////////////////////////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);//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) //I 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
}
}
}

Re: Printing several arrays by calling 1 array!

First you need to post the code that generated these warnings/errors. There are no templates in the code you provided in your last post.

Next what does this mean?

Quote

Sorry I always seem to change the code but I refused to use gentype since I felt it was unnececery

What is gentype?? If gentype is some kind of source format tool then it is indeed necessary. Proper indentation helps in many ways. For one with a proper indented source file it is much easier to spot missing or misplaced braces ({}). And it makes following the logic of the program much easier.

Next your snippets don't reflect as to what file contains them. Your error messages are useless if you don't provide the full code so we can see where the error occurs, the messages do tell this.

For example in your code you posted please point out the line this error is talking about:

Re: Printing several arrays by calling 1 array!

Posted 30 September 2012 - 01:46 PM

Hey this is the new error log I do not think there is a gentype error in the new error log.
Gentype: Generic type that is part of unsortedlist that has a list of functions like delete, retrieve etc.
I have deleted them because I think its more difficult to call classes that refer to struct datatypes.
I actually explained every error in the code as a comment but I did not type the error line number within the code.
The errors are in syncronological order so every error I determine is part of the error I typed in the code as a comment.I will edit the code & type the code number for every line.
There are over 54 errors its hard to write the number try to run the code in a compiler.
* Fixed error log I forgot to clear solution & recompile.

jimblumberg, on 30 September 2012 - 01:27 PM, said:

First you need to post the code that generated these warnings/errors. There are no templates in the code you provided in your last post.

Next what does this mean?

Quote

Sorry I always seem to change the code but I refused to use gentype since I felt it was unnececery

What is gentype?? If gentype is some kind of source format tool then it is indeed necessary. Proper indentation helps in many ways. For one with a proper indented source file it is much easier to spot missing or misplaced braces ({}). And it makes following the logic of the program much easier.

Next your snippets don't reflect as to what file contains them. Your error messages are useless if you don't provide the full code so we can see where the error occurs, the messages do tell this.

For example in your code you posted please point out the line this error is talking about: