Geradot345

курсовая работа

Dec 17th, 2020 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.87 KB | None | 0 0
  1. //курсовая работа Вариант 13 Щеглов В.А. 19ВИ1
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5. #include <string>
  6. #include <set>
  7.  
  8. using namespace std;
  9.  
  10. struct ege
  11. {
  12. string fam;
  13. string name;
  14. string otch;
  15. string sch;
  16. int phis=0;
  17. int math=0;
  18. int inf=0;
  19. ege* next;
  20. ege* prev;
  21. };
  22.  
  23. void peren(ege* start){
  24. ifstream fil("курсач.txt");
  25. string n;
  26. fil>>n;
  27. fil.close();
  28. ifstream file("курсач.txt");
  29. if(n!=""){
  30. ege *sp,*prev;
  31. string phis,math,inf;
  32. file>>start->fam;
  33. file>>start->name;
  34. file>>start->otch;
  35. file>>start->sch;
  36. file>>phis;
  37. file>>math;
  38. file>>inf;
  39. start->phis=stoi(phis);
  40. start->math=stoi(math);
  41. start->inf=stoi(inf);
  42. sp=start;
  43. while(!(file.eof())){
  44. ege *node=new ege;
  45. sp->next=node;
  46. prev=sp;
  47. sp=sp->next;
  48. sp->prev=prev;
  49. file>>sp->fam;
  50. file>>sp->name;
  51. file>>sp->otch;
  52. file>>sp->sch;
  53. file>>phis;
  54. file>>math;
  55. file>>inf;
  56. sp->phis=stoi(phis);
  57. sp->math=stoi(math);
  58. sp->inf=stoi(inf);
  59. }
  60. file.close();
  61. sp->next=NULL;
  62. }
  63. }
  64.  
  65. void pokaz(ege *start){
  66. ege *sp;
  67. if(start->fam!=""){
  68. sp=start;
  69. while(sp!=NULL){
  70. cout<<endl<<sp->fam<<" "<<sp->name<<" "<<sp->otch<<" "<<sp->sch<<" "<<sp->phis<<" "<<sp->math<<" "<<sp->inf;
  71. sp=sp->next;
  72. }
  73. }else cout<<"Документ пуст";
  74. }
  75.  
  76. void dob_elem(ege* start){
  77. ege *sp,*prev;
  78. cout<<"Сколько хотите добавить элементов?";
  79. int c;
  80. cin>>c;
  81. ofstream fi ("курсач.txt", ios::app);
  82. if(start->fam==""){
  83. cout<<"Фамилия сдавшего ЕГЭ: ";
  84. cin>>start->fam;
  85. cout<<"Имя сдавшего ЕГЭ: ";
  86. cin>>start->name;
  87. cout<<"Отчество сдавшего ЕГЭ: ";
  88. cin>>start->otch;
  89. cout<<"Школа сдавшего ЕГЭ: ";
  90. cin>>start->sch;
  91. cout<<"Баллы по физике сдавшего ЕГЭ: ";
  92. cin>>start->phis;
  93. cout<<"Баллы по математике сдавшего ЕГЭ: ";
  94. cin>>start->math;
  95. cout<<"Баллы по информатике сдавшего ЕГЭ: ";
  96. cin>>start->inf;
  97. fi<<start->fam<<" "<<start->name<<" "<<start->otch<<" "<<start->sch<<" "<<start->phis<<" "<<start->math<<" "<<start->inf;
  98. c--;
  99. start->next=NULL;
  100. start->prev=NULL;
  101. }
  102. sp=start;
  103. while(!(sp->next==NULL)){
  104. sp=sp->next;
  105. }
  106. for(int i=1;i<=c;i++){
  107. ege *node=new ege;
  108. sp->next=node;
  109. prev=sp;
  110. sp=sp->next;
  111. sp->prev=prev;
  112. sp->next=NULL;
  113. cout<<"Фамилия сдавшего ЕГЭ: ";
  114. cin>>sp->fam;
  115. cout<<"Имя сдавшего ЕГЭ: ";
  116. cin>>sp->name;
  117. cout<<"Отчество сдавшего ЕГЭ: ";
  118. cin>>sp->otch;
  119. cout<<"Школа сдавшего ЕГЭ: ";
  120. cin>>sp->sch;
  121. cout<<"Баллы по физике сдавшего ЕГЭ: ";
  122. cin>>sp->phis;
  123. cout<<"Баллы по математике сдавшего ЕГЭ: ";
  124. cin>>sp->math;
  125. cout<<"Баллы по информатике сдавшего ЕГЭ: ";
  126. cin>>sp->inf;
  127. fi<<endl<<sp->fam<<" "<<sp->name<<" "<<sp->otch<<" "<<sp->sch<<" "<<sp->phis<<" "<<sp->math<<" "<<sp->inf;
  128. }
  129. fi.close();
  130. }
  131.  
  132. void find(ege *start){
  133. ege *sp;
  134. if(start->fam!=""){
  135. cout<<"По какому параметру хотите произвести поиск(Фамилия, Школа)?";
  136. string b;
  137. cin>>b;
  138. if (b=="Фамилия"){
  139. cout<<"Данные по ученикам с какой Фамилией вы хотите найти?";
  140. string c;
  141. cin>>c;
  142. sp=start;
  143. while(sp!=NULL){
  144. if(sp->fam==c){
  145. cout << sp->fam << " " << sp->name << " " << sp->otch << " " << sp->sch << " " << sp->phis << " " << sp->math << " " << sp->inf<<endl;
  146. cout<<"Хотите удалить этот элемент?";
  147. string d;
  148. cin>>d;
  149. if(d=="Да"){
  150. if(sp->prev==NULL){
  151. if(sp->next!=NULL){
  152. sp=sp->next;
  153. sp->prev=NULL;
  154. start=sp;
  155. }else {
  156. start->fam="";
  157. start->name="";
  158. start->otch="";
  159. start->sch="";
  160. start->phis=0;
  161. start->math=0;
  162. start->inf=0;
  163. start->next=NULL;
  164. start->prev=NULL;
  165. sp=start;
  166. }
  167. }else{
  168. if(sp->next==NULL){
  169. sp->prev->next=NULL;
  170. free(sp);
  171. }else{
  172. sp->prev->next=sp->next;
  173. sp->next->prev=sp->prev;
  174. free(sp);
  175. }
  176. }
  177. }
  178. }
  179. sp=sp->next;
  180. }
  181. }
  182. if (b=="Школа"){
  183. cout<<"Данные по ученикам из какой школы вы хотите найти?";
  184. string c;
  185. cin>>c;
  186. sp=start;
  187. while(sp!=NULL){
  188. if(sp->sch==c){
  189. cout << sp->fam << " " << sp->name << " " << sp->otch << " " << sp->sch << " " << sp->phis << " " << sp->math << " " << sp->inf<<endl;
  190. cout<<"Хотите удалить этот элемент?";
  191. string d;
  192. cin>>d;
  193. if(d=="Да"){
  194. if(sp->prev==NULL){
  195. if(sp->next!=NULL){
  196. sp=sp->next;
  197. sp->prev=NULL;
  198. start=sp;
  199. }else {
  200. start->fam="";
  201. start->name="";
  202. start->otch="";
  203. start->sch="";
  204. start->phis=0;
  205. start->math=0;
  206. start->inf=0;
  207. start->next=NULL;
  208. start->prev=NULL;
  209. sp=start;
  210. }
  211. }else{
  212. if(sp->next==NULL){
  213. sp->prev->next=NULL;
  214. free(sp);
  215. }else{
  216. sp->prev->next=sp->next;
  217. sp->next->prev=sp->prev;
  218. free(sp);
  219. }
  220. }
  221. }
  222. }
  223. sp=sp->next;
  224. }
  225. }
  226. ofstream f("курсач.txt");
  227. sp=start;
  228. if(sp->fam!=""){
  229. f<<sp->fam<<" "<<sp->name<<" "<<sp->otch<<" "<<sp->sch<<" "<<sp->phis<<" "<<sp->math<<" "<<sp->inf;
  230. sp=sp->next;
  231. while(sp!=NULL){
  232. f<<endl<<sp->fam<<" "<<sp->name<<" "<<sp->otch<<" "<<sp->sch<<" "<<sp->phis<<" "<<sp->math<<" "<<sp->inf;
  233. sp=sp->next;
  234. }
  235. }
  236. f.close();
  237. }else cout<<"Документ Пуст";
  238. }
  239.  
  240. void max_min(ege* start){
  241. if(start->fam!=""){
  242. float max=0;
  243. string max_sc;
  244. float min=900;
  245. string min_sc;
  246. set<string>myset;
  247. ege *sp,*st;
  248. sp=start;
  249. while(sp!=NULL){
  250. if(!(myset.count(sp->sch))){
  251. float sum=0;
  252. float kol=0;
  253. st=start;
  254. while(st!=NULL){
  255. if(sp->sch==st->sch){
  256. sum+=st->phis+st->math+st->inf;
  257. kol++;
  258. }
  259. st=st->next;
  260. }
  261. if ((sum/kol)>max){
  262. max=sum/kol;
  263. max_sc=sp->sch;
  264. }
  265. if ((sum/kol)<min){
  266. min=sum/kol;
  267. min_sc=sp->sch;
  268. }
  269. myset.insert(sp->sch);
  270. }
  271. sp=sp->next;
  272. }
  273. cout<<"Школа с минимальным средним баллом: "<<min_sc<<endl;
  274. cout<<"Школа с максимальным средним баллом: "<<max_sc<<endl;
  275. } else cout<<"Данных нет";
  276. }
  277.  
  278. int main()
  279. {
  280. setlocale(LC_ALL, "Russian");
  281. ege start;
  282. char r;
  283. start.prev=NULL;
  284. peren(&start);
  285. while(r!='0'){
  286. cout<<"Меню:"<<endl<<"1)Показать данные"<<endl<<"2)Добавить Элемент"<<endl<<"3)Найти данные по элементу"<<endl<<"4)Определить школы с максимальным средним баллом по ЕГЭ и минимальным"<<endl<<"0)Закрыть"<<endl<<"Выберите действие(0..4) ";
  287. cin>>r;
  288. switch(r){
  289. case '1':
  290. pokaz(&start);
  291. cout<<endl;
  292. break;
  293. case '2':
  294. dob_elem(&start);
  295. break;
  296. case '3':
  297. find(&start);
  298. break;
  299. case '4':
  300. max_min(&start);
  301. }
  302. }
  303. }
Add Comment
Please, Sign In to add comment