Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;程序在函数调用时停止 我对C++工作新手,所以我很难找到我的错误所在。当我的代码到达调用assignGate时,它停止工作。我尝试了我的程序,删除了行,一切正常。所以问题很可能出在这个函数中,但我看不出它有什么问题 #include "stdafx.h" #include <stdio.h> #include <iostream> #include <string> #include <fstream> using namespace std; struct node { string code; int flight; int time; string gate; node *next; }; bool isEmpty(node *head); void insert(node *&head, node *&last, string code, int flight, int time); void remove(node *&head, node *&last); void assignGate(node *&head, int gates); void print(node *&head); int main() { int gates; bool x = false; string code; int flight, time, gate; node *head = NULL; node *last = NULL; cout << "Welcome to Gate Scheduler.\n"; ifstream file("FlightList.txt"); if (!file) { cout << "Unable to open text file. \n"; cout << "Make sure file is in correct location then restart program. \n"; } while (file >> code >> flight >> time) { insert(head, last, code, flight, time); } cout << "Please enter the max number of gates avaliable:"; cin >> gates; assignGate(head, gates); cout << "\n"; print(head); return 0; } bool isEmpty(node *head) { if (head == NULL) { return true; } else { return false; } } void insert(node *&head, node *&last, string code, int flight, int time) { node *temp = new node; temp->flight = flight; temp->code = code; temp->time = time; temp->next = NULL; if (isEmpty(head)) { head = temp; last = temp; } else { last->next = temp; last = temp; } } void remove(node *&head, node *&last) { if (isEmpty(head)) { cout << "The list is already empty \n"; } else if (head == last) { delete head; head = NULL; last = NULL; } else { node *temp = head; head = head->next; delete temp; } } void assignGate(node *&head, int gates) { int y = 0; int gate[6]; node* temp = head; while (temp->next != NULL) { if (temp->time > 2300 || temp->time < 600) { temp->gate = "N/A: Plane lands outside of airport operating hours."; } else { for (y = 0; y <= gates; ++y) { if (gate[y] == NULL) { temp->gate = y; } else if (gate[y] + 100 < temp->time) { temp->gate = y; } } if (temp->gate != "0" || "1" || "2" || "3" || "4") { temp->gate == "All gate are full at this time"; } } } } void print(node *&head) { node* temp = head; while (temp->next != NULL) { cout << "Flight " << temp->code << " " << temp->flight << " will be at gate " << temp->gate << "\n"; temp = temp->next; } } #包括“stdafx.h” #包括 #包括 #包括 #包括 使用名称空间std; 结构节点{ 字符串代码; 国际航班; 整数时间; 弦门; 节点*下一步; }; 布尔为空(节点*头部); 无效插入(节点*&头部、节点*&最后一个、字符串代码、整数航班、整数时间); 无效删除(节点*&头部、节点*&最后); 无效分配门(节点*&头部,内部门); 无效打印(节点*&头); int main() { 内部门; boolx=假; 字符串代码; 国际航班、时间、登机门; node*head=NULL; node*last=NULL; cout>航班>>时间){ 插入(头、尾、代码、航班、时间); } 门; 分配闸门(头部、闸门); cout flight=飞行; 温度->代码=代码; 温度->时间=时间; temp->next=NULL; 如果(i空(头)){ 压头=温度; 最后=温度; } 否则{ 最后->下一步=温度; 最后=温度; } } 无效删除(节点*&头部、节点*&最后){ 如果(i空(头)){ 下一步; 删除临时文件; } } 无效分配门(节点*&头部,内部门){ int y=0; int门[6]; 节点*温度=头部; while(临时->下一步!=NULL){ 如果(温度->时间>2300 |温度->时间gate=“不适用:飞机在机场运营时间以外降落。”; } 否则{ 对于(y=0;y门=y; } 否则如果(门[y]+100时间){ 温度->闸门=y; } } 如果(临时->闸门!=“0”| |“1”| |“2”| |“3”| |“4”){ 临时->闸门==“此时所有闸门均已满”; } } } } 无效打印(节点*&头){ 节点*温度=头部; while(临时->下一步!=NULL){ cout_C++_Function - Fatal编程技术网 航班>>时间){ 插入(头、尾、代码、航班、时间); } 门; 分配闸门(头部、闸门); cout flight=飞行; 温度->代码=代码; 温度->时间=时间; temp->next=NULL; 如果(i空(头)){ 压头=温度; 最后=温度; } 否则{ 最后->下一步=温度; 最后=温度; } } 无效删除(节点*&头部、节点*&最后){ 如果(i空(头)){ 下一步; 删除临时文件; } } 无效分配门(节点*&头部,内部门){ int y=0; int门[6]; 节点*温度=头部; while(临时->下一步!=NULL){ 如果(温度->时间>2300 |温度->时间gate=“不适用:飞机在机场运营时间以外降落。”; } 否则{ 对于(y=0;y门=y; } 否则如果(门[y]+100时间){ 温度->闸门=y; } } 如果(临时->闸门!=“0”| |“1”| |“2”| |“3”| |“4”){ 临时->闸门==“此时所有闸门均已满”; } } } } 无效打印(节点*&头){ 节点*温度=头部; while(临时->下一步!=NULL){ cout,c++,function,C++,Function" /> 航班>>时间){ 插入(头、尾、代码、航班、时间); } 门; 分配闸门(头部、闸门); cout flight=飞行; 温度->代码=代码; 温度->时间=时间; temp->next=NULL; 如果(i空(头)){ 压头=温度; 最后=温度; } 否则{ 最后->下一步=温度; 最后=温度; } } 无效删除(节点*&头部、节点*&最后){ 如果(i空(头)){ 下一步; 删除临时文件; } } 无效分配门(节点*&头部,内部门){ int y=0; int门[6]; 节点*温度=头部; while(临时->下一步!=NULL){ 如果(温度->时间>2300 |温度->时间gate=“不适用:飞机在机场运营时间以外降落。”; } 否则{ 对于(y=0;y门=y; } 否则如果(门[y]+100时间){ 温度->闸门=y; } } 如果(临时->闸门!=“0”| |“1”| |“2”| |“3”| |“4”){ 临时->闸门==“此时所有闸门均已满”; } } } } 无效打印(节点*&头){ 节点*温度=头部; while(临时->下一步!=NULL){ cout,c++,function,C++,Function" />

C++;程序在函数调用时停止 我对C++工作新手,所以我很难找到我的错误所在。当我的代码到达调用assignGate时,它停止工作。我尝试了我的程序,删除了行,一切正常。所以问题很可能出在这个函数中,但我看不出它有什么问题 #include "stdafx.h" #include <stdio.h> #include <iostream> #include <string> #include <fstream> using namespace std; struct node { string code; int flight; int time; string gate; node *next; }; bool isEmpty(node *head); void insert(node *&head, node *&last, string code, int flight, int time); void remove(node *&head, node *&last); void assignGate(node *&head, int gates); void print(node *&head); int main() { int gates; bool x = false; string code; int flight, time, gate; node *head = NULL; node *last = NULL; cout << "Welcome to Gate Scheduler.\n"; ifstream file("FlightList.txt"); if (!file) { cout << "Unable to open text file. \n"; cout << "Make sure file is in correct location then restart program. \n"; } while (file >> code >> flight >> time) { insert(head, last, code, flight, time); } cout << "Please enter the max number of gates avaliable:"; cin >> gates; assignGate(head, gates); cout << "\n"; print(head); return 0; } bool isEmpty(node *head) { if (head == NULL) { return true; } else { return false; } } void insert(node *&head, node *&last, string code, int flight, int time) { node *temp = new node; temp->flight = flight; temp->code = code; temp->time = time; temp->next = NULL; if (isEmpty(head)) { head = temp; last = temp; } else { last->next = temp; last = temp; } } void remove(node *&head, node *&last) { if (isEmpty(head)) { cout << "The list is already empty \n"; } else if (head == last) { delete head; head = NULL; last = NULL; } else { node *temp = head; head = head->next; delete temp; } } void assignGate(node *&head, int gates) { int y = 0; int gate[6]; node* temp = head; while (temp->next != NULL) { if (temp->time > 2300 || temp->time < 600) { temp->gate = "N/A: Plane lands outside of airport operating hours."; } else { for (y = 0; y <= gates; ++y) { if (gate[y] == NULL) { temp->gate = y; } else if (gate[y] + 100 < temp->time) { temp->gate = y; } } if (temp->gate != "0" || "1" || "2" || "3" || "4") { temp->gate == "All gate are full at this time"; } } } } void print(node *&head) { node* temp = head; while (temp->next != NULL) { cout << "Flight " << temp->code << " " << temp->flight << " will be at gate " << temp->gate << "\n"; temp = temp->next; } } #包括“stdafx.h” #包括 #包括 #包括 #包括 使用名称空间std; 结构节点{ 字符串代码; 国际航班; 整数时间; 弦门; 节点*下一步; }; 布尔为空(节点*头部); 无效插入(节点*&头部、节点*&最后一个、字符串代码、整数航班、整数时间); 无效删除(节点*&头部、节点*&最后); 无效分配门(节点*&头部,内部门); 无效打印(节点*&头); int main() { 内部门; boolx=假; 字符串代码; 国际航班、时间、登机门; node*head=NULL; node*last=NULL; cout>航班>>时间){ 插入(头、尾、代码、航班、时间); } 门; 分配闸门(头部、闸门); cout flight=飞行; 温度->代码=代码; 温度->时间=时间; temp->next=NULL; 如果(i空(头)){ 压头=温度; 最后=温度; } 否则{ 最后->下一步=温度; 最后=温度; } } 无效删除(节点*&头部、节点*&最后){ 如果(i空(头)){ 下一步; 删除临时文件; } } 无效分配门(节点*&头部,内部门){ int y=0; int门[6]; 节点*温度=头部; while(临时->下一步!=NULL){ 如果(温度->时间>2300 |温度->时间gate=“不适用:飞机在机场运营时间以外降落。”; } 否则{ 对于(y=0;y门=y; } 否则如果(门[y]+100时间){ 温度->闸门=y; } } 如果(临时->闸门!=“0”| |“1”| |“2”| |“3”| |“4”){ 临时->闸门==“此时所有闸门均已满”; } } } } 无效打印(节点*&头){ 节点*温度=头部; while(临时->下一步!=NULL){ cout

C++;程序在函数调用时停止 我对C++工作新手,所以我很难找到我的错误所在。当我的代码到达调用assignGate时,它停止工作。我尝试了我的程序,删除了行,一切正常。所以问题很可能出在这个函数中,但我看不出它有什么问题 #include "stdafx.h" #include <stdio.h> #include <iostream> #include <string> #include <fstream> using namespace std; struct node { string code; int flight; int time; string gate; node *next; }; bool isEmpty(node *head); void insert(node *&head, node *&last, string code, int flight, int time); void remove(node *&head, node *&last); void assignGate(node *&head, int gates); void print(node *&head); int main() { int gates; bool x = false; string code; int flight, time, gate; node *head = NULL; node *last = NULL; cout << "Welcome to Gate Scheduler.\n"; ifstream file("FlightList.txt"); if (!file) { cout << "Unable to open text file. \n"; cout << "Make sure file is in correct location then restart program. \n"; } while (file >> code >> flight >> time) { insert(head, last, code, flight, time); } cout << "Please enter the max number of gates avaliable:"; cin >> gates; assignGate(head, gates); cout << "\n"; print(head); return 0; } bool isEmpty(node *head) { if (head == NULL) { return true; } else { return false; } } void insert(node *&head, node *&last, string code, int flight, int time) { node *temp = new node; temp->flight = flight; temp->code = code; temp->time = time; temp->next = NULL; if (isEmpty(head)) { head = temp; last = temp; } else { last->next = temp; last = temp; } } void remove(node *&head, node *&last) { if (isEmpty(head)) { cout << "The list is already empty \n"; } else if (head == last) { delete head; head = NULL; last = NULL; } else { node *temp = head; head = head->next; delete temp; } } void assignGate(node *&head, int gates) { int y = 0; int gate[6]; node* temp = head; while (temp->next != NULL) { if (temp->time > 2300 || temp->time < 600) { temp->gate = "N/A: Plane lands outside of airport operating hours."; } else { for (y = 0; y <= gates; ++y) { if (gate[y] == NULL) { temp->gate = y; } else if (gate[y] + 100 < temp->time) { temp->gate = y; } } if (temp->gate != "0" || "1" || "2" || "3" || "4") { temp->gate == "All gate are full at this time"; } } } } void print(node *&head) { node* temp = head; while (temp->next != NULL) { cout << "Flight " << temp->code << " " << temp->flight << " will be at gate " << temp->gate << "\n"; temp = temp->next; } } #包括“stdafx.h” #包括 #包括 #包括 #包括 使用名称空间std; 结构节点{ 字符串代码; 国际航班; 整数时间; 弦门; 节点*下一步; }; 布尔为空(节点*头部); 无效插入(节点*&头部、节点*&最后一个、字符串代码、整数航班、整数时间); 无效删除(节点*&头部、节点*&最后); 无效分配门(节点*&头部,内部门); 无效打印(节点*&头); int main() { 内部门; boolx=假; 字符串代码; 国际航班、时间、登机门; node*head=NULL; node*last=NULL; cout>航班>>时间){ 插入(头、尾、代码、航班、时间); } 门; 分配闸门(头部、闸门); cout flight=飞行; 温度->代码=代码; 温度->时间=时间; temp->next=NULL; 如果(i空(头)){ 压头=温度; 最后=温度; } 否则{ 最后->下一步=温度; 最后=温度; } } 无效删除(节点*&头部、节点*&最后){ 如果(i空(头)){ 下一步; 删除临时文件; } } 无效分配门(节点*&头部,内部门){ int y=0; int门[6]; 节点*温度=头部; while(临时->下一步!=NULL){ 如果(温度->时间>2300 |温度->时间gate=“不适用:飞机在机场运营时间以外降落。”; } 否则{ 对于(y=0;y门=y; } 否则如果(门[y]+100时间){ 温度->闸门=y; } } 如果(临时->闸门!=“0”| |“1”| |“2”| |“3”| |“4”){ 临时->闸门==“此时所有闸门均已满”; } } } } 无效打印(节点*&头){ 节点*温度=头部; while(临时->下一步!=NULL){ cout,c++,function,C++,Function,首先,您假设数组是零初始化的。它不是。您在gate[]中没有零。您应该对其进行值初始化以使其为零 int gate[6] = {}; 您确实应该检查门是否小于数组的大小 接下来,您的问题在这一部分: else if (gate[y] + 100 < temp->time) { temp->gate = y; } } if (temp->gate != "0" ||

首先,您假设数组是零初始化的。它不是。您在gate[]中没有零。您应该对其进行值初始化以使其为零

 int gate[6] = {};
您确实应该检查门是否小于数组的大小

接下来,您的问题在这一部分:

        else if (gate[y] + 100 < temp->time) {
                temp->gate = y;
            }
        }
        if (temp->gate != "0" || "1" || "2" || "3" || "4") {
            temp->gate == "All gate are full at this time";
'head==NULL'是一个布尔表达式。您可以返回它

inline bool isEmpty(node *head) {
   return head == NULL;
}

有很多错误的东西,代码>分配门< /C>,但是所有的基本C++规则都可以通过一本好书来解决。就像我说的,我是C++编程新手,我的代码在调试时不会出错。所以,如果你能给我指出正确的方向来纠正错误,我会很感激。谢谢!你输入的是什么“GA”?“assignGate”函数中的“tes”参数?如果“文件”包含1行,而您输入的gates值大于1,则“assignGate”将意外退出。“gates”可以是2到5之间的整数,“文件”包含20行
inline bool isEmpty(node *head) {
   return head == NULL;
}