#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <string>

using namespace std;

//const int MAX_SIZE = 10;

//char determine_grade(int smarks);



class student{
      public:
             student();  //constructor
              ~student(); //destructor
             //char grade;

             //set values
             void set_mark(int);
             void set_id(string);
             void print_students_records(student, int);

             //get values
             int get_mark();
             string get_id();

     private:

             int mark;
             string id;

};
//void print_students_records(student s[], int size);
//void student::print_students_records(s[], int size){

void student::set_mark(int mark){
     student::mark = mark;
}

void student::set_id(string id){
     student::id = id;
}

int student::get_mark(){
     return mark;
}

string student::get_id(){
     return id;
}

void student::print_students_records(student s, int size){
    cout<<"\n\nstudents, records"<<endl<<endl;
    for (int i = 0; i < size; i++){
        cout<<"id: "<<s[i].get_id(i)<<", marks: "<<s[i].get_mark(i)<<endl;//<<", grade: "<<sgrades[i]<<endl;
    }
    cout<<endl;
}



//void discard_line(ifstream &infile);
int main()
{
    student s[8];

    ifstream infile;

    cout<<"This program determines the grades of students."<<endl;


    infile.open("E:\\students.txt",ios::in);

    if(!infile){
		cerr<<"File could not be opened"<<endl;
		exit(1);
	}

    //discard_line(infile);

    int total_records = 0;

    while(infile.good()){
        for (int i = 0; i < total_records; i++){
            infile >> s[i].set_id(i) >> s[i].set_mark(i);
            total_records++ ;
    }



    infile.close();

    print_students_records(s[], total_records);

    system("PAUSE");
    return 0;
}
}

i get the following errors while compiling

57 g:\copyof~1.cpp no match for `student &[int &]'
57 g:\copyof~1.cpp no match for `student &[int &]'
87 g:\copyof~1.cpp no matching function for call to `student::set_id (int &)'
42 g:\copyof~1.cpp
candidates are: void student::set_id(basic_string<char,string_char_traits<char>,__default_alloc_template<false,0> >)
95 g:\copyof~1.cpp parse error before `]'


what is the problem?

First, another issue at hand.

#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>

should be

#include <iostream>
#include <fstream>
#include <cstdlib>

The ones with the .h are prestandard C++ headers (and when using stdlib.h from c, use the cstdlib version).

There's a design problem brewing here. If you are going to have a student as an object, the print method should know how to print the information for that particular object. One object should not be responsible for printing the entire array of objects out.

So keep line 23 as it is, without the array. Change line 54 to have no parameters (since the object has access to its own member variables) and change 57 to output the single student. Instead of line 95, iterate through the array and invoke the print method for each of the objects within.

Also, use this->mark instead of student::mark (and change all the others using ::)

thanks for the help jonsca... i just had a problem though that the question given had asked to use void print_students_record (student s[], int size). as the syntax for printing.. that is why i was confused... is there any way to solve that using the same syntax T_T.thx for ur help.

are you sure that function has to be part of your student class or is that a separate function to be called in main?

this is what the question says exactly

Modify function void print_students_records to pass an object of student instead of
passing students’ information separately. Syntax for the prototype of modified
function should be void print_students_record (student s[], int size).

okay so that function shouldn't be part of the student class. you should have a print function in your class that prints the student information. then you create your print records function to accept a student array and then call the print function for each student in the array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.