List Program

I am trying to write a program with lists that stores student id's, names, resident status and credit hours. The program is supposed to accept input as long as the id# is not 0. The output is the list of students in the order they were enterd, the list of resident students, and the list of students with 12+ credit hours. I have the below that I have written. When I compile I get two errors. Also, what is the best way to make sure that the values are entered until id = 0? Right now, I have a break statement, but I think a while loop would be more efficient. However, I have never used a while loop and immediaitely after used a for loop. Is this the best way?

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
#include <string>
#include <iomanip>
#include <list>

using namespace std;

//==========================================================
// class to hold student information

class Student
{
  private:
    int id;         // student ID
    string name;    // student name
    char type;      // 'R' represents resident and 'N' represents nonresident
    int crds;       // number of credits enrolled

  public:
    // default constructor
    Student()
    {
      id = 0; name = ""; type = ' '; crds = 0;
    }

    // constructor
    Student(int theId, string theName, char theType, int theCrds)
    {
      id = theId; name = theName; type = theType; crds = theCrds;
    }

    // get functions
    int getID() {return id;}
    string getName() {return name;}
    char getType() {return type;}
    int getCrds() {return crds;}

    // prints out the student's record
    void print()
    {
       cout << setw(10) << id << setw(15) << name
            << setw(15) << type << setw(10) << crds << endl;
    }
};
//===================================================================

int main()
{
   list<Student> stuList;
   list<Student>::iterator iter;
   int id;
   string name;
   char type;
   int crds;

   for(int i=0; i<3; i++)
   {
      cout << "Student ID: ";
      cin >> id;
      if(id=0)
      {break;}
      cin.ignore();
      cout << "Student Name:";
      getline(cin, name);
      cout << "Student Type (R/N)";
      cin >> type;
      cout << "Number of Credits: ";
      cin >> crds;
      cin.ignore(80, '\n');
      Student stu(id, name, type, crds);
      stuList.push_back(stu);
   }
   cout << "Students in the order they were entered" << endl;
   iter = stuList.begin();
   while(iter != stuList.end())
   {
      (*iter).print();
      cout << endl;
      iter++;
   }
   cout << "Resident Students" << endl;
   iter = stuList.begin();
   while(iter != stuList.end())
   {
      if( (*iter).getType=='R')
        {
          (*iter).print();
          cout << endl;
        }
      iter++;
   }
   cout << "Full Time Students (12+ Credit Hours)" << endl;
   iter = stuList.begin();
   while(iter != stuList.end())
   {
      if( (*iter).getCrds >= 12)
        {
          (*iter).print();
          cout << endl;
        }
      iter++;
   }
   return 0;
}

Here are the errors:
1
2
3
stulist.cpp: In function 'int main()':
stulist.cpp:85: error: invalid use of member (did you forget the '&' ?)
stulist.cpp:96: error: invalid use of member (did you forget the '&' ?)
Thanks in advance for any advice.
On lines 85 and 96 you are missing the function parentheses
Line 60: id==0

For line 85 and 96, add () at the end of the member call. ie: (*iter).getCrds() >= 12
If you have the time, take a look at this article. I wrote this article a while ago as a way to show how some std library features can be easily used for these types of exercises.
http://cplusplus.com/forum/articles/10879/

Also, consider reading this FAQ. You should consider updating your stream I/O operations to handle input errors.
http://www.parashift.com/c++-faq-lite/input-output.html

Of course that has nothing to do with the errors, but are just suggestions for improving the program.
Topic archived. No new replies allowed.