├── README.md └── CMS.c /README.md: -------------------------------------------------------------------------------- 1 | This is a project on College Management System using basic C programming where i had used Structure with Pointer and also saved the record in data file. 2 | Feel free to modify this and use it as your own project. 3 | -------------------------------------------------------------------------------- /CMS.c: -------------------------------------------------------------------------------- 1 | //Simple College Management System 2 | 3 | #include 4 | #include 5 | 6 | struct Student { 7 | int id; 8 | char fname[30]; 9 | char lname[30]; 10 | }; 11 | 12 | struct Course { 13 | int id; 14 | char name[60]; 15 | }; 16 | 17 | void addStudent(struct Student *students, int *numStudents) { 18 | if (*numStudents < 100) { 19 | printf("Enter student ID Number: "); 20 | scanf("%d", &students[*numStudents].id); 21 | printf("Enter student's First Name: "); 22 | scanf("%s", students[*numStudents].fname); 23 | printf("Enter student's Last Name: "); 24 | scanf("%s", students[*numStudents].lname); 25 | (*numStudents)++; 26 | printf("\nStudent added successfully.\n\n"); 27 | } else { 28 | printf("Maximum number of students reached.\n"); 29 | } 30 | } 31 | 32 | void addCourse(struct Course *courses, int *numCourses) { 33 | if (*numCourses < 100) { 34 | printf("\nEnter course Code:"); 35 | scanf("%d", &courses[*numCourses].id); 36 | printf("Enter course Name:\n "); 37 | scanf("%s", courses[*numCourses].name); 38 | (*numCourses)++; 39 | printf("Course added successfully.\n"); 40 | } else { 41 | printf("Maximum number of courses reached.\n"); 42 | } 43 | } 44 | 45 | void deleteStudent(struct Student *students, int *numStudents) { 46 | if (*numStudents > 0) { 47 | int studentId; 48 | printf("Enter student ID to delete: "); 49 | scanf("%d", &studentId); 50 | 51 | int found = 0; 52 | for (int i = 0; i < *numStudents; i++) { 53 | if (students[i].id == studentId) { 54 | // Shift the remaining elements to fill the gap 55 | for (int j = i; j < *numStudents - 1; j++) { 56 | students[j] = students[j + 1]; 57 | } 58 | (*numStudents)--; 59 | found = 1; 60 | break; 61 | } 62 | } 63 | 64 | if (found) { 65 | printf("Student record deleted successfully.\n"); 66 | } else { 67 | printf("Student record not found.\n"); 68 | } 69 | } else { 70 | printf("No students found.\n"); 71 | } 72 | } 73 | 74 | void deleteCourse(struct Course *courses, int *numCourses) { 75 | if (*numCourses > 0) { 76 | int courseId; 77 | printf("Enter course ID to delete: "); 78 | scanf("%d", &courseId); 79 | 80 | int found = 0; 81 | for (int i = 0; i < *numCourses; i++) { 82 | if (courses[i].id == courseId) { 83 | // Shift the remaining elements to fill the gap 84 | for (int j = i; j < *numCourses - 1; j++) { 85 | courses[j] = courses[j + 1]; 86 | } 87 | (*numCourses)--; 88 | found = 1; 89 | break; 90 | } 91 | } 92 | 93 | if (found) { 94 | printf("Course record deleted successfully.\n"); 95 | } else { 96 | printf("Course record not found.\n"); 97 | } 98 | } else { 99 | printf("No courses found.\n"); 100 | } 101 | } 102 | 103 | void displayStudents(struct Student *students, int numStudents) { 104 | printf("\nStudent List:\n"); 105 | for (int i = 0; i < numStudents; i++) { 106 | printf("Student ID: %d \n", students[i].id); 107 | printf("Name: %s %s\n", students[i].fname, students[i].lname); 108 | printf("\n"); 109 | } 110 | } 111 | 112 | void displayCourses(struct Course *courses, int numCourses) { 113 | printf("\nCourse List:\n"); 114 | for (int i = 0; i < numCourses; i++) { 115 | printf("Course ID: %d\n", courses[i].id); 116 | printf("Name of Course is: %s\n", courses[i].name); 117 | printf("\n"); 118 | } 119 | } 120 | 121 | void saveData(struct Student *students, int numStudents, struct Course *courses, int numCourses) { 122 | FILE *file = fopen("data.txt", "w"); 123 | if (file == NULL) { 124 | printf("Error opening file.\n"); 125 | return; 126 | } 127 | 128 | fprintf(file, "Students:\n"); 129 | for (int i = 0; i < numStudents; i++) { 130 | fprintf(file, "ID: %d\n", students[i].id); 131 | fprintf(file, "Name: %s %s\n", students[i].fname, students[i].lname); 132 | fprintf(file, "\n"); 133 | } 134 | 135 | fprintf(file, "Courses:\n"); 136 | for (int i = 0; i < numCourses; i++) { 137 | fprintf(file, "ID: %d\n", courses[i].id); 138 | fprintf(file, "Name: %s\n", courses[i].name); 139 | fprintf(file, "\n"); 140 | } 141 | 142 | fclose(file); 143 | printf("Data saved to file successfully.\n"); 144 | } 145 | 146 | int main() { 147 | struct Student students[100]; 148 | struct Course courses[100]; 149 | int numStudents = 0; 150 | int numCourses = 0; 151 | int choice; 152 | 153 | do { 154 | printf("\nCollege Management System\n\n"); 155 | printf("1. Add Student\n"); 156 | printf("2. Add Course\n"); 157 | printf("3. Delete Student\n"); 158 | printf("4. Delete Courses Record\n"); 159 | printf("5. Display Students Record\n"); 160 | printf("6. Display Courses\n"); 161 | printf("7. Save Data to File\n"); 162 | printf("8. Exit\n"); 163 | printf("Enter your choice: "); 164 | scanf("%d", &choice); 165 | 166 | switch (choice) { 167 | case 1: 168 | addStudent(students, &numStudents); 169 | break; 170 | case 2: 171 | addCourse(courses, &numCourses); 172 | break; 173 | case 3: 174 | deleteStudent(students, &numStudents); 175 | break; 176 | case 4: 177 | deleteCourse(courses, &numCourses); 178 | break; 179 | case 5: 180 | displayStudents(students, numStudents); 181 | break; 182 | case 6: 183 | displayCourses(courses, numCourses); 184 | break; 185 | case 7: 186 | saveData(students, numStudents, courses, numCourses); 187 | break; 188 | case 8: 189 | printf("Exiting...\n"); 190 | break; 191 | default: 192 | printf("Invalid choice. Please try again.\n"); 193 | } 194 | } while (choice != 8); 195 | 196 | return 0; 197 | } 198 | --------------------------------------------------------------------------------