I am Working on a project about university database and i got stuck in DeleteCollege(College*&head) funcion that would take the head pointer and search for the name of the college and delete it by it's name without losing other colleges from the linked list
This is a linked list program and this is an example:
I have created 2 classes and an add function
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
class Department
{
public:
string name;
int numOfStudents;
Department* next;
Department(){name[0] ; numOfStudents=0 ; next=NULL ;}
Department( string n , int numS){ name =" "; n ;numOfStudents = numS ; next=NULL;}
void Print(){cout<<name<<" "<<numOfStudents;}
};
class College
{
public :
string name; //for name of the colleg
int numOfColleges;
int numDepartments; //number of departments in this college
Department* dep; //this will point to the department in this college
College * next; //the next pointer to point to the next college
College(){name =" "; numDepartments=0 ;dep=NULL; next=NULL;}
College (string n, int numD ){name=n ;next=NULL;}
void Print(){cout<<name<<"\nnum Of Departments :"<<numDepartments;}
};
void AddCollege( College* &head)
{
string n;
int numD;
cout<<"Enter the name of the College : ";
cin>>n;
cout<<"Enter the number of Departments : ";
cin>>numD;
College * tmp = new College(n,numD) ;
tmp->next = head;
head=tmp;
cout<<"college added";}
void Delete(College*& head) // this is where I'm stuck
int main() // Main should look like this
{
int choice=0;
College * h = NULL;
while(choice!=11) //Menu choice repeat
{
cout<<"\n\nMenu\n";
cout<<"1: Add a new college in the list \n";
cout<<"2: Delete a college from the list \n";
cout<<"3: Add a department in a college\n";
cout<<"4: Delete a department from a college.\n";
cout<<"5: Print all the colleges along with their departments\n ";
cout<<"6: Delete all the departments of a particular college \n";
cout<<"7: Delete all the colleges from the list.\n";
cout<<"8: Print the total number of students in a college.\n";
cout<<"9: Find and print the college that has the highest number of students. \n";
cout<<"10: Find and print the department that has the highest number of students.\n";
cout<<"EXIT\n";
cin>>choice;
switch(choice)
{
case 1: AddCollege(*&h);
break;
case 2: DeleteCollege(*&h);
break;
/*
case 3:
AddDepartment(*&h);
break;
case 4:
DeleteDepartment(*&h);
break;
case 5:
PrintAll(*&h);
break;
case 6:
DeleteDepartment(*&h);
break;
case 7:
DeleteAllColleges(*&h);
break;
case 8:
NumOfStudentsInCollege(*&h);
break;
case 9:
HighestNumOfStudentsInCollege(*&h);
break;
case 10:
HighestNumOfStudentsInDep(*&h);
break;
case 11:
cout<<"bye";
break;*/