help with class with a vector

Im having a hard time trying to implement this vector into a class can someone please help

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

class Course {
private:
int scores;

public:
Course();
Course( int s);
int minimum();
int get_score();
void set_score(int s);
};
Course::Course()
{
scores = 0;
}
Course::Course(int s)
{
scores=s;
}
int Course::get_score()
{
return scores;
}
void Course::set_score(int s)
{
scores = s;
}
int Course::minimum()
{
vector<Course *>numbers;
int min=numbers[0];
for (int i = 0; i<numbers.size(); i++)
{
if (numbers[i]< min)
{
min = numbers[i];
return min;
}

}
}
int main()
{
Course cs202;
vector<Course *>numbers;
int grade;

cout<<"Enter set of scores for students until eof\n";
cin >> grade;
while (!cin.eof()) {
Course * n = new Course(grade);
numbers.push_back(n);
cin>>grade;
}

int i;
for (i = 0; i < numbers.size(); i++) {
grade = numbers[i]->get_score();
grade++;
numbers[i]->set_score(grade);
}


/*cs202.read();*/

cout << "Minimum = " << cs202.minimum() << endl;

cout << "The scores again: \n";
cs202.print();*/
return 0;

}
1
2
3
4
5
6
7
8
9
10
11
int Course::minimum()
{
    vector<Course *>numbers; //Creating an empty vector here
    int min=numbers[0]; //Access out of bounds
    for (int i = 0; i<numbers.size(); i++) {
        if (numbers[i]< min) { //Another one
            min = numbers[i]; //And another
            return min;
        }
    }
}

Even if you do everything right, you comparing pointers here...

Why do you use a vector of pointers?
Topic archived. No new replies allowed.