forked from CSUF-CPSC-131-Fall2019/Data-Structures-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtendableVector_main.cpp
More file actions
60 lines (47 loc) · 1.41 KB
/
ExtendableVector_main.cpp
File metadata and controls
60 lines (47 loc) · 1.41 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
#include <iostream>
#include <string>
#include "ExtendableVector.hpp"
using std::cout;
using std::string;
using std::ostream;
using std::endl;
class Student {
private:
string name_;
int numOfSemesters_;
public:
Student() = default;
Student (string name, int nsem=1): name_(name), numOfSemesters_(nsem) {}
void updateNSemesters() {
numOfSemesters_++;
}
friend ostream& operator<<(ostream& os, const Student& student);
};
ostream& operator<<(ostream& os, const Student& student) {
os << "Name: " << student.name_;
os << ". No. of semesters= " << student.numOfSemesters_ << endl;
return os;
}
int main() {
ExtendableVector<Student> studentVector; // capacity is not specified
Student s("Adam", 2);
studentVector.push_back(s);
studentVector.push_back(Student("Bob", 1));
studentVector.push_back(Student("Dolores", 3));
for (size_t i = 0; i < studentVector.size(); i++) {
cout << studentVector[i];
}
// add student Carla between Bob and Dolores
studentVector.insert(2, Student("Carla"));
for (size_t i = 0; i < studentVector.size(); i++) {
cout << studentVector[i];
}
// update Carla's record
studentVector[2].updateNSemesters();
cout << studentVector[2];
// remove student Adam (element at index 0)
studentVector.erase(0);
for (size_t i = 0; i < studentVector.size(); i++) {
cout << studentVector[i];
}
}