-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegistrationList.cpp
More file actions
71 lines (62 loc) · 2.39 KB
/
RegistrationList.cpp
File metadata and controls
71 lines (62 loc) · 2.39 KB
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
// RegistrationList.cpp
#include "RegistrationList.h"
#include "RegistrationEntry.h"
#include <fstream>
using std::ifstream;
using std::ofstream;
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <map>
using std::pair;
#include <string>
using std::string;
void RegistrationList::read_file(const string & file_name) {
ifstream ifs(file_name);
if (!ifs) return; // no file; one will be created when
// write_file is called
ifs >> num_entries;
ifs.get(); // \n
for (int i = 0; i < num_entries; i++) {
RegistrationEntry new_entry;
ifs >> new_entry;
m_entries.insert(m_entries.end(),{new_entry.name, new_entry});
}
itr_current_entry = m_entries.begin();
}
void RegistrationList::write_file(const string & file_name) const {
string update_file_name = "registration_list.txt";
ofstream ofs_output(update_file_name);
ofs_output << m_entries.size() << endl;
//ofs_output << current_year << endl;
for (auto itr_current_entry = m_entries.begin(); itr_current_entry != m_entries.end(); itr_current_entry++) {
ofs_output << itr_current_entry->second;
}
}
//**** Backup ****//
void RegistrationList::write_file_backup(const string & file_name) const {
string backup_file_name = "registration_backup.txt";
ofstream ofs_output_backup(backup_file_name);
ofs_output_backup << m_entries.size() << endl;
//ofs_output_backup << current_year << endl;
for (auto itr_current_entry = m_entries.begin(); itr_current_entry != m_entries.end(); itr_current_entry++) {
ofs_output_backup << itr_current_entry->second;
}
cout << "\nThe Registration List has been backed up and saved as '" << backup_file_name << "'.\n";
}
//**** List for Category ****//
void RegistrationList::write_file_list_cat(const string & filename) const {
cout << "Please enter a filename (ex. 'U14List.txt'): ";
string cat_file_name;
getline(cin, cat_file_name);
cout << "Please enter the category (ex. 'U14'): ";
string category;
cin >> category;
ofstream ofs_output_cat(cat_file_name);
for (auto itr_current_entry = m_entries.begin(); itr_current_entry != m_entries.end(); itr_current_entry++){
if (itr_current_entry->second == category){
ofs_output_cat << itr_current_entry->second;
}
}
}