Write to the end of .csv file

Pages: 123
The bad thing when you split the program and tell your team: "OK, you will write this part of code; and you, another part; and I will combine all of yours!" is that: they will write codes with their thought, using their own variables, and their on structs; therefore, it's very hard for you to combine all of them.
Here's what one of them had written:
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
#define MAX_STUDENT 100
#define MAX_COURSE 100

 struct student
{
	string No;
	string ID;
	string lastName;
	string firstName;
	string gender;
	string date;
};
struct course
{
	string course_No;
	string course_ID;
	string course_Name;
	string Class;
	string start;
	string lecture;
	string end;
	string start_hour;
	string end_hour;
	string room;
};
struct listStudent
{
	char class_name[20];
	int num_student;
	student students[MAX_STUDENT];
};
struct Class
{
	listStudent list_student[5];
};
struct listCourse
{
	char class_courses[20];
	course courses[MAX_COURSE];
	int num_coures;
};
struct allCourses
{
	listCourse list_courses[5];

};

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
bool saveStudent(const char *s, student a[], int num)
{
	ofstream q;
	q.open(s);
	if (!q.is_open())
		return false;
	else for (int i = 0; i < num; i++)
	{
		q << a[i].No << endl;
		q << a[i].ID << endl;
		q << a[i].lastName << endl;
		q << a[i].firstName << endl;
		q << a[i].gender << endl;
		q << a[i].date << endl;
	}
	q.close();
	return true;
}
removeStudent(int classnum, int nostu, Class &cla)
{
	if (classnum < 1 || classnum > 5)
		return 0;
	if (nostu > cla.list_student[classnum - 1].num_student || nostu < 1)
		return 0;

	for (int i = nostu - 1; i < cla.list_student[classnum - 1].num_student; i++)
	{
		cla.list_student[classnum - 1].students[i + 1].No -= 1;
		cla.list_student[classnum - 1].students[i] =
			cla.list_student[classnum - 1].students[i + 1];
	}
	cla.list_student[classnum - 1].num_student -= 1;

	saveStudent(cla.list_student[classnum - 1].class_name, cla.list_student[classnum - 1].students, cla.list_student[classnum - 1].num_student);

	return 1;
}
Last edited on
And here's my reading students and writing them to the .txt
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
void readStudents_andWrite(ifstream &in, ofstream &out, string in_file_name, string out_file_name, Student student[], size_t &index)
{
	in.open(in_file_name);
	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();
	}

	out.open(out_file_name);
	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 << student[i].no << " ";
			out << student[i].id << " ";
			out << student[i].last_name << " ";
			out << student[i].first_name << " ";
			out << student[i].gender << " ";
			out << student[i].dob << endl;
		}
		out.close();
	}
}

My structs:
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
#define MAX_STUDENT 100
#define MAX_COURSE 100

constexpr size_t MAXHEADINGS{ 6 };
constexpr size_t MAXSTUDENT{ 50 };
constexpr size_t MAXCOURSE{ 50 };

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;
};

struct Pass
{
	string no, user, pass;
};
struct listStudent
{
	char class_name[20];
	int num_student;
	Student students[MAX_STUDENT];
};

struct Class
{
	listStudent list_student[5];
};
struct listCourse
{
	char class_courses[20];
	Timetable courses[MAX_COURSE];
	int num_coures;
};
struct allCourses
{
	listCourse list_courses[5];

};

By the way, I have a outside-question.
Did you start your work by working with teammates like me? If you did, how can you bypass the problem which I would called "own codes, self-named structs, self-named variables"?
My thought is creating my structs and variables and they will use them.
Topic archived. No new replies allowed.
Pages: 123