Professional Documents
Culture Documents
Activity
CC2-1-Fundamentals of Programming/ CC2-Computer Programming 1
Module 16 – Vector Type
Background
The lesson discussed vector data type. Vector solve some limitations of using array as data structure,
since the size of vector data type can grow and shrink depending on the number of elements you put
into it. Vector implementation in C++ was implemented as class, therefore we can use various methods
of vector class to manipulate vectors.
Task
Now your task is, to think of one simple programming problem that you think is solvable using vector.
State the problem as comment on the top of your source code, and the algorithm you use to solve the
problem.
Sample Output
Say, we want to calculate the average of grades the students got for their projects. The number of
scores may vary from student to student since some students might not able to submit their project.
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
int main() {
vector<string> student;
vector<vector<float>> scores;
getStudentData(student, scores);
printStudentData(student, scores);
return 0;
}
cout << "Input the scores, you can input -1 if you're done entering the last "
<< "score.\n";
float score = 0;
vector<float> s;
scr.push_back(s);
}
cout << left << setw(10) << "Name" << left << setw(40) << "Scores" << left;
cout << endl;
cout << right << setw(10) << "Average: " << fixed << setprecision(2)
<< sum / j;
Submission