Я пытаюсь прочитать сведения об учениках и учителях с помощью одного связанного списка.компилятор не показывает никаких ошибок на экране.как я могу это исправить ?
я пытаюсь прочитать сведения о студенте и учителе из разных файлов и использую два разных класса как от студента, так и от учителя.Когда я компилирую свою программу, она не показывает никаких ошибок, но я ставлю break в main, а затем запускаю ее. при чтении файла в первом случае в то время как условие точка останова останавливается на
S.create_node(name, course_code, marks, cgpa);
любая идея, как я могу решить эту проблему, так как я очень новичок в этой концепции программирования.
Что я уже пробовал:
#include<iostream> #include<fstream> #include<stdio.h> #include<string> using namespace std; struct Node { string s_name; string s_course_code; int s_marks; float s_cgpa; string t_name; int t_age; int t_Class; string t_subject; Node *next; }; class student { private: Node *head; public: student(); void create_node(string name, string course_code, int marks, float cgpa); void delete_node(int node_no); void display(); void search_name(string name); }; student::student() { head = NULL; } void student::create_node(string name, string course_code, int marks, float cgpa) { int size = 0; Node *temp = new Node; temp->s_name = name; temp->s_course_code = course_code; temp->s_marks = marks; temp->s_cgpa = cgpa; temp->next = NULL; if (!head) { head = temp; } else { Node *t = head; while (t->next != NULL) { t = t->next; } temp = t; t->next = temp; t = t->next; } size++; } void student::delete_node(int node_no) { int counter = 0; // Check if node is exist if (node_no > counter) { cout << "No such node is exist"; } else { Node *temp1; // create a temporary node temp1 = (Node*)malloc(sizeof(Node)); // allocate space for node temp1 = head; // transfer the address of 'head' to 'temp1' Node *old_temp; // create a temporary node old_temp = (Node*)malloc(sizeof(Node)); // allocate space for node old_temp = temp1; // transfer the address of 'temp1' to 'old_temp' // Check node number is 1 if (node_no == 1) { head = temp1->next; // transfer the address of 'temp1->next' to 'head' free(temp1); counter--; cout << node_no << " node of the Linked List is deleted" << endl; } else { // Go to the node number of the node for (int i = 1; i < node_no; i++) { old_temp = temp1; // store previous node temp1 = temp1->next; // store current node } old_temp->next = temp1->next; // transfer the address of 'temp1->next' to 'old_temp->next' free(temp1); counter--; cout << node_no << " node of the Linked List is deleted" << endl; } } } void student::display() { if (!head) { cout << "File is Empty.........................." << endl; } else { Node *t = head; //while(t->next!=NULL) //t=t->next; int count = 1; cout << endl << endl; while (t != NULL) { cout << "[" << count << "]=>" << endl; cout << "\t\tName:" << t->s_name << endl; cout << "\t\tCourse Code:" << t->s_course_code << endl; cout << "\t\tMarks:" << t->s_marks << endl; cout << "\t\tCGPA:" << t->s_cgpa << endl; count++; t = t->next; } } } void student::search_name(string name) { if (!head) { cout << "File is Empty.........................." << endl; } else { Node *t = head; //while(t->next!=NULL) //t=t->next; int count = 1; cout << endl << endl; while (t != NULL) { if (t->s_name == name) { cout << "[" << count << "]=>" << endl; cout << "\t\tName:" << t->s_name << endl; cout << "\t\tCourse Code:" << t->s_course_code << endl; cout << "\t\tMarks:" << t->s_marks << endl; cout << "\t\tCGPA:" << t->s_cgpa << endl; } count++; t = t->next; } } } class teacher { private: Node *head; public: teacher(); void create_node(string name, string subject, int Class, int age); void delete_node(int node_no); void display(); void search_name(string name); }; teacher::teacher() { head = NULL; } void teacher::create_node(string name, string subject, int Class, int age) { int size = 0; Node *temp = new Node; temp->t_name = name; temp->t_subject = subject; temp->t_Class = Class; temp->t_age = age; temp->next = NULL; if (!head) { head = temp; } else { Node *t = head; while (t->next != NULL) { t = t->next; } temp = t; t->next = temp; t = t->next; } size++; } void teacher::delete_node(int node_no) { int counter = 0; // Check if node is exist if (node_no > counter) { cout << "No such node is exist"; } else { Node *temp1; // create a temporary node temp1 = (Node*)malloc(sizeof(Node)); // allocate space for node temp1 = head; // transfer the address of 'head' to 'temp1' Node *old_temp; // create a temporary node old_temp = (Node*)malloc(sizeof(Node)); // allocate space for node old_temp = temp1; // transfer the address of 'temp1' to 'old_temp' // Check node number is 1 if (node_no == 1) { head = temp1->next; // transfer the address of 'temp1->next' to 'head' free(temp1); counter--; cout << node_no << " node of the Linked List is deleted" << endl; } else { // Go to the node number of the node for (int i = 1; i < node_no; i++) { old_temp = temp1; // store previous node temp1 = temp1->next; // store current node } old_temp->next = temp1->next; // transfer the address of 'temp1->next' to 'old_temp->next' free(temp1); counter--; cout << node_no << " node of the Linked List is deleted" << endl; } } } void teacher::display() { if (!head) { cout << "File is Empty.........................." << endl; } else { Node *t = head; //while(t->next!=NULL) //t=t->next; int count = 1; cout << endl << endl; while (t != NULL) { cout << "[" << count << "]=>" << endl; cout << "\t\tName:" << t->t_name << endl; cout << "\t\tSubject" << t->t_subject << endl; cout << "\t\tClass" << t->t_Class << endl; cout << "\t\tAge:" << t->t_age << endl; count++; t = t->next; } } } void teacher::search_name(string name) { if (!head) { cout << "File is Empty.........................." << endl; } else { Node *t = head; //while(t->next!=NULL) //t=t->next; int count = 1; cout << endl << endl; while (t != NULL) { if (t->t_name == name) { cout << "[" << count << "]=>" << endl; cout << "\t\tName:" << t->t_name << endl; cout << "\t\tSubject:" << t->t_subject << endl; cout << "\t\tClass" << t->t_Class << endl; cout << "\t\tAge:" << t->t_age << endl; } count++; t = t->next; } } } int main() { student S; teacher T; string T_name; string subject; int age; int Class_teacher; string course_code; int marks; float cgpa; string name; int ch; ifstream fin,fin1,fin2,fin3,fin4, fin5, fin6, fin7; fin.open("s_name.txt"); fin1.open("s_course.txt"); fin2.open("s_marks.txt"); fin3.open("s_cgpa.txt"); fin4.open("t_name.txt"); fin5.open("t_subject.txt"); fin6.open("t_class.txt"); fin7.open("t_age.txt"); while (!fin.eof() && !fin1.eof() && !fin2.eof() && !fin3.eof() && !fin4.eof() && !fin5.eof() && !fin6.eof() && !fin7.eof()) { fin >> name; fin1 >> course_code; fin2 >> marks; fin3 >> cgpa; fin4 >> T_name; fin5 >> subject; fin6 >> Class_teacher; fin7 >> age; S.create_node(name, course_code, marks, cgpa); T.create_node(T_name, subject, Class_teacher, age); } while (1) { cout << "-------------------STUDENT MANAGEMENT FUNCTION----------------------------" << endl; cout << "Enter 1 to Create_Student_Record:" << endl; cout << "Enter 2 to Display the Student_Record:" << endl; cout << "Enter 3 to Find the Student with Name:" << endl; cout << "Enter 4 to Delete the Record of the Student:" << endl; cout << "-------------------TEACHER MANAGEMENT FUNCTION----------------------------" << endl; cout << "Enter 5 to Create_Teacher_Record:" << endl; cout << "Enter 6 to Display the Teacher_Record:" << endl; cout << "Enter 7 to Find the Teacher with Name:" << endl; cout << "Enter 8 to Delete the Record of the Teacher:" << endl; cout << "Enter 9 for Exit:" << endl; cin >> ch; if (ch == 1) { cout << "Enter the Name:" << endl; cin >> name; cout << "Enter the Course Code:" << endl; cin >> course_code; cout << "Enter the marks:" << endl; cin >> marks; cout << "Enter the CGPA:" << endl; cin >> cgpa; S.create_node(name, course_code, marks, cgpa); } else if (ch == 2) { S.display(); } else if (ch == 3) { string x; cout << "Enter the name:" << endl; cin >> x; S.search_name(x); } else if (ch == 4) { int x; cout << "Enter the Student Location-Number:" << endl; cin >> x; S.delete_node(x); cout << "Student at Location " << x << " is deleted" << endl; } else if (ch == 5) { cout << "Enter the Name:" << endl; cin >> T_name; cout << "Enter the subject:" << endl; cin >> subject; cout << "Enter the class:" << endl; cin >> Class_teacher; cout << "Enter the age" << endl; cin >> age; T.create_node(T_name, subject, Class_teacher, age); } else if (ch == 6) { T.display(); } else if (ch == 7) { string x; cout << "Enter the name:" << endl; cin >> x; T.search_name(x); } else if (ch == 8) { int x; cout << "Enter the Teacher Location-Number:" << endl; cin >> x; T.delete_node(x); cout << "Teacher at Location " << x << " is deleted" << endl; } else if (ch == 9) { exit(1); } else { cout << "Enter the valid Input......" << endl; } system("pause"); system("cls"); } return 0; }