void
update_recode()
{
fstream fin, fout;
fin.open(
"reportcard.csv"
, ios::in);
fout.open(
"reportcardnew.csv"
, ios::out);
int
rollnum, roll1, marks, count = 0, i;
char
sub;
int
index, new_marks;
string line, word;
vector<string> row;
cout <<
"Enter the roll number "
<<
"of the record to be updated: "
;
cin >> rollnum;
cout <<
"Enter the subject "
<<
"to be updated(M/P/C/B): "
;
cin >> sub;
if
(sub ==
'm'
|| sub ==
'M'
)
index = 2;
else
if
(sub ==
'p'
|| sub ==
'P'
)
index = 3;
else
if
(sub ==
'c'
|| sub ==
'C'
)
index = 4;
else
if
(sub ==
'b'
|| sub ==
'B'
)
index = 5;
else
{
cout <<
"Wrong choice.Enter again\n"
;
update_record();
}
cout <<
"Enter new marks: "
;
cin >> new_marks;
while
(!fin.eof()) {
row.clear();
getline(fin, line);
stringstream s(line);
while
(getline(s, word,
', '
)) {
row.push_back(word);
}
roll1 = stoi(row[0]);
int
row_size = row.size();
if
(roll1 == rollnum) {
count = 1;
stringstream convert;
convert << new_marks;
row[index] = convert.str();
if
(!fin.eof()) {
for
(i = 0; i < row_size - 1; i++) {
fout << row[i] <<
", "
;
}
fout << row[row_size - 1] <<
"\n"
;
}
}
else
{
if
(!fin.eof()) {
for
(i = 0; i < row_size - 1; i++) {
fout << row[i] <<
", "
;
}
fout << row[row_size - 1] <<
"\n"
;
}
}
if
(fin.eof())
break
;
}
if
(count == 0)
cout <<
"Record not found\n"
;
fin.close();
fout.close();
remove
(
"reportcard.csv"
);
rename
(
"reportcardnew.csv"
,
"reportcard.csv"
);
}