Hey everyone, I am writing a program for my c++ class to take student records and organize them according to the students last name. All data is stored to a class and I have created an array of class objects(its part of the assignment). I am using Vi to compile (again because I have to) and here are the compile errors I'm getting:

assign5.cpp: In function âint main()â:
assign5.cpp:83: error: too many arguments to function âvoid Sort(cStudent (&)[30], int)â
assign5.cpp:92: error: at this point in file
assign5.cpp: In function âvoid Swap(cStudent (&)[30], cStudent (&)[30])â:
assign5.cpp:137: error: invalid array assignment
assign5.cpp:138: error: invalid array assignment
assign5.cpp:139: error: invalid array assignment
assign5.cpp: In function âvoid Sort(cStudent (&)[30], int)â:
assign5.cpp:149: error: argument of type âvoid (cStudent::)(char (&)[11])â does not match âconst char*â
assign5.cpp:151: error: invalid initialization of reference of type âcStudent (&)[30]â from expression of type âcStudentâ
assign5.cpp:134: error: in passing argument 1 of âvoid Swap(cStudent (&)[30], cStudent (&)[30])â


here is my code:

#include<iomanip>
#include<iostream>
#include<fstream>
using namespace std;

const int NAMESIZE=11;
const int FILENAMESIZE=51;
const int ARRAYSIZE=20;
int N=0;
typedef char Name_t[NAMESIZE];
typedef int Grade_t;
typedef char Filename_t[FILENAMESIZE];
typedef fstream Infile_t;
typedef fstream Outfile_t;

class cStudent
{
        private:
                Name_t fname;
                Name_t lname;
                Grade_t t1;
                Grade_t t2;
                Grade_t t3;
                Grade_t t4;
                Grade_t ag;
                Grade_t eg;
        public:
                cStudent();
                cStudent(Name_t NewName, Grade_t NewGrade);
                //set
                void set_fname(Name_t first)
                { strcpy(fname,first);}
                void set_lname(Name_t last)
                { strcpy(lname,last);}
                void set_t1(Grade_t a)
                { t1=a;}
                void set_t2(Grade_t b)
                { t2=b;}
                void set_t3(Grade_t c)
                { t3=c;}
                void set_t4(Grade_t d)
                { t4=d;}
                void set_ag(Grade_t e)
                { ag=e;}
                void set_eg(Grade_t f)
                { eg=f;}
                //get
                void get_fname(Name_t &fname)
                { strcpy(fname,this->fname);}
                void get_lname(Name_t &lname)
                { strcpy(lname,this->lname);}
                int get_t1(Grade_t &t1)
                { t1=this->t1; return t1;}
                int get_t2(Grade_t &t2)
                { t2=this->t2; return t2;}
                int get_t3(Grade_t &t3)
                { t3=this->t3; return t3;}
                int get_t4(Grade_t &t4)
                { t4=this->t4; return t4;}
                int get_ag(Grade_t &ag)
                { ag=this->ag; return ag;}
                int get_eg(Grade_t &eg)
                { eg=this->eg; return eg;}
};// end class cStudent
//cStudent Methods
cStudent::cStudent()
{
        t1=0;
        t2=0;
        t3=0;
        t4=0;
        ag=0;
        eg=0;
};//end of cStudent::cStudent

typedef cStudent StudentArray[30];
StudentArray CSCI208Class; //array of cStudent objects

void Read(StudentArray &CSCI208Class, int &N);
void Swap(StudentArray &x, StudentArray &y);
void Sort(StudentArray &CSCI208Class, int N);
void Print(StudentArray &CSCI208Class, int &N);
void Display(StudentArray &CSCI208Class, int &N);

//begin main
main()
{

        Read(CSCI208Class,N);
        Sort(CSCI208Class,N,Swap);
        Print(CSCI208Class,N);
        Display(CSCI208Class,N);
        cout<<"TERMINATING PROGRAM.........GOODBYE!"<<endl;

};//end main

void Read(StudentArray &CSCI208Class, int &N)
{
        Filename_t Filename;
        Infile_t Infile;
        cout<<"Enter the name of the data file:"<<endl<<endl;
        cin>>Filename;
        cout<<"Opening Datafile..............."<<endl;
        Infile.open(Filename,ios::in);

        Name_t first, last;
        Grade_t a,b,c,d,e,f;
        N=0;

        Infile>>first;
        CSCI208Class[N].set_fname(first);
        while(!Infile.eof())
        {
                Infile>>last>>a>>b>>c>>d>>e>>f;
                CSCI208Class[N].set_lname(last);
                CSCI208Class[N].set_t1(a);
                CSCI208Class[N].set_t2(b);
                CSCI208Class[N].set_t3(c);
                CSCI208Class[N].set_t4(d);
                CSCI208Class[N].set_ag(e);
                CSCI208Class[N].set_eg(f);
                N=N+1;
                Infile>>first;
                CSCI208Class[N].set_fname(first);
        }//end while loop
        cout<<"READ COMPLETE..............."<<endl;
        cout<<"Closing Datafile..............."<<endl;
        cout<<"Begining Next Process..............."<<endl<<endl;
        Infile.close();
};//end of read

void Swap(StudentArray &x, StudentArray &y)
{
        StudentArray Temp;
        Temp=x;
        x=y;
        y=Temp;
};//end of swap

void Sort(StudentArray &CSCI208Class, int N)
{
        int I,Pass;
        for(Pass=0; Pass<N-2; Pass++)
        {
                for(I=0; I<N-2; I++)
                {
                        if(strcmp(CSCI208Class[I].get_lname,CSCI208Class[I+1].get_lname))
                        {
                                Swap(CSCI208Class[I],CSCI208Class[I+1]);
                        }//end if
                }//end inside for
        }//end outside for
};//end sort


void Print(StudentArray CSCI208Class, int &N)
{
        Filename_t Filename;
        Outfile_t Outfile;
        cout<<"Please enter the name of the output file to be created:"<<endl<<endl;
        cin>>Filename;
        cout<<"CREATING OUTPUT FILE..............."<<endl;
        Outfile.open(Filename,ios::out);
        cout<<"BEGINING WRITE PLEASE WAIT..............."<<endl;
        Outfile<<"********************************************************************************************"<<endl;
        Outfile<<"      "<<"NAME"<<"    "<<"TEST GRADES"<<"     "<<"ASSIGNMENT GRADE"<<" "<<"EXAM GRADE"<<endl;
        Outfile<<"********************************************************************************************"<<endl<<endl;

        for(int I=0; I<N; I++)
        {
                Name_t fname,lname;
                Grade_t t1,t2,t3,t4,ag,eg;
                CSCI208Class[I].get_fname(fname);
                CSCI208Class[I].get_lname(lname);
                CSCI208Class[I].get_t1(t1);
                CSCI208Class[I].get_t2(t2);
                CSCI208Class[I].get_t3(t3);
                CSCI208Class[I].get_t4(t4);
                CSCI208Class[I].get_ag(ag);
                CSCI208Class[I].get_eg(eg);
                Outfile<<"   "<<fname<<" "<<lname<<"   "<<t1<<" "<<t2<<" "<<t3<<" "<<t4<<"   "<<ag<<"   "<<eg<<endl;
                Outfile<<"---------------------------------------------------------------------------------------"<<endl;
        };//end for loop
        Outfile<<"********************************"<<N<<"students in this file***********************************"<<endl;
        Outfile<<"********************************END-OF-REPORT**************************************************"<<endl;
        cout<<"DATA SUCESSFULLY WRITTEN TO FILE!"<<endl;
        cout<<"NOW SAVING AND CLOSING OUTPUT FILE PLEASE WAIT..............."<<endl<<endl;
        Outfile.close();
};//end of print

void Display(StudentArray CSCI208Class, int &N)
{
        char choice[5];
        cout<<"Would you like to preview the student records output file? (Yes/No)"<<endl;
        cin>>choice;

        if(choice=="No"||choice=="NO"||"no")
        { cout<<"TERMINATING PROGRAM.................GOODBYE"<<endl;}
        else
        if(choice=="Yes"||"YES"||"yes")
        {
                cout<<"********************************************************************************************"<<endl;
                cout<<" "<<"NAME"<<"    "<<"TEST GRADES"<<"     "<<"ASSIGNMENT GRADE"<<" "<<"EXAM GRADE"<<endl;
                cout<<"********************************************************************************************"<<endl<<endl;

                for(int I=0; I<N; I++)
                {
                        Name_t fname,lname;
                        Grade_t t1,t2,t3,t4,ag,eg;
                        CSCI208Class[I].get_fname(fname);
                        CSCI208Class[I].get_lname(lname);
                        CSCI208Class[I].get_t1(t1);
                        CSCI208Class[I].get_t2(t2);
                        CSCI208Class[I].get_t3(t3);
                        CSCI208Class[I].get_t4(t4);
                        CSCI208Class[I].get_ag(ag);
                        CSCI208Class[I].get_eg(eg);
                        cout<<"   "<<fname<<" "<<lname<<"   "<<t1<<" "<<t2<<" "<<t3<<" "<<t4<<"   "<<ag<<"   "<<eg<<endl;
                        cout<<"----------------------------------------------------------------------------------"<<endl;
                };//end for loop
                cout<<"***"<<N<<" students in this file***"<<endl;
                cout<<"*****************END-OF-REPORT*******************"<<endl;
        }
        else
        { cout<<"PLEASE ENTER EITHER YES or NO......................."<<endl;}
}//end display

does anyone have any idea whats wrong? I am really worried about my swap function and using it in my sort function.

thanks!
-atticusr5

assign5.cpp:83: error: too many arguments to function âvoid Sort(cStudent (&)[30], int)â

Well, the function Sort has more parameters in the call than the function is designed to take.

Hope that helps...

hey everyone, i am down to 1 compile error!

here it is:

ACC.joshid2@edmonton:~$ c++ -c assign5.cpp
assign5.cpp: In function âvoid Sort(cStudent (&)[30], int&)â:
assign5.cpp:141: error: invalid use of void expression

here is the updated code:

//assignment 5

#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;

const int NAMESIZE=11;
const int FILENAMESIZE=51;
const int ARRAYSIZE=20;
int N=0;
typedef char Name_t[NAMESIZE];
typedef int Grade_t;
typedef char Filename_t[FILENAMESIZE];
typedef fstream Infile_t;
typedef fstream Outfile_t;

class cStudent
{
        private:
                Name_t fname;
                Name_t lname;
                Grade_t t1;
                Grade_t t2;
                Grade_t t3;
                Grade_t t4;
                Grade_t ag;
                Grade_t eg;
        public:
                cStudent();
                cStudent(Name_t NewName, Grade_t NewGrade);
                //set
                void set_fname(Name_t first)
                { strcpy(fname,first);}
                void set_lname(Name_t last)
                { strcpy(lname,last);}
                void set_t1(Grade_t a)
                { t1=a;}
                void set_t2(Grade_t b)
                { t2=b;}
                void set_t3(Grade_t c)
                { t3=c;}
                void set_t4(Grade_t d)
                { t4=d;}
                void set_ag(Grade_t e)
                { ag=e;}
                void set_eg(Grade_t f)
                { eg=f;}
                //get
                void get_fname(Name_t &fname)
                { strcpy(fname,this->fname);}
                void get_lname(Name_t &lname)
                { strcpy(lname,this->lname);}
                int get_t1(Grade_t &t1)
                { t1=this->t1; return t1;}
                int get_t2(Grade_t &t2)
                { t2=this->t2; return t2;}
                int get_t3(Grade_t &t3)
                { t3=this->t3; return t3;}
                int get_t4(Grade_t &t4)
                { t4=this->t4; return t4;}
                int get_ag(Grade_t &ag)
                { ag=this->ag; return ag;}
                int get_eg(Grade_t &eg)
                { eg=this->eg; return eg;}
};// end class cStudent
//cStudent Methods
cStudent::cStudent()
{
        t1=0;
        t2=0;
        t3=0;
        t4=0;
        ag=0;
        eg=0;
};//end of cStudent::cStudent

typedef cStudent StudentArray[30];
StudentArray CSCI208Class; //array of cStudent objects

void Read(StudentArray &CSCI208Class, int &N);
void Sort(StudentArray &CSCI208Class, int &N);
void Print(StudentArray &CSCI208Class, int &N);
void Display(StudentArray &CSCI208Class, int &N);

//begin main
main()
{

        Read(CSCI208Class,N);
        Sort(CSCI208Class,N);
        Print(CSCI208Class,N);
        Display(CSCI208Class,N);
        cout<<"TERMINATING PROGRAM.........GOODBYE!"<<endl;

};//end main

void Read(StudentArray &CSCI208Class, int &N)
{
        Filename_t Filename;
        Infile_t Infile;
        cout<<"Enter the name of the data file:"<<endl<<endl;
        cin>>Filename;
        cout<<"Opening Datafile..............."<<endl;
        Infile.open(Filename,ios::in);

        Name_t first, last;
        Grade_t a,b,c,d,e,f;
        N=0;

        Infile>>first;
        CSCI208Class[N].set_fname(first);
        while(!Infile.eof())
        {
                Infile>>last>>a>>b>>c>>d>>e>>f;
                CSCI208Class[N].set_lname(last);
                CSCI208Class[N].set_t1(a);
                CSCI208Class[N].set_t2(b);
                CSCI208Class[N].set_t3(c);
                CSCI208Class[N].set_t4(d);
                CSCI208Class[N].set_ag(e);
                CSCI208Class[N].set_eg(f);
                N=N+1;
                Infile>>first;
                CSCI208Class[N].set_fname(first);
        }//end while loop
        cout<<"READ COMPLETE..............."<<endl;
        cout<<"Closing Datafile..............."<<endl;
        cout<<"Begining Next Process..............."<<endl<<endl;
        Infile.close();
};//end of read

void Sort(StudentArray &CSCI208Class, int &N)
{
        int I,Pass;
        Name_t lname;
        for(Pass=0; Pass<N-2; Pass++)
        {
                for(I=0; I<N-2; I++)
                {
                        if(strcmp(CSCI208Class[I].get_lname(lname),CSCI208Class[I+1].get_lname(lname))>0)
                        {
                                StudentArray Temp;
                                Temp[I]=CSCI208Class[I];
                                CSCI208Class[I]=CSCI208Class[I+1];
                                CSCI208Class[I+1]=Temp[I];
                        }//end if
                }//end inside for
        }//end outside for
};//end sort


void Print(StudentArray CSCI208Class, int &N)
{
        Filename_t Filename;
        Outfile_t Outfile;
        cout<<"Please enter the name of the output file to be created:"<<endl<<endl;
        cin>>Filename;
        cout<<"CREATING OUTPUT FILE..............."<<endl;
        Outfile.open(Filename,ios::out);
        cout<<"BEGINING WRITE PLEASE WAIT..............."<<endl;
        Outfile<<"********************************************************************************************"<<endl;
        Outfile<<"      "<<"NAME"<<"    "<<"TEST GRADES"<<"     "<<"ASSIGNMENT GRADE"<<"        "<<"EXAM GRADE"<<endl;
        Outfile<<"********************************************************************************************"<<endl<<endl;

        for(int I=0; I<N; I++)
        {
                Name_t fname,lname;
                Grade_t t1,t2,t3,t4,ag,eg;
                CSCI208Class[I].get_fname(fname);
                CSCI208Class[I].get_lname(lname);
                CSCI208Class[I].get_t1(t1);
                CSCI208Class[I].get_t2(t2);
                CSCI208Class[I].get_t3(t3);
                CSCI208Class[I].get_t4(t4);
                CSCI208Class[I].get_ag(ag);
                CSCI208Class[I].get_eg(eg);
                Outfile<<"   "<<fname<<" "<<lname<<"   "<<t1<<" "<<t2<<" "<<t3<<" "<<t4<<"   "<<ag<<"   "<<eg<<endl;
                Outfile<<"---------------------------------------------------------------------------------------"<<endl;
        };//end for loop
        Outfile<<"********************************"<<N<<"students in this file***********************************"<<endl;
        Outfile<<"********************************END-OF-REPORT**************************************************"<<endl;
        cout<<"DATA SUCESSFULLY WRITTEN TO FILE!"<<endl;
        cout<<"NOW SAVING AND CLOSING OUTPUT FILE PLEASE WAIT..............."<<endl<<endl;
        Outfile.close();
};//end of print

void Display(StudentArray CSCI208Class, int &N)
{
        char choice[5];
        cout<<"Would you like to preview the student records output file? (Yes/No)"<<endl;
        cin>>choice;

        if(choice=="No"||choice=="NO"||"no")
        { cout<<"TERMINATING PROGRAM.................GOODBYE"<<endl;}
        else
        if(choice=="Yes"||"YES"||"yes")
        {
                cout<<"********************************************************************************************"<<endl;
                cout<<" "<<"NAME"<<"    "<<"TEST GRADES"<<"     "<<"ASSIGNMENT GRADE"<<"        "<<"EXAM GRADE"<<endl;
                cout<<"********************************************************************************************"<<endl<<endl;

                for(int I=0; I<N; I++)
                {
                        Name_t fname,lname;
                        Grade_t t1,t2,t3,t4,ag,eg;
                        CSCI208Class[I].get_fname(fname);
                        CSCI208Class[I].get_lname(lname);
                        CSCI208Class[I].get_t1(t1);
                        CSCI208Class[I].get_t2(t2);
                        CSCI208Class[I].get_t3(t3);
                        CSCI208Class[I].get_t4(t4);
                        CSCI208Class[I].get_ag(ag);
                        CSCI208Class[I].get_eg(eg);
                        cout<<"   "<<fname<<" "<<lname<<"   "<<t1<<" "<<t2<<" "<<t3<<" "<<t4<<"   "<<ag<<"   "<<eg<<endl;
                        cout<<"----------------------------------------------------------------------------------"<<endl;
                };//end for loop
                cout<<"***"<<N<<" students in this file***"<<endl;
                cout<<"*****************END-OF-REPORT*******************"<<endl;
        }
        else
        { cout<<"PLEASE ENTER EITHER YES or NO......................."<<endl;}
}//end display

does anyone see whats wrong? its this sort functions that driving me crazy!

Your get_lname method is void and on 141 you are trying to compare two return values from it using strcmp. Try something like this:

Name_t lname;
Name_t nextlname;
CSCI208Class[I].get_lname(lname);
CSCI208Class[I+1].get_lname(nextlname);
if(strcmp(lname,nextlname)>0)

or something to that effect. Or you could change the return type on get_lname() to Name_t but I don't know if you have some flexibility in that regard.

Edited 6 Years Ago by jonsca: n/a

that did the trick! i guess that message makes sense

now i'm getting linker errors!:

assign5.o: In function `main':
assign5.cpp:(.text+0xfd9): undefined reference to `Print(cStudent (&) [30], int&)'
assign5.cpp:(.text+0xfed): undefined reference to `Display(cStudent (&) [30], int&)'
collect2: ld returned 1 exit status


i will see how far I can get, its probably something silly

You left off the ampersands in the function definitions for print and display: void Display(StudentArray & CSCI208Class, int &N)

You left off the ampersands in the function definitions for print and display: void Display(StudentArray & CSCI208Class, int &N)

thanks im suck at debugging so much to learn!

thanka again!

This question has already been answered. Start a new discussion instead.