Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<fstream>
- using namespace std;
- struct STUDENT
- {
- string Name;
- int Age;
- double Weight;
- double Height;
- string Course;
- int Year;
- bool Status;
- STUDENT *next;
- STUDENT *prev;
- STUDENT(string n, int a, double w, double h, string c, int y, bool s)
- {
- Name=n;
- Age=a;
- Weight=w;
- Height=h;
- Course=c;
- Year=y;
- Status=s;
- next=NULL;
- prev=NULL;
- }
- }*start,*tail;
- struct doubly
- {
- doubly()
- {
- start=NULL;
- tail=NULL;
- }
- bool add(STUDENT *studnt)
- {
- if(start==NULL)
- {
- start = studnt;
- tail = studnt;
- }
- else
- {
- STUDENT *temp=start;
- cout<<"compare!:"<<temp->Name.compare(studnt->Name)<<endl;
- if(temp->Name.compare(studnt->Name)>=0&&temp==start)
- {
- if(temp->Name.compare(studnt->Name)==0)
- {
- cout<<"Name already exists!"<<endl;
- return false;
- }
- studnt->next=start;
- start->prev=studnt;
- start=studnt;
- return true;
- }
- while(temp->next!=NULL)
- {
- if(temp->Name.compare(studnt->Name)==0)
- {
- cout<<"Name already exists!"<<endl;
- return false;
- }
- if(temp->next->Name.compare(studnt->Name)<=0)
- {
- temp=temp->next;
- break;
- }
- }
- studnt->next=temp->next;
- temp->next=studnt;
- studnt->prev=temp;
- }
- return true;
- }
- bool edit(STUDENT *studnt)
- {
- if(start==NULL)
- {
- cout<<"No such student exist!"<<endl;
- return false;
- }
- else
- {
- STUDENT *temp=start;
- if(studnt->Name.compare(start->Name)==0)
- {
- studnt->next=temp->next;
- temp->next->prev=studnt;
- start=studnt;
- delete temp;
- return true;
- }
- while(temp->next!=NULL)
- {
- if(studnt->Name.compare(temp->next->Name)==0)
- {
- studnt->next=temp->next->next;
- temp->next=studnt;
- return true;
- }
- temp=temp->next;
- }
- }
- return false;
- }
- bool del(string name)
- {
- if(start==NULL)
- {
- cout<<"No such student exist!"<<endl;
- return false;
- }
- STUDENT *temp=start;
- if(name.compare(start->Name)==0)
- {
- start=temp->next;
- delete temp;
- return true;
- }
- while(temp->next!=NULL)
- {
- if(name.compare(temp->next->Name)==0)
- {
- STUDENT *trash = temp->next;
- temp->next=temp->next->next;
- delete trash;
- return true;
- }
- temp=temp->next;
- }
- }
- void display()
- {
- STUDENT *temp=start;
- int studentnum=1;
- while(temp!=NULL)
- {
- cout<<"Student Number "<<studentnum<<": "<<endl;
- cout<<"Name: "<<temp->Name<<endl<<"Age: "<<temp->Age<<endl;
- cout<<"Weight: "<<temp->Weight<<endl<<"Height: "<<temp->Height<<endl;
- cout<<"Course: "<<temp->Course<<endl<<"Year: "<<temp->Year<<endl;
- if(temp->Status==true)
- cout<<"Status: Regular"<<endl<<endl;
- else
- cout<<"Status: Irregular"<<endl<<endl;
- temp=temp->next;
- studentnum++;
- }
- system("pause");
- }
- };
- void main()
- {
- doubly listers;
- ifstream a;
- a.open("input.in");
- int condition = 0;
- string firstline;
- getline(a,firstline);
- condition = stoi(firstline);
- string start;
- string cond;
- string name;
- string age;
- string weight;
- string height;
- string course;
- string year;
- string status;
- string end;
- for(int i=1;i<=condition;i++)
- {
- cout<<"entra";
- getline(a,start);
- if(start.compare(":")==0)
- {
- getline(a,cond);
- if(cond.compare("1")==0) // add
- {
- getline(a,name);
- cout<<name<<endl;
- getline(a,age);
- cout<<age<<endl;
- getline(a,weight);
- cout<<weight<<endl;
- getline(a,height);
- cout<<height<<endl;
- getline(a,course);
- cout<<course<<endl;
- getline(a,year);
- cout<<year<<endl;
- getline(a,status);
- cout<<status<<endl;
- getline(a,end);
- cout<<end<<endl<<endl;
- int edad = stoi(age);
- double pesa = stod(weight);
- double altor = stod(height);
- int anyo = stoi(year);
- bool st;
- if(status.compare("Y")==0)
- st=true;
- else
- st=false;
- STUDENT *s1 = new STUDENT(name,edad,pesa,altor,course,anyo,st);
- listers.add(s1);
- }
- else if(cond.compare("2")==0) // add
- {
- getline(a,name);
- cout<<name<<endl;
- getline(a,age);
- cout<<age<<endl;
- getline(a,weight);
- cout<<weight<<endl;
- getline(a,height);
- cout<<height<<endl;
- getline(a,course);
- cout<<course<<endl;
- getline(a,year);
- cout<<year<<endl;
- getline(a,status);
- cout<<status<<endl;
- getline(a,end);
- cout<<end<<endl<<endl;
- int edad = stoi(age);
- double pesa = stod(weight);
- double altor = stod(height);
- int anyo = stoi(year);
- bool st;
- if(status.compare("Y")==0)
- st=true;
- else
- st=false;
- STUDENT *s1 = new STUDENT(name,edad,pesa,altor,course,anyo,st);
- listers.edit(s1);
- }else if(cond.compare("3")==0)
- {
- getline(a,name);
- cout<<"DELETING!"<<name<<endl;
- listers.del(name);
- }
- while(cond.compare(";")!=0&&cond.compare("1")!=0&&cond.compare("2")!=0) //removing waste
- {
- getline(a,cond);
- cout<<cond<<"asd"<<endl;
- }
- }
- }
- listers.display();
- a.close();
- /*
- cout<<"--------test---------"<<endl;
- STUDENT *s1 = new STUDENT("Jan",28,60.6,58,"BSFM",2008,true);
- STUDENT *s2 = new STUDENT("Roy",28,60.6,58,"BSFM",2008,true);
- STUDENT *s4 = new STUDENT("Ori",28,60.6,58,"BSFM",2008,true);
- doubly tutz;
- tutz.add(s1);
- tutz.add(s2);
- tutz.add(s3);
- tutz.add(s4);
- tutz.display();
- */
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement