How to modify my student records using vectors

hello, I am trying to do an assignment and I am stuck on trying to figure out how to correctly modify the data inputted via vectors. so for example if inputted John Doe Math101 5 and would like to modify the record to Jane Doe Math 102 6. thank you and hope to hear back!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// function modifies student record
void modifyStudent(
	vector<string> &name,
	vector<string> &course,
	vector<string> &section) {
	string theName = "";
	string theCourse = "";
	string theSection = "";

	cout << endl << "Enter the student name to modify: " << endl;
	getline(cin, theName);
        cout << "Enter " << theName << "'s course: " << endl;
	getline(cin, theCourse);
	cout << "Enter " << theName << "'s section: " << endl;
	getline(cin, theSection);

} // end modify student records 
Hello vlopez13,

Having no idea what is required by the assignment, You should post what you were given for the asssignment. And not what you think it means.

Unless 3 vectors are required consider this:
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
struct Student
{
    std::string sName;
    std::string sCourse;
    std::string sSection;
};

void modifyStudent(std::vector<Student>/*vector<string> &name, vector<string> &course, vector<string> &section*/)
{
    std::string theName = "";
    std::string theCourse = "";
    std::string theSection = "";

    std::cout << '\n' << "Enter the student name to modify: ";  // <--- Set up this way puts the input on the same line.
    std::getline(std::cin, theName);

    std::cout << "Enter " << theName << "'s course: ";
    std::getline(std::cin, theCourse);

    std::cout << "Enter " << theName << "'s section: ";
    std::getline(std::cin, theSection);

    /* Find the vector element that contains the student information to modify.
       Input the new information.
       Modify the the proper element.
    */
} // end modify student records. 

This is much easier to work with than trying to deal with 3 separate vectors. # vectors can work I just need to know what you have to use.

The first input is fine to find the element of the vector that you need. The next 2 may work better after you find the correct element. That is if you use the struct.

Andy
Hi Handy Andy, so the assignment is simply to build a student records database, that can be used to add, list, modify, and delete the records generated by the user. i will link the full code
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include <iostream>
#include <string>
#include <vector>
using namespace std;


int main() {
   //this security only allows 3 attempts before terminating the program
    string accountName;
    accountName = "admin";
    string accountPass;
    accountPass = "1234";
    string loginName;
    string loginPassword;
    int loginAttempt = 0;

    while (loginAttempt < 3)
    {
        
    cout << "Enter login name: ";
    cin >> loginName;
    cout << "Enter password: ";
    cin >> loginPassword;
    if (loginName == accountName && loginPassword == accountPass) 
  {
    cout << "Hello " << loginName << ", Welcome to the ... " << endl;
    break;
  }
      else
    {
      cout << "Invalid login attempt. Please try again.\n" << '\n';
      loginAttempt++;
    }
  }
      if (loginAttempt == 3)
    {
      cout << "Too many login attempts! The program will now terminate.";
      return 0;
    }
	// function protypes
	void addStudent(
		vector<string> & name,
		vector<string> & course,
		vector<string> & section);
	void deleteStudent(
		vector<string> & name,
		vector<string> & course,
		vector<string> & section);
	void modifyStudent(
		vector<string> & name,
		vector<string> & course,
		vector<string> & section);
	void listStudent(
		vector<string> & name,
		vector<string> & course,
		vector<string> & section);
	char getAction(string prompt);

	const char exitProgram = '5'; // 5 to exit program
	cout << "\n\t= * = STUDENT DATABASE MANAGEMENT SYSTEM = * =" << endl;
	const string prompt = "\n \t\t\t 1. Add Records"
						  "\n \t\t\t 2. List Records"
						  "\n \t\t\t 3. Modify Records"
						  "\n \t\t\t 4. Delete Records"
						  "\n \t\t\t 5. Exit Program"
						  "\n\n"
						  "\t\t\t Select Your Choice: ";

	vector<string> name(0);
	vector<string> course(0);
	vector<string> section(0);

	char userAction = '?';

	// Loop until the user enters the exit code.
	userAction = getAction(prompt);

	while (userAction != exitProgram) {
		switch (userAction) {
		case '1':
			cout << "\nADD STUDENT:\n------------\n";
			addStudent(name, course, section);
			break;
		case '2':
			cout << "\nLIST ALL STUDENTS:\n------------------\n";
			listStudent(name, course, section);
			break;
		case '3': // come back to this
			cout << "\nMODIFY STUDENT:\n---------------\n";
			modifyStudent(name, course, section);
			break;
		case '4':
			cout << "\nDELETE STUDENT:\n---------------\n";
			deleteStudent(name, course, section);
			break;
		default:
			cout << "\nInvalid selection!\n";
			break;
		} // end switch

		userAction = getAction(prompt);
	} // end while
	return 0;
}

// Adds  student
void addStudent(
	vector<string> &name,
	vector<string> &course,
	vector<string> &section) {
	string theName{""};
	string theCourse{""};
	string theSection{""};

	cout << endl << "Enter the student name to add: ";
	getline(cin, theName);
	cout << "\nEnter " << theName << "'s course: ";
	getline(cin, theCourse);
	cout << "\nEnter " << theName << "'s section: ";
	getline(cin, theSection);

	name.push_back(theName);
	course.push_back(theCourse);
	section.push_back(theSection);

	cout << theName << "'s information has been added." << endl;

	return;
}

void listStudent(
	vector<string> &name,
	vector<string> &course,
	vector<string> &section) {
	int nElements = 0;

	nElements = name.size();
	if (nElements > 0) {
		cout << endl;
		for (int i = 0; i < nElements; ++i) {
			cout << i << ") Name: " << name.at(i)
				 << ",\tCourse: " << course.at(i)
				 << ",\tSection: " << section.at(i) << endl;
		}
	} else {
		cout << endl << "there are no students to list." << endl;
	}
	return;
} // end listStudents

// function modifies student record
// function modifies student record
void modifyStudent(
	vector<string> &name,
	vector<string> &course,
	vector<string> &section) {
	string theName = "";
	string theCourse = "";
	string theSection = "";

	cout << endl << "Enter the student name to modify: " << endl;
	getline(cin, theName);
        cout << "Enter " << theName << "'s course: " << endl;
	getline(cin, theCourse);
	cout << "Enter " << theName << "'s section: " << endl;
	getline(cin, theSection);

} // end modify student records 

// function deletes student records
void deleteStudent(
	vector<string> &name,
	vector<string> &course,
	vector<string> &section) {
	string theName = "";
	string theCourse = "";
	string theSection = "";

	cout << endl << "Enter the student name to delete: " << endl;
	getline(cin, theName);
	cout << "Enter " << theName << "'s course: " << endl;
	getline(cin, theCourse);
	cout << "Enter " << theName << "'s section: " << endl;
	getline(cin, theSection);

	int i = name.size() - 1;
	int any = 0;
	for (; i >= 0; --i) {
		if (name[i] == theName && course[i] == theCourse &&
			section[i] == theSection) {
			name.erase(name.begin() + i);
			course.erase(course.begin() + i);
			section.erase(section.begin() + i);
			any++;
		}
	}
	if (any > 0) {
		cout << theName << "'s information has been deleted." << endl;
	} else {
		cout << theName << "'s info has not been found." << endl;
	}
	return;
}

// Get the action the user wants to perform

char getAction(string prompt) {
	string answer = ""; // empty string

	char firstChar = '?';
	cout << endl << prompt << endl;
	getline(cin, answer);

	while (answer.length() == 0) {
		getline(cin, answer);
	}

	firstChar = toupper(answer[0]); // change first char to uppercase

	return firstChar;
}
Hello vlopez13,

A quick look at the whole. The function prototypes, I believe these days they are referred to as forward declarations, should be above "main" not in "main".

I still think the best solution is to create a struct and a vector of structs. This way each element of the vector is an individual struct containing all the information on 1 student. Much easier to deal with.

Just playing around with what you started with I came up with. Not finished yet, but see what you think:
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
#include <iostream>
#include <string>
#include <vector>

using uInt = unsigned int;

constexpr uInt MAXSIZE{ 5 };

struct Student
{
    std::string sName;
    std::string sCourse;
    std::string sSection;
};

void modifyStudent(std::vector<Student>& students)
{
    std::string theName, newName;
    std::string theCourse, newCourse;
    std::string theSection, newSection;

    std::cout << '\n' << "Enter the student name to modify: ";  // <--- Set up this way puts the input on the same line.
    std::getline(std::cin, theName);

    uInt index{};

    for (size_t idx = 0; idx < students.size(); idx++)
    {
        if (students[idx].sName == theName)
        {
            index = idx;
            break;
        }
        else
        {
            index = -1;
        }
    }

    if (index == -1)
    {
        std::cerr << "\n    Record not found!  Check your spelling.\n\n";

        return;
    }
    else
    {
        std::cout <<
            "\n    Name: " << students[index].sName <<
            "\n  Course: " << students[index].sCourse <<
            "\n Section: " << students[index].sSection << '\n';
    }

    std::cout << '\n' << "Enter the new student name to modify (blank to leave as is): ";
    std::getline(std::cin, newName);

    std::cout << "Enter " << theName << "'s course (blank to leave as is): ";
    std::getline(std::cin, newCourse);

    std::cout << "Enter " << theName << "'s section (blank to leave as is): ";
    std::getline(std::cin, theSection);

    if (!newName.empty())
    {
        students[index].sName = newName;
    }

    return; // <--- Used as a break point for testing. Remove when finished.
} // end modify student records.

int main()
{
    std::vector<Student> students
    {
        { "Navarre", "Math101", "5" },
        { "Isabeau", "Math102", "5" },
        { "Imperius", "Engl101", "3" },
        { "Arya", "Scie103", "4" },
        { "Saphira", "Engr103", "4" }
    };

    modifyStudent(students);

    return 0;  // <--- Not required, but makes a good break point.
}


I will load up your code and see what happens.

Andy
Hi Andy, this might work for me, if I can incorporate it into the existing code, as i cant have prefixed students, which i guess were created for testing purposes.
I've cleaned up the structure of the code and sorted out the compile errors. This code now compiles OK. The logic for modifyStudent() needs to be completed and the other functions tested.

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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void addStudent(vector<string>& name, vector<string>& course, vector<string>& section);
void deleteStudent(vector<string>& name, vector<string>& course, vector<string>& section);
void modifyStudent(vector<string>& name, vector<string>& course, vector<string>& section);
void listStudent(const vector<string>& name, const vector<string>& course, const vector<string>& section);
char getAction(const string& prompt);
bool login();

int main() {
	if (!login())
		return 1;

	vector<string> name;
	vector<string> course;
	vector<string> section;

	const char exitProgram {'5'}; // 5 to exit program
	const string prompt {"\n \t\t\t 1. Add Records"
		"\n \t\t\t 2. List Records"
		"\n \t\t\t 3. Modify Records"
		"\n \t\t\t 4. Delete Records"
		"\n \t\t\t 5. Exit Program"
		"\n\n"
		"\t\t\t Select Your Choice: "};

	cout << "\n\t= * = STUDENT DATABASE MANAGEMENT SYSTEM = * =\n";

	// Loop until the user enters the exit code.
	for (char userAction; (userAction = getAction(prompt)) != exitProgram; ) {
		switch (userAction) {
			case '1':
				cout << "\nADD STUDENT:\n------------\n";
				addStudent(name, course, section);
				break;

			case '2':
				cout << "\nLIST ALL STUDENTS:\n------------------\n";
				listStudent(name, course, section);
				break;

			case '3': // come back to this
				cout << "\nMODIFY STUDENT:\n---------------\n";
				modifyStudent(name, course, section);
				break;

			case '4':
				cout << "\nDELETE STUDENT:\n---------------\n";
				deleteStudent(name, course, section);
				break;

			default:
				cout << "\nInvalid selection!\n";
				break;
		} // end switch
	} // end while
}

bool login()
{
	static const string accountName {"admin"};
	static const string accountPass {"1234"};

	size_t loginAttempt {};

	for (string loginName, loginPassword; loginAttempt < 3; ++loginAttempt) {
		cout << "Enter login name: ";
		cin >> loginName;

		cout << "Enter password: ";
		cin >> loginPassword;

		if (loginName == accountName && loginPassword == accountPass) {
			cout << "Hello " << loginName << ", Welcome to the ... \n";
			return true;
		}

		cout << "Invalid login attempt. Please try again.\n";
	}

	cout << "Too many invalid login attempts! The program will now terminate.\n";
	return false;
}

// Adds  student
 void addStudent(vector<string>& name, vector<string>& course, vector<string>& section) {
	string theName;
	string theCourse;
	string theSection;

	cout << "\nEnter the student name to add: ";
	getline(cin, theName);

	cout << "\nEnter " << theName << "'s course: ";
	getline(cin, theCourse);

	cout << "\nEnter " << theName << "'s section: ";
	getline(cin, theSection);

	name.push_back(theName);
	course.push_back(theCourse);
	section.push_back(theSection);

	cout << theName << "'s information has been added.\n";
}

void listStudent(const vector<string>& name, const vector<string>& course, const vector<string>& section) {
	const auto nElements {name.size()};

	if (nElements > 0) {
		cout << '\n';

		for (size_t i = 0; i < nElements; ++i) {
			cout << i << ") Name: " << name.at(i)
				<< ",\tCourse: " << course.at(i)
				<< ",\tSection: " << section.at(i) << endl;
		}
	} else
		cout << endl << "there are no students to list." << endl;

} // end listStudents

// function modifies student record
void modifyStudent(vector<string>& name, vector<string>& course, vector<string>& section) {
	string theName;
	string theCourse;
	string theSection;

	cout << "\nEnter the student name to modify: ";
	getline(cin, theName);

	cout << "Enter " << theName << "'s course: ";
	getline(cin, theCourse);

	cout << "Enter " << theName << "'s section: ";
	getline(cin, theSection);

} // end modify student records

// function deletes student records
void deleteStudent(vector<string>& name, vector<string>& course, vector<string>& section) {
	string theName;
	string theCourse;
	string theSection ;

	cout << endl << "\nEnter the student name to delete: ";
	getline(cin, theName);

	cout << "Enter " << theName << "'s course: ";
	getline(cin, theCourse);

	cout << "Enter " << theName << "'s section: ";
	getline(cin, theSection);

	auto i {name.size() - 1};
	size_t any {};

	for (; i > 0; --i)
		if (name[i] == theName && course[i] == theCourse && section[i] == theSection) {
			name.erase(name.begin() + i);
			course.erase(course.begin() + i);
			section.erase(section.begin() + i);
			++any;
		}

	if (any > 0)
		cout << theName << "'s information has been deleted.\n";
	else
		cout << theName << "'s info has not been found.\n";
}

// Get the action the user wants to perform
char getAction(const string& prompt) {
	string answer;

	cout << '\n' << prompt << '\n';

	while (getline(cin, answer) && answer.empty());

	return static_cast<char>(toupper(static_cast<unsigned char>(answer[0]))); // change first char to uppercase
}


Hello vlopez13,

Yes I initialized the vector for testing. It beats typing everything over and over each time you test the program. Also you can still add to the vector anything new with the add function.

Going through your code I noticed things like: string answer = ""; // empty string . The (= "") is not necessary. string answer; // empty string defines a (0)zero length string or an empty string. The (= "") produces the same thing, so adding this part has no advantage.

I also noticed you wrote: vector<string> & name, and vector<string> &name,. The position of the "&" makes no difference to the compiler, but it is nicer to be consistent in the way that you use them.

Consider leaving off the "endl" at the end of a prompt. This will put your input on the same line as the prompt, which to me, it looks nicer.

In other places try to use the new line (\n) in place of the function "endl", which takes time to call and process. At some point changes to the 2011 or 2014 standards, I think it is updates to the 2011 standards, allow the (\n) to work the same as calling "flush" or "endl". Also any "cout" followed by a "cin" the "cin" will flush the buffer before any input is taken. This you can use to your advantage.

I never did like using the (\t). It may be quick and easy, but does not always space things the way you are thinking. Especially when the (\t) is in the middle of a string or used to space columns.

As an alternative I did this:
1
2
3
4
5
6
7
8
9
10
11
12
13
std::string space(25, ' ');

const string prompt
{
    "\n"
    + space + "1. Add Records\n"
    + space + "2. List Records\n"
    + space + "3. Modify Records\n"
    + space + "4. Delete Records\n"
    + space + "5. Exit Program"
    "\n\n"
    + space + "Select Your Choice: "
};

The first line uses the fill ctor of the string class to define a string of 25 spaces. Just a thought.

In your "listStudents" function you wrote: if (nElements > 0). You could just as easily say: if (nElements). Since any number greater than (0)zero is converted to a bool variable of 1 for true. Should the variable be (0)zero it would go to the else part.

In your delete function consider this:
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
//int i = name.size() - 1;  // <--- There is no reason for this just to go backwards.
int any = 0;  // <--- Could define as a bool.
bool deleted{};

for (; i >= 0; --i)  // <--- Or for (size_t i{}; i < name.size(); i++) 
{
    if (name[i] == theName && course[i] == theCourse &&
        section[i] == theSection)
    {
        name.erase(name.begin() + i);
        course.erase(course.begin() + i);
        section.erase(section.begin() + i);
            
        any++;

        deleted = true;

        break;  // <--- Once you delete there is no point in processing the rest of the vector.
    }
}

if (any > 0) // if (deleted)
{
    cout << theName << "'s information has been deleted.\n";
}


Andy
I'm a little confused on what modifyStudent() should do. I assume that one student can have several records in the database, so don't you need to know the old course/section number AND the new course/section number?

Also, consider adding some object orientation. Some of these code can be methods of the Student class. You could also add a new class that represents the database of Students. If you haven't learned about methods yet then just ignore this.

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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using std::cin;
using std::cout;
using std::vector;
using std::string;

// Get the action the user wants to perform
char getAction();

// Prompt for login and password up to "maxAttempts" times.
// Return true if the login/password are valid
bool login( int maxAttempts);

// Show the program banner
void showBanner();

class Record {
public:
    string name, course;
    int section;
    bool operator==(const Record &rhs);
    void input();		// prompt user and read a record
    void list();		// print it to cout
};

class Database {
    vector<Record> records;
public:
    void add();
    void del();
    void modify();
    void list();
};


int
main()
{
    //this security only allows 3 attempts before terminating the program
    if (!login(3)) {
	cout << "Too many login attempts! The program will now terminate.";
	return 0;
    }
	
    cout << "\n\t= * = STUDENT DATABASE MANAGEMENT SYSTEM = * =" << '\n';

    // Loop until the user enters the exit code.
    Database records;
    char userAction;
    do {
	userAction = getAction();
	switch (userAction) {
	case '1':
	    cout << "\nADD STUDENT:\n------------\n";
	    records.add();
	    break;
	case '2':
	    cout << "\nLIST ALL STUDENTS:\n------------------\n";
	    records.list();
	    break;
	case '3':				 // come back to this
	    cout << "\nMODIFY STUDENT:\n---------------\n";
	    records.modify();
	    break;
	case '4':
	    cout << "\nDELETE STUDENT:\n---------------\n";
	    records.del();
	    break;
	case '5':		// Exit code
	    break;
	default:
	    cout << "\nInvalid selection!\n";
	    break;
	}					 // end switch
    } while (userAction != '5');		 // end do/while
    return 0;
}

bool
Record::operator ==(const Record &rhs)
{
    return (name == rhs.name && course == rhs.course && section == rhs.section);
}

void
Record::input()
{
    cout << "Enter the student name: ";
    getline(cin, name);
    cout << "Enter " << name << "'s course: ";
    getline(cin, course);
    cout << "Enter " << name << "'s section: ";
    cin >> section;
    cin.ignore(1000000000, '\n'); // skip past the new line
}

void
Record::list()
{
    cout << "Name: " << name
	 << ",\tCourse: " << course
	 << ",\tSection: " << section << '\n';
}


// Prompt for login and password. validate them and return true if
// valid and false if not.
bool login( int maxAttempts)
{
    string accountName;
    accountName = "admin";
    string accountPass;
    accountPass = "1234";
    string loginName;
    string loginPassword;

    for (int loginAttempt = 0; loginAttempt < maxAttempts; ++loginAttempt) {
	cout << "Enter login name: ";
	cin >> loginName;
	cout << "Enter password: ";
	cin >> loginPassword;
	if (loginName == accountName && loginPassword == accountPass) {
	    cout << "Hello " << loginName << ", Welcome to the ... " << '\n';
	    return true;
	}
	cout << "Invalid login attempt. Please try again.\n" << '\n';
    }
    return false;
}

// Adds  student
void
Database::add()
{
    Record r;
    r.input();
    records.push_back(r);
    cout << r.name << "'s information has been added." << '\n';
}

void
Database::list()
{
    if (records.size()) {
	for (Record &r : records) {
	    r.list();
	}
    } else {
	cout << '\n' << "there are no students to list." << '\n';
    }
}

void
Database::modify()
{
    Record r;
    r.input();
    auto pos = std::find(records.begin(), records.end(), r);

    if (pos == records.end()) {
	cout << "Can't find that record\n";
	return;
    }

    cout << "Enter the new information:\n";
    r.input();
    *pos = r;
}

// function deletes student records
void
Database::del()
{
    Record r;
    r.input();
    // http://www.cplusplus.com/reference/algorithm/remove/
    auto pos = std::remove(records.begin(), records.end(), r);
    if (pos == records.end()) {
	cout << "Can't find that record to remove.\n";
    } else {
	// http://www.cplusplus.com/reference/vector/vector/erase/
	records.erase(pos);
    }
}

// Get the action the user wants to perform
char
getAction()
{
    cout << "\n\n \t\t\t 1. Add Records"
	"\n \t\t\t 2. List Records"
	"\n \t\t\t 3. Modify Records"
	"\n \t\t\t 4. Delete Records"
	"\n \t\t\t 5. Exit Program" "\n\n" "\t\t\t Select Your Choice:\n";

    string answer;		// empty string
    char firstChar = '?';
    getline(cin, answer);

    while (answer.length() == 0) {
	getline(cin, answer);
    }

    firstChar = toupper(answer[0]);		 // change first char to uppercase

    return firstChar;
}

Topic archived. No new replies allowed.