Saturday, March 3, 2007

March 6, 2007

A. Goal: Better understanding of the vector STL

B. Result:

The Program

The blog thinks the angle brackets are HTML code and deesn't display whatever follows the include, so I left them out in the blog. They were in the original program. There are angle brackets missing in several places for the purpose of the blog.

#include iostream
#include iomanip
#include vector

using namespace std;

int main ()
{
int NUM_OF_STUDENTS = 0;
cout << "How many students are in your class?\n"; cin >> NUM_OF_STUDENTS;

vector int grades; Again can't display the angle brackets

cout <<"Enter the grades for each of your student\n"; for (int i = 0; i <> cout << "Student ID" < cout <<"------------------------------------\n"; for (int i = 0; i <> }

return 0;
}

The Output

How many students are in your class?
5
Enter the grades for each of your student
Student ID:1 87
Student ID:2 68
Student ID:3 99
Student ID:4 87
Student ID:5 88

----------------------------------
Student ID Grade
------------------------------------
1 0
2 1
3 2
4 3
5 4

C. I spent about an hour or more on this program, it's suppose to be simple, but I couldn't figure out why my data wasn't being stored in the vector. When I went to print it the screen it just would not show the data that was supposed to be in there. I NEED more practice and more understanding of vectors as I apparently cannot get this to work out correctly. I did get it to work if I used array notation, but if I wanted to used the push_back function, it wouldn't work
.

No comments: