1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
#include <iostream>
#include <string>
#include <fstream>
#define MAX_SUBJECTS 10
using namespace std;
struct Subjects
{
string id, w1, w2, w3, w4, w5, w6, w7, w8;
};
void readCheckin(ifstream &in, const string path, Subjects s[], size_t &index)
{
in.open(path);
if (!in)
{
cout << "Can't open!\n";
}
string heading;
getline(in, heading, '\n');
while (getline(in, s[index].id, ','))
{
getline(in, s[index].w1, ',');
getline(in, s[index].w2, ',');
getline(in, s[index].w3, ',');
getline(in, s[index].w4, ',');
getline(in, s[index].w5, ',');
getline(in, s[index].w6, ',');
getline(in, s[index].w7, ',');
getline(in, s[index++].w8, '\n');
}
in.close();
}
void Checkin(ofstream &out, const string path, Subjects s[], size_t &index)
{
system("cls");
string ID;
cout << "Enter the ID to check-in: ";
cin >> ID;
system("cls");
for (int i = 0; i < index; i++)
{
if (s[i].id == ID)
{
int c;
cout << "1. W1\n" << "2. W2\n" << "3. W3\n" << "4. W4\n" << "5. W5\n" << "6. W6\n" << "7. W7\n" << "8. W8\n";
cout << "Choose: ";
cin >> c;
system("cls");
cout << "Enter 0 (absented) or 1 (attended)\n";
string W1, W2, W3, W4, W5, W6, W7, W8;
switch (c)
{
case 1:
cin >> W1;
s[i].w1 = W1;
break;
case 2:
cin >> W2;
s[i].w2 = W2;
break;
case 3:
cin >> W3;
s[i].w2 = W2;
break;
case 4:
cin >> W4;
s[i].w4 = W4;
break;
case 5:
cin >> W5;
s[i].w5 = W5;
break;
case 6:
cin >> W6;
s[i].w6 = W6;
break;
case 7:
cin >> W7;
s[i].w7 = W7;
break;
case 8:
cin >> W8;
s[i].w8 = W8;
break;
}
}
}
out.open(path);
if (!out)
{
cout << "Error\n";
}
out << "Student ID,1,2,3,4,5,6,7,8\n";
for (int i = 0; i < index; i++)
{
out << s[i].id << "," << s[i].w1 << "," << s[i].w2 << ","
<< s[i].w3 << "," << s[i].w4 << "," << s[i].w5 << ","
<< s[i].w6 << "," << s[i].w7 << "," << s[i].w8 << endl;
}
out.close();
}
int main()
{
string CLC1[]{ "E:/cth008clc1.csv", "E:/tth026clc1.csv", "E:/ctt010clc1.csv", "E:/kth001clc1.csv", "E:/cth001clc1.csv" };
Subjects CTT008clc1[MAX_SUBJECTS], TTH026clc1[MAX_SUBJECTS], CTT010clc1[MAX_SUBJECTS], KTH001clc1[MAX_SUBJECTS], CTH001clc1[MAX_SUBJECTS];
ifstream ctt008clc1, tth026clc1, ctt010clc1, kth001clc1, cth001clc1;
ofstream out1, out2, out3, out4, out5;
size_t ctt008{}, tth026{}, ctt010{}, kth010{}, kth001{}, cth001{};
for (int i = 0; i < CLC1->size(); i++)
{
switch (i)
{
case 0:
readCheckin(ctt008clc1, CLC1[i], CTT008clc1, ctt008);
break;
case 1:
readCheckin(tth026clc1, CLC1[i], TTH026clc1, tth026);
break;
case 2:
readCheckin(ctt010clc1, CLC1[i], CTT010clc1, ctt010);
break;
case 3:
readCheckin(kth001clc1, CLC1[i], KTH001clc1, kth001);
break;
case 4:
readCheckin(cth001clc1, CLC1[i], CTH001clc1, cth001);
break;
}
}
int c;
cout << "1. 18clc1\n" << "2. 18clc2\n" << "3. 18clc3\n" << "4. 18clc4\n" << "5. 18clc5\n";
cout << "Choose class: ";
cin >> c;
system("cls");
if (c == 1)
{
int s;
cout << "1. CTT008\n" << "2. TTH026\n" << "3. CTT010\n" << "4. KTH001\n" << "5. CTH001\n";
cout << "Enter subject: ";
cin >> s;
switch (s)
{
case 1:
Checkin(out1, CLC1[0], CTT008clc1, ctt008);
break;
case 2:
Checkin(out2, CLC1[1], TTH026clc1, tth026);
break;
case 3:
Checkin(out3, CLC1[2], CTT010clc1, ctt010);
break;
case 4:
Checkin(out4, CLC1[3], KTH001clc1, kth001);
break;
case 5:
Checkin(out5, CLC1[4], CTH001clc1, cth001);
break;
}
}
}
|