|
utemez202305_dk_C++.cpp
|
|
1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 #include <algorithm>
5 #include <string>
6
7 using namespace std;
8
9 struct tabor
10 {
11 int h1,n1,h2,n2;
12 string diakok,tema;
13 };
14
15 void F1(vector<tabor> &t)
16 {
17 ifstream fbe;
18 fbe.open("taborok.txt");
19 tabor tmp;
20 while(fbe>>tmp.h1&&fbe>>tmp.n1&&fbe>>tmp.h2&&fbe>>tmp.n2&&fbe>>tmp.diakok&&fbe>>tmp.tema)
21 {
22 t.push_back(tmp);
23 }
24 fbe.close();
25 }
26
27 void F2(vector<tabor> t)
28 {
29 cout << "2. feladat" << endl;
30 printf("Az adatsorok száma: %d\n",t.size()); // 28
31 printf("Az először rögzített tábor témája : %s\n",t[0].tema.c_str());
32 printf("Az utoljára rögzített tábor témája: %s\n",t[t.size()-1].tema.c_str());
33 }
34
35 void F3(vector<tabor> t)
36 {
37 cout << "------------------------------------------------------" << endl;
38 cout << "3. feladat" << endl;
39 bool van=false;
40 for(auto tabor:t)
41 {
42 if(tabor.tema=="zenei")
43 {
44 printf("Zenei tábor kezdődik %d. hó %d. napján.\n",tabor.h1,tabor.n1);
45 van=true;
46 }
47 }
48 if(!van) cout << "Nem volt zenei tábor." << endl;
49 }
50
51 bool diakok_szerint(tabor a, tabor b)
52 {
53 return a.diakok.size()>b.diakok.size();
54 }
55
56 void F4(vector<tabor> t)
57 {
58 cout << "------------------------------------------------------" << endl;
59 cout << "4. feladat" << endl;
60 vector<tabor> tmp;
61 tmp=t;
62 sort(tmp.begin(),tmp.end(),diakok_szerint);
63 cout << tmp[0].h1 << " " << tmp[0].n1 << " " << tmp[0].tema << endl;
64 int i=1;
65 while(tmp[i].diakok.size()==tmp[0].diakok.size())
66 {
67 cout << tmp[i].h1 << " " << tmp[i].n1 << " " << tmp[i].tema << endl;
68 i++;
69 }
70 }
71
72 int sorszam(int h,int n)
73 {
74 // A nyári szünet első napja 6. hó 16.
75 // A nyári szünet 77. napja 8. hó 31.
76 // (A nyári hónapok rendre 30, 31, 31 naposak.)
77 int napok=0;
78 switch(h)
79 {
80 case 6: napok+=(n-15); break; // júniusban 15 nap, ami nyári szünet
81 case 7: napok+=15+n; break; // július esetén: júniusi 15 nap + a megadott nap
82 case 8: napok+=46+n; // augusztus esetén: 15 júniusi nap + 31 júliusi nap + a megadott nap
83 }
84 return napok;
85 }
86
87 void F6(vector<tabor> t)
88 {
89 cout << "------------------------------------------------------" << endl;
90 cout << "6. feladat" << endl;
91 int honap,nap,k,v,db;
92 printf("hó: ");
93 scanf("%d",&honap);
94 printf("nap: ");
95 scanf("%d",&nap);
96 int s=sorszam(honap,nap); // a megadott dátum sorszáma
97 db=0;
98 for(auto tab:t)
99 {
100 k=sorszam(tab.h1,tab.n1); // egy adott tábor kezdőnapjának sorszáma
101 v=sorszam(tab.h2,tab.n2); // egy adott tábor befejező napjának sorszáma
102 if((k<=s)&&(s<=v)) db++;
103 }
104 printf("Ekkor éppen %d tábor tart.\n",db);
105 }
106
107 bool honap_nap_szerint(tabor a, tabor b)
108 {
109 return ((a.h1<b.h1)||((a.h1==b.h1)&&(a.n1<b.n1)));
110 }
111
112 void F7(vector<tabor> t)
113 {
114 cout << "------------------------------------------------------" << endl;
115 cout << "7. feladat" << endl;
116 string tanulo;
117 cout << "Adja meg egy tanuló betűjelét: ";
118 cin >> tanulo;
119 vector<tabor> erdeklodes;
120 int poz;
121 for(auto tab:t)
122 {
123 poz=tab.diakok.find(tanulo);
124 if(poz>-1)
125 {
126 erdeklodes.push_back(tab);
127 }
128 }
129 sort(erdeklodes.begin(),erdeklodes.end(),honap_nap_szerint);
130 ofstream fki;
131 fki.open("egytanulo.txt");
132 for(auto tmp:erdeklodes)
133 fki << tmp.h1 << "." << tmp.n1 << "-" << tmp.h2 << "." << tmp.n2 << ". " << tmp.tema << endl;
134 fki.close();
135 bool utkozes=false;
136 for(int i=1;i<erdeklodes.size();i++)
137 {
138 if(sorszam(erdeklodes[i-1].h2,erdeklodes[i-1].n2)>=sorszam(erdeklodes[i].h1,erdeklodes[i].n1))
139 {
140 utkozes=true;
141 break;
142 }
143 }
144 if(utkozes) cout << "Nem mehet el mindegyik táborba." << endl;
145 }
146
147 int main()
148 {
149 setlocale(LC_ALL,"");
150 vector<tabor> taborok;
151 F1(taborok);
152 F2(taborok);
153 F3(taborok);
154 F4(taborok);
155
156 F6(taborok);
157 F7(taborok);
158 return 0;
159 }