Page 1 of 1

C/C++

Posted: Wed Apr 27, 2022 3:37 pm
by answerhappygod
C/C++
C C 1
C C 1 (159.96 KiB) Viewed 52 times
In this assignment, you will implement a class for a linked list to maintain and register students in a university (small scale). The information required for the students as, the NAME, STU_ID, ADDRESS, GPA. By using this STU_ID number, we will be able to retrieve and update information for the students. The STU_ID must be unique. Class UNIVERSITY includes a LinkedList of students, NAME and COUNT which is the number of the students. Use the following definitions: struct STUDENT { char name[64]; char address [64]; int id; double gpa; STUDENT* next_student; }; class UNIVERSITY { private: STUDENT *start; char* university_name; int count; // number of stored students. public: // default constructor; //copy constructor; // destructor; // overload operator = // overload operator +; UNIVERSITY + STUDENT, this function add students in ascending order according to their (ID). // function to set the name. // Overload «, to print the students in descending order (ID), without reversing the linkedlist. Use stack. //Overload operator >> to read from a file. Reading students from the file must also be stored in ascending order(ID). // Rec_AVG(); a recursive member function that return the average gpa of the students in the university. }; Task: You are required to implement all functions in the class university as shown above. You must write them correctly. For example, the destructor must delete the name in the heap memory correctly. You can't leave it empty. Similarly for all other functions. You can add other functions, but they must be private functions.
Example of Input Files: "univ 1.txt" University_1 120455 Rami Jerusalem 3.5 120222 Ali Nablus 3.5 120444 Aya Jenin 3.2 “univ_2.txt" University_2 120111 Ahmed Nablus 3.5 120222 Amro Nablus 3.6 120333 Serin Tulkarm 2.9 120987 Tala Bethlehem3.1 120719 Ruba Jerusalem 3.1 120438 Shadi Jenin 4.0 120745 Haya Nablus 2.0 120541 Tala Bethlehem 3.8 “univ_3.txt" University_3 120138 Adam Bethlehem 3.6 120198 Sondos Tulkarm 2.7 120172 Tamer Nablus 3.2 The following main function must work correctly after finishing your code: #include "Univ.h" #include<iostream> #include<fstream> #include<cmath> using namespace std; int main() { ifstream input_f1("univ_1.txt"); ifstream input_f2("univ_2.txt"); ifstream input_f3("univ_3.txt"); UNIVERSITY U1; UNIVERSITY U2; UNIVERSITY U3; input_f1 >> U1; input_f2 >> U2; input_f3 >> U3; { UNIVERSITY TEST(U1); UNIVERSITY TEST2; TEST2 = TEST1; cout << TEST1; 11 (1) STUDENT S; strcpy(s.name, "testName"); strcpy(S.address, "testAddress"); S.gpa = 3.4; S.id = 121515; TEST2 = TEST2 + S; cout << TEST2; // (2) } cout << U3; // (3) cout << "Average: "«< 03. Rec_AVG(); // (4) return 0;
The corresponding output as the following: 11 (1) University_1 120455 Rami Jerusalem 3.5 120444 Aya Jenin 3.2 120222 Ali Nablus 3.5 11 (2) University_1 120515 testName testAddress 3.4 120455 Rami Jerusalem 3.5 120444 Aya Jenin 3.2 120222 Ali Nablus 3.5 // (3) University_3 120198 Sondos Tulkarm 2.7 120138 Adam Bethlehem 3.6 120172 Tamer Nablus 3.2 // (4) Average: 3.17