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
|
#include <iostream>
#include <fstream>
#include <limits>
#include <string>
#include <iomanip>
using namespace std;
struct Student
{
string no, id, last_name, first_name, gender, dob;
};
struct Timetable
{
string courses_no, courses_id, lecture_account, class_name, lectures_account, start, end, day, start_hour, end_hour, room;
};
int main()
{
size_t index{}, tIndex{};
ifstream in;
in.open("E:/students.csv");
Student student[100];
string No, student_id, Last_name, First_name, Gender, DoB;
if (!in.is_open())
{
cout << "Error!\n";
}
else
{
getline(in, No, ',');
getline(in, student_id, ',');
getline(in, Last_name, ',');
getline(in, First_name, ',');
getline(in, Gender, ',');
getline(in, DoB, '\n');
while (getline(in, student[index].no, ','))
{
getline(in, student[index].id, ',');
getline(in, student[index].last_name, ',');
getline(in, student[index].first_name, ',');
getline(in, student[index].gender, ',');
getline(in, student[index++].dob, '\n');
}
in.close();
}
ofstream out;
out.open("E:/student.txt");
if (!out.is_open())
{
cout << "Error!\n";
}
else
{
out << No << " " << student_id << " " << Last_name << " " << First_name << " " << Gender << " " << DoB << endl;
for (int i = 0; i < index; i++)
{
out << right << setw(2) << student[i].no << " ";
out << left << setw(10) << student[i].id << " ";
out << setw(12) << student[i].last_name << " ";
out << setw(11) << student[i].first_name << " ";
out << setw(6) << student[i].gender << " ";
out << student[i].dob << endl;
}
out.close();
}
Timetable t[100];
string No_t, Course_ID, LectureAccount, Class, LecturesAccount, Start_Date, End_Date, Day_of_week, Start_hour, End_hour, Room;
in.open("E:/timetable.csv");
if (!in.is_open())
{
cout << "Error!\n";
}
else
{
getline(in, No_t, ',');
getline(in, Course_ID, ',');
getline(in, LectureAccount, ',');
getline(in, Start_Date, ',');
getline(in, End_Date, ',');
getline(in, Day_of_week, ',');
getline(in, Start_hour, ',');
getline(in, End_hour, ',');
getline(in, Room, '\n');
while (getline(in, t[tIndex].courses_no, ','))
{
getline(in, t[tIndex].courses_no, ',');
getline(in, t[tIndex].courses_id, ',');
getline(in, t[tIndex].lecture_account, ',');
getline(in, t[tIndex].start, ',');
getline(in, t[tIndex].end, ',');
getline(in, t[tIndex].day, ',');
getline(in, t[tIndex].start_hour, ',');
getline(in, t[tIndex].end_hour, ',');
getline(in, t[tIndex++].room, '\n');
}
in.close();
}
out.open("E:/timetable.txt");
if (!out.is_open())
{
cout << "Error!\n";
}
else
{
out << No_t << " " << Course_ID << " " << LectureAccount << " " << Start_Date << " " << End_Date << " " << Day_of_week << " " << Start_hour << " " << End_hour << " " << Room << endl;
for (int i = 0; i < tIndex; i++)
{
out << t[i].courses_no << " " << t[i].courses_id << " " << t[i].lecture_account << " " << t[i].start << " " << t[i].end << " " << t[i].day << " " << t[i].start_hour << " " << t[i].end_hour << " " << t[i].room << endl;
}
out.close();
}
string newLastName, newFirstName, newID, newGender, newDob;
cout << "Enter new ID: ";
cin >> newID;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
cout << "Enter new first name: ";
getline(cin, newFirstName);
cout << "Enter new last name: ";
getline(cin, newLastName);
cout << "Enter new gender: ";
cin >> newGender;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
cout << "Enter dob: ";
getline(cin, newDob);
student[index + 1].no = index + 1;
student[index + 1].id = newID;
student[index + 1].first_name = newFirstName;
student[index + 1].last_name = newLastName;
student[index + 1].gender = newGender;
student[index + 1].dob = newDob;
out.open("E:/students.csv", std::ios::app);
if (!out.is_open())
{
cout << "Error!\n";
}
else
{
out << student[index + 1].no << "," << student[index + 1].id << "," << student[index + 1].first_name << "," << student[index + 1].last_name << "," << student[index + 1].gender << "," << student[index + 1].dob << endl;
out.close();
}
system("pause");
}
|