Debugging C++ file -
i getting error main.cpp:23:5: error: ‘department’ not name type
/* * file: main.cpp * author: anonymous * * created on may 11, 2015, 9:44 pm */ #include <cstdlib> #include <iostream> using namespace std; class college{ public : string name; //for name of college int numofcolleges; int numdepartments; //number of departments in college department* dep; //this point department in college college* next; //the next pointer point next college college(){ name =" "; numdepartments=0 ; dep = null; next=null;} college (string n, int numd ){name=n ;next=null;} void print(){ cout<<name<<"\n"; } }; 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;} }; void addcollege(college *head) { string n; int numd; cout<<"enter name of college : "; cin>>n; cout<<"enter number of departments : "; cin>>numd; college* tmp = new college(n,numd); if(!head) { head=tmp; return; } college * t=head; while(t->next) t=t->next; t->next=tmp; cout<<"college added"; } void deletecollege(college*&head) { string name; cout<<"enter name of college:"; cin>>name; if((!head)||(!head->next && head->name!=name)) { cout<<"could not find "<<name<<" in list\n"; return; } if(head->next && head->name==name) { college *tmp=head; head=head->next; delete tmp; tmp=null; return; } college* tmp = head; college* t; while(tmp->next) { if(tmp->name==name) { college* tmp = head; head = head->next; delete tmp; tmp->next=null; } if(tmp->next->name == name) { t = tmp->next; tmp->next = tmp->next->next; delete t; return; } tmp=tmp->next; } cout<<"could not find "<<name<<" in list\n"; }; /*print list of colleges int college head*/ void printcolleges(college *head) { cout<<"all colleges in database : \n"; college * temp = head; while(temp!=null) { temp->print(); temp=temp->next; } } void adddepartment(college *head) { if(!head) { cout<<"no colleges added!!"; return; } string n,dname; int nums; college* tmp = head; college*tmp2 = tmp; ; while(tmp) { cout<<"->"<<tmp->name; tmp=tmp->next; cout<<endl; } cout<<"type college name add department inside\n"; cin>>n; cout<<"enter department name:"; cin>>dname; cout<<"enter number of students :"; cin>>nums; while(n!=tmp->name) { tmp=tmp->next; } if(!tmp-> dep) { college * tmpd = new department(dname,nums); department*tmpdd = tmpd; head=tmp; return; } /*if(tmp->dep) { department *tmp3 = tmp->dep->next; t=tmp->dep; dep->next=tmp3; }*/ }; //void deletedepartment(college* head) //{ // // // ;} void printall(college*head) { college * temp = head; while(temp!=null) { temp->print(); temp=temp->next; } }; int main(int argc, char** argv) { int choice; college*h = null; while(choice!=11){ cout<<"\n\nmenu\n"; cout<<"1: add new college in list \n"; cout<<"2: delete college list \n"; cout<<"3: add department in college\n"; cout<<"4: delete department college.\n"; cout<<"5: print colleges along departments\n "; cout<<"6: delete departments of particular college \n"; cout<<"7: delete colleges list.\n"; cout<<"8: print total number of students in college.\n"; cout<<"9: find , print college has highest number of students. \n"; cout<<"10: find , print department has highest number of students.\n"; cout<<"exit\n"; cin>>choice; switch(choice) { case 1: addcollege(*&h); break; case 2: deletecollege(*&h); break; case 3: printcolleges(*&h); break; case 4: 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;*/ default: cout<<"\ninvalid menu choice"; } } }
declare department class before it's called in college. (move department declaration above college declaration):
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 college int numofcolleges; int numdepartments; //number of departments in college department * dep; //this point department in college college * next; //the next pointer point next college college(){ name =" "; numdepartments=0 ; dep = null; next=null;} college (string n, int numd ){name=n ;next=null;} void print(){ cout<<name<<"\n"; } };
Comments
Post a Comment