Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unordered_map<int, string> topic_index_to_title_map_new;
- void change_mark(string login, int index_topic, int mark) {
- ifstream file;
- file.open("students.txt");
- int all_lines = 0;
- if (file.is_open()) {
- ofstream temp_file;
- temp_file.open("students_temp.txt", std::ios::app);
- string questions_to_replace = "";
- if (temp_file.is_open()) {
- string line;
- int login_divider = 13;
- while (getline(file, line)) {
- if (all_lines % login_divider == 0) {
- string subbed_login = line.substr(2, line.length());
- cout << subbed_login << endl;
- if (login == subbed_login) {
- cout << " marks for " << login << endl;
- temp_file << line << '\n';
- getline(file, line);
- temp_file << line << '\n';
- getline(file, line);
- temp_file << line << '\n';
- all_lines += 2;
- int curr_topic_index = 0;
- for (int i = 0; i < 8; i++) {
- getline(file, line);
- cout << "mark by " << topic_index_to_title_map_new[i] << " is " << line << endl;
- if (i == index_topic) {
- temp_file << to_string(mark) << '\n';
- all_lines++;;
- cout << "Change mark for " << topic_index_to_title_map_new[i] << " to " << mark << endl;
- }
- else {
- temp_file << line << '\n';
- all_lines++;;
- }
- }
- }
- else {
- temp_file << line << '\n';
- all_lines++;
- }
- } else {
- temp_file << line << '\n';
- all_lines++;
- }
- }
- temp_file.close();
- }
- }
- file.close();
- ofstream file2("students.txt", ofstream::trunc);
- file2.close();
- ifstream file_orig_r("students.txt");
- string test_str;
- while (getline(file_orig_r, test_str)) {
- cout << " read from orig file after truncating " << test_str << endl;
- }
- ofstream origfile("students.txt", std::ios::app);
- ifstream temp_file_r("students_temp.txt");
- string temp_line;
- int curr_line = 0;
- while (getline(temp_file_r, temp_line)) {
- if (curr_line == all_lines) {
- cout << "-2 line is " << temp_line;
- origfile << temp_line;
- }
- else {
- origfile << temp_line << '\n';
- }
- curr_line++;
- }
- ofstream temp_file_n("students_temp.txt", ofstream::trunc);
- temp_file_n.close();
- temp_file_r.close();
- origfile.close();
- }
- topic_index_to_title_map_new[0] = "Loop";
- topic_index_to_title_map_new[1] = "Array";
- topic_index_to_title_map_new[2] = "String";
- topic_index_to_title_map_new[3] = "Recursion";
- topic_index_to_title_map_new[4] = "Struct";
- topic_index_to_title_map_new[5] = "File";
- topic_index_to_title_map_new[6] = "Pointers";
- topic_index_to_title_map_new[7] = "Dynamic";
- string login = "loginK9877";
- change_mark(login, 4, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement