Advertisement
Guest User

geraldine doubly 3

a guest
Nov 28th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.27 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<fstream>
  4.  
  5. using namespace std;
  6. struct STUDENT
  7. {
  8. string Name;
  9. int Age;
  10. double Weight;
  11. double Height;
  12. string Course;
  13. int Year;
  14. bool Status;
  15. STUDENT *next;
  16. STUDENT *prev;
  17. STUDENT(string n, int a, double w, double h, string c, int y, bool s)
  18. {
  19. Name=n;
  20. Age=a;
  21. Weight=w;
  22. Height=h;
  23. Course=c;
  24. Year=y;
  25. Status=s;
  26. next=NULL;
  27. prev=NULL;
  28. }
  29.  
  30. }*start,*tail;
  31. struct doubly
  32. {
  33. doubly()
  34. {
  35. start=NULL;
  36. tail=NULL;
  37. }
  38. bool add(STUDENT *studnt)
  39. {
  40. if(start==NULL)
  41. {
  42. start = studnt;
  43. tail = studnt;
  44. }
  45. else
  46. {
  47. STUDENT *temp=start;
  48. cout<<"compare!:"<<temp->Name.compare(studnt->Name)<<endl;
  49. if(temp->Name.compare(studnt->Name)>=0&&temp==start)
  50. {
  51. if(temp->Name.compare(studnt->Name)==0)
  52. {
  53. cout<<"Name already exists!"<<endl;
  54. return false;
  55. }
  56. studnt->next=start;
  57. start->prev=studnt;
  58. start=studnt;
  59.  
  60. return true;
  61.  
  62. }
  63. while(temp->next!=NULL)
  64. {
  65. if(temp->Name.compare(studnt->Name)==0)
  66. {
  67. cout<<"Name already exists!"<<endl;
  68. return false;
  69. }
  70. if(temp->next->Name.compare(studnt->Name)<=0)
  71. {
  72. temp=temp->next;
  73. break;
  74. }
  75. }
  76. studnt->next=temp->next;
  77. temp->next=studnt;
  78. studnt->prev=temp;
  79.  
  80. }
  81. return true;
  82. }
  83. bool edit(STUDENT *studnt)
  84. {
  85. if(start==NULL)
  86. {
  87. cout<<"No such student exist!"<<endl;
  88. return false;
  89. }
  90. else
  91. {
  92. STUDENT *temp=start;
  93. if(studnt->Name.compare(start->Name)==0)
  94. {
  95. studnt->next=temp->next;
  96. temp->next->prev=studnt;
  97. start=studnt;
  98. delete temp;
  99. return true;
  100. }
  101. while(temp->next!=NULL)
  102. {
  103. if(studnt->Name.compare(temp->next->Name)==0)
  104. {
  105. studnt->next=temp->next->next;
  106. temp->next=studnt;
  107. return true;
  108. }
  109. temp=temp->next;
  110. }
  111. }
  112. return false;
  113. }
  114. bool del(string name)
  115. {
  116. if(start==NULL)
  117. {
  118. cout<<"No such student exist!"<<endl;
  119. return false;
  120. }
  121. STUDENT *temp=start;
  122. if(name.compare(start->Name)==0)
  123. {
  124. start=temp->next;
  125. delete temp;
  126. return true;
  127. }
  128. while(temp->next!=NULL)
  129. {
  130. if(name.compare(temp->next->Name)==0)
  131. {
  132. STUDENT *trash = temp->next;
  133. temp->next=temp->next->next;
  134. delete trash;
  135. return true;
  136. }
  137. temp=temp->next;
  138. }
  139. }
  140. void display()
  141. {
  142. STUDENT *temp=start;
  143. int studentnum=1;
  144. while(temp!=NULL)
  145. {
  146. cout<<"Student Number "<<studentnum<<": "<<endl;
  147. cout<<"Name: "<<temp->Name<<endl<<"Age: "<<temp->Age<<endl;
  148. cout<<"Weight: "<<temp->Weight<<endl<<"Height: "<<temp->Height<<endl;
  149. cout<<"Course: "<<temp->Course<<endl<<"Year: "<<temp->Year<<endl;
  150. if(temp->Status==true)
  151. cout<<"Status: Regular"<<endl<<endl;
  152. else
  153. cout<<"Status: Irregular"<<endl<<endl;
  154. temp=temp->next;
  155. studentnum++;
  156. }
  157. system("pause");
  158. }
  159. };
  160. void main()
  161. {
  162. doubly listers;
  163. ifstream a;
  164. a.open("input.in");
  165. int condition = 0;
  166. string firstline;
  167. getline(a,firstline);
  168. condition = stoi(firstline);
  169. string start;
  170. string cond;
  171. string name;
  172. string age;
  173. string weight;
  174. string height;
  175. string course;
  176. string year;
  177. string status;
  178. string end;
  179. for(int i=1;i<=condition;i++)
  180. {
  181. cout<<"entra";
  182. getline(a,start);
  183. if(start.compare(":")==0)
  184. {
  185. getline(a,cond);
  186. if(cond.compare("1")==0) // add
  187. {
  188. getline(a,name);
  189. cout<<name<<endl;
  190. getline(a,age);
  191. cout<<age<<endl;
  192. getline(a,weight);
  193. cout<<weight<<endl;
  194. getline(a,height);
  195. cout<<height<<endl;
  196. getline(a,course);
  197. cout<<course<<endl;
  198. getline(a,year);
  199. cout<<year<<endl;
  200. getline(a,status);
  201. cout<<status<<endl;
  202. getline(a,end);
  203. cout<<end<<endl<<endl;
  204. int edad = stoi(age);
  205. double pesa = stod(weight);
  206. double altor = stod(height);
  207. int anyo = stoi(year);
  208. bool st;
  209. if(status.compare("Y")==0)
  210. st=true;
  211. else
  212. st=false;
  213.  
  214. STUDENT *s1 = new STUDENT(name,edad,pesa,altor,course,anyo,st);
  215. listers.add(s1);
  216. }
  217. else if(cond.compare("2")==0) // add
  218. {
  219. getline(a,name);
  220. cout<<name<<endl;
  221. getline(a,age);
  222. cout<<age<<endl;
  223. getline(a,weight);
  224. cout<<weight<<endl;
  225. getline(a,height);
  226. cout<<height<<endl;
  227. getline(a,course);
  228. cout<<course<<endl;
  229. getline(a,year);
  230. cout<<year<<endl;
  231. getline(a,status);
  232. cout<<status<<endl;
  233. getline(a,end);
  234. cout<<end<<endl<<endl;
  235. int edad = stoi(age);
  236. double pesa = stod(weight);
  237. double altor = stod(height);
  238. int anyo = stoi(year);
  239. bool st;
  240. if(status.compare("Y")==0)
  241. st=true;
  242. else
  243. st=false;
  244.  
  245. STUDENT *s1 = new STUDENT(name,edad,pesa,altor,course,anyo,st);
  246. listers.edit(s1);
  247. }else if(cond.compare("3")==0)
  248. {
  249. getline(a,name);
  250. cout<<"DELETING!"<<name<<endl;
  251. listers.del(name);
  252. }
  253. while(cond.compare(";")!=0&&cond.compare("1")!=0&&cond.compare("2")!=0) //removing waste
  254. {
  255. getline(a,cond);
  256. cout<<cond<<"asd"<<endl;
  257. }
  258.  
  259.  
  260. }
  261. }
  262. listers.display();
  263. a.close();
  264. /*
  265. cout<<"--------test---------"<<endl;
  266. STUDENT *s1 = new STUDENT("Jan",28,60.6,58,"BSFM",2008,true);
  267. STUDENT *s2 = new STUDENT("Roy",28,60.6,58,"BSFM",2008,true);
  268. STUDENT *s4 = new STUDENT("Ori",28,60.6,58,"BSFM",2008,true);
  269. doubly tutz;
  270. tutz.add(s1);
  271.  
  272. tutz.add(s2);
  273. tutz.add(s3);
  274. tutz.add(s4);
  275. tutz.display();
  276. */
  277.  
  278. system("pause");
  279. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement