-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvectors.cpp
76 lines (53 loc) · 2.36 KB
/
vectors.cpp
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
#include <iostream>
#include <vector> // don't forget this in order to use vectors
using namespace std;
int main() {
cout << "----------------------------------------------------------" << endl;
vector <char> my_letters {'a' , 'b', 'c', 'd', 'e'};
cout << my_letters[0] << endl;
cout << my_letters[4] << endl;
/*
cout << "----------------------------------------------------------" << endl;
vector <int> my_test_scores (3); // 3 elements all initialized to zero
//vector <int> my_test_scores (3, 100); // 3 elements all initialized to 100
//vector <int> my_test_scores {15,22,87};
cout << "\nTest scores using array syntax:" << endl;
cout << my_test_scores[0] << endl;
cout << my_test_scores[1] << endl;
cout << my_test_scores[2] << endl;
cout << "\nTest scores using vector syntax:" << endl;
cout << my_test_scores.at(0) << endl;
cout << my_test_scores.at(1) << endl;
cout << my_test_scores.at(2) << endl;
cout << "\nThere are " << my_test_scores.size() << " scores in the vector" << endl;
cout << "\nEnter 3 test scores: ";
cin >> my_test_scores.at(0);
cin >> my_test_scores.at(1);
cin >> my_test_scores.at(2);
cout << "\nUpdated test scores: " << endl;
cout << my_test_scores.at(0) << endl;
cout << my_test_scores.at(1) << endl;
cout << my_test_scores.at(2) << endl;
*/
//================================================
/*
cout << "----------------------------------------------------------" << endl;
cout << "\nEnter a test score to add to the vector: ";
int score_to_add {0};
cin >> score_to_add;
my_test_scores.push_back(score_to_add);
cout << "\nEnter one more test score to add to the vector: ";
cin >> score_to_add;
my_test_scores.push_back(score_to_add);
cout << "\nTest scores are now: " << endl;
cout << my_test_scores.at(0) << endl;
cout << my_test_scores.at(1) << endl;
cout << my_test_scores.at(2) << endl;
cout << my_test_scores.at(3) << endl;
cout << my_test_scores.at(4) << endl;
cout << "\nThere are now " << my_test_scores.size() << " scores in the vector" << endl;
*/
//cout << "This may or may not cause an exception!!" << my_test_scores[10]<< endl;
//cout << "This should cause an exception!!" << my_test_scores.at(10) << endl;
return 0;
}