fork(1) download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4.  
  5. using namespace std;
  6. /////////////////////////////Struct Levels/////////////////////////////////////
  7. struct FlightType{
  8. string id; //array id
  9. CarrierType aCarrier; //error line1,2 & 3
  10. };
  11.  
  12. struct CarrierType{
  13. string carrier; //array carrier
  14. int capacity; //array capacity
  15. string destination; //array destination
  16. TimeType aTime; //erro line 3,5 & 6
  17. };
  18.  
  19. struct TimeType{
  20. CarrierType aCarrier;
  21. string departure; //array departure
  22. string arrival; //array arrival
  23. //int date; //current date or machine date to compare to departure or arrival
  24. };
  25. ///////////////////////////////Global Variable///////////////////////////////////////////////
  26. //Global variable for datatype struct array
  27. //#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
  28. 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!
  29. int Flightno = 0; //global counter
  30. //////////////////////////////////Display Menu////////////////////////////////////////////
  31. void DislayMenu(){
  32. cout<<"---------------------------------------------------------"<<endl;
  33. cout<<"Flight Management System (CSC301, Fall2012)"<<endl;
  34. cout<<"---------------------------------------------------------"<<endl;
  35. cout<<"1- Create a new flight"<<endl;
  36. cout<<"2- Delete a flight"<<endl;
  37. cout<<"3- List all flights"<<endl;
  38. cout<<"4- Check if a flight exists based on its ID"<<endl;
  39. cout<<"0- Quit"<<endl;
  40. cout<<"---------------------------------------------------------"<<endl;
  41. }
  42.  
  43. int UserMenuChoice(){
  44. int choice = 1000;
  45. while(choice > 4) {
  46. cout<<"Your choice (0, 1, 2, 3, 4)?";
  47. cin>>choice;
  48. }
  49. return choice;
  50. }
  51. //////////////////////////////Create Flight/////////////////////////////////////////////////
  52. //This simply adds values to the array so when this is executed flightno will be incremented noting that this is ticket 1.
  53. void CreateFlight(FlightsType Flights){//error
  54. cout<<"=================================================================";
  55. cout<<"== NEW FLIGHT ==";
  56. cout<<"=================================================================";
  57. FlightType aFlight;
  58. cout<< setw(20)<<"ID: ";
  59. cin>>aFlight.id;
  60. cout<<setw(20)<<"Capacity: ";
  61. cin>>aFlight.aCarrier.capacity;
  62. cout<<setw(20)<<"Destination: ";
  63. cin>>aFlight.aCarrier.destination;
  64. cout<<setw(20)<<"Departure: ";
  65. cin>>aFlight.aCarrier.aTime.departure;
  66. cout<<setw(20)<<"Arrival: ";
  67. cin>>aFlight.aCarrier.aTime.arrival;
  68. Flights[Flightno] = aFlight;
  69. Flightno++;
  70. }
  71.  
  72. ///////////////////////////////////Delete Flight///////////////////////////////////////////////////
  73. //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
  74. //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.
  75. void DeleteFlight(/*FlightsType[] aFlight*/){
  76. 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.
  77. //node that FlightType is different from FlighsType. The plural is the global the single is the local.
  78. string id;
  79. cin>>id;
  80. bool found = false;
  81. int location=0
  82. for (; (location<aaFlight.length) && (!found); location++) //error problem with for loop
  83. if (id == (aFlight[location].id)) found = true;
  84. if (found) {
  85. aFlight[location] = aFlight[length - 1];//error since it did not detect global
  86. length--;
  87. }
  88. }
  89.  
  90. /////////////////////////////////////List Flight///////////////////////////////////////////////////////////
  91. //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.
  92. void ListFlights(FlightsType Flights[], Flightno){//error, global var still not detected
  93. cout<<"=================================================================";
  94. cout<<"== FLIGHT LIST ==";
  95. cout<<"=================================================================";
  96. cout<<"please select available flights destination:";
  97. for (int i=0;i< Flightno; i++){
  98. PrintFlightData(Flights[i]);/////error, This should print all students but this doesn't work since it did not detect global var.
  99. }
  100. }
  101. void PrintFlightData()//print fuction is fine
  102. {
  103. FlightType aFlight;
  104. cout <<"__________________________________________________________" << endl;
  105. cout << setw(25)<< "ID #: " << aFlight.id <<endl;
  106. cout << setw(25)<< "Capacity: " << aFlight.aCarrier.capacity <<"Destination: "<< aFlight.aCarrier.destination<<endl;
  107. cout << setw(25)<< "School and Major: "<<aFlight.aCarrier.aTime.departure << "Age: " << aFlight.aCarrier.aTime.arrival <<endl;
  108. cout << "__________________________________________________________" << endl;
  109. }
  110.  
  111. ////////////////////////////////Search Flight/////////////////////////////////////////////////////////
  112. //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.
  113. void SearchFlight(){
  114. cout<<"=================================================================";
  115. cout<<"== CHECK FLIGHT ==";
  116. cout<<"=================================================================";
  117. cout<<"please type ID of flight to check if it exists:";
  118. FlightType aFlight;
  119. bool moreToSearch;
  120. int location=0;
  121. bool found;
  122. found = false;
  123. int id;
  124. cin>>id;
  125. 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.
  126. while (moreToSearch && !found) {
  127. if (id == aFlight[location].id) { //error
  128. found = true;
  129. 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.
  130. } else {
  131. location++;
  132. 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
  133. }
  134. }
  135. }
  136. //////////////////////main/////////////////////////////////////////
  137. int main(int argc, char* argv[])
  138. {
  139. int userChoice;
  140. do {
  141. system("cls");
  142. DislayMenu();
  143. userChoice = UserMenuChoice();
  144. switch (userChoice) {
  145. case 1:
  146. CreateFlight();
  147. break;
  148. case 2:
  149. DeleteFlight();
  150. break;
  151. case 3:
  152. ListFlights();
  153. break;
  154. case 4:
  155. SearchFlight();
  156. break;
  157. default: cout<<"Thanks for using CSC301's Flight Managenment System. Good Bye.";
  158. }
  159. }while (userChoice != 0);
  160. return 0;
  161. }
  162.  
  163.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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
stdout
Standard output is empty