Hi,
Wondering if I could get some help. This program is supposed to :
-Input student data(firstname,lastname,student#, and a vector of Grades(up to 10 grades) with a grade and assignment name(notworking)) from a text file and store it in a vector
-Have a menu system for navigation
-add a student ---Working
-delete a student --- not working
-modify a student --- not working, dont know how to access student and modify the non-working struct vector of Grades, i need help with this
-quit (save vector in text file on quit--this is not working, im not using ofstream right)

Vectors/iterators must be used


Here is my bug ridden code, I know it's crappy, but any help, suggestions, comments, would be greatly appreciated.

Thanks, Dev

//****************
//STUDENT.H
//***************

#ifndef _Student_HG_
#define _Student_HG_
#include <string>
#include <vector>

using std::string;

class Student 
{
public:
    Student( const string &, const string &, const string &, vector <Grade> &);//i should have an int and assign it to a vector instead of vector here?
    ~Student(); //Destructor
    void setFirstName( const string & );//set first name
    string getFirstName() const;

    void setLastName( const string & );
    string getLastName() const;

    void setStudentNumber( const string & );
    string getStudentNumber() const;

    void printGrades( vector <Grade> &);

    //void addGrade
    vector <Grade> vecGrade;
private:
    string firstName;
    string lastName;
    string studentNumber;
    


};
#endif


//**************************
//STUDENT.CPP
//*********************

#include <iostream>
using namespace std;
#include "Student.h"
//, const int &grade

struct Grade()
{
    string assignmentName;
    int assignmentGrade;
}

Student::Student( const string &first, const string &last, const string &snum , vector <Grade> &vG)
: firstName( first ), lastName( last ), studentNumber( snum )
{
    Grade tempGrade = new Grade;
    //start loop to input grades into vector<Grade>         NOT WORKING
    /*tempGrade.assignmentName =   ;
    tempGrade.assignmentGrade =   ;
    vecGrade.push_back(tempGrade);*/
}

Student::~Student()
{
}

void Student::setFirstName( const string &first)
{
    firstName = first;
}

string Student::getFirstName() const
{
    return firstName;
}

void Student::setLastName( const string &last)
{
    lastName = last;
}

string Student::getLastName() const
{
    return lastName;
}

void Student::setStudentNumber(const string &snum)
{
    studentNumber = snum;
}

string Student::getStudentNumber() const
{
    return studentNumber;
}

void Student::printGrades()
{
    for (vector<Grade>::iterator it = vecGrade.begin();
         it != vecGrade.end(); it++)
    {
        cout << (*it).assignmentName << "     "
        << (*it).assignemtnGrade << endl;//DONT KNOW what todo...This doesnt work
    }
}



//**************
//Main
//***********


#include <iostream>
#include <iomanip>
#include <vector>        
#include <string>
#include <fstream>
#include "Student.h"

using namespace std;




int enterChoice()
{
    cout << "\nEnter your choice" << endl
        << "1 - Add a student" << endl
        << "2 - Modify a student" << endl
        << "3 - Delete a student" << endl
        << "0 - Exit\n" << endl << endl << endl;
    
        int menuChoice;
        cin >> menuChoice;
        return menuChoice;
}

int enterModChoice()
{
    cout << "\nEnter your choice" << endl
        << "1 - Change student's first name" << endl
        << "2 - Change student's last name" << endl
        << "3 - Change student's student number" << endl
        << "4 - change students assignment/grades" << endl
        << "0 - Exit\n" << endl << endl << endl;
    
        int menuChoice;
        cin >> menuChoice;
        return menuChoice;
}



void printOut(vector<Student> &vecStud)
{
    cout << "Student" << setw(25) << "Grade" <<endl;
    for (vector<Student>::iterator it = vecStud.begin();
         it != vecStud.end(); it++)
    {
        cout << (*it).getFirstName() << " " <<
            (*it).getLastName() << " :" <<
                 endl;
    }

}


int main()
{
    //Load up the student data text file into vector
    vector < Student > vecStudent;
    ifstream myFile("studentData.txt");
    string fname;
    string lname;
    string    ssn;
    
    while (myFile >> fname >> lname >> ssn)
    {
    Student tempStu(fname,lname,ssn);
    vecStudent.push_back(tempStu);
    }
    myFile.close;

    printOut(vecStudent);


    int choice;
    int choice2;
    string result;
    while ( ( choice = enterChoice() ) != 0)
    {
        
        switch ( choice)
        {
        case 1:
            {//add a student
            
            cout << endl << endl << endl;
            cout << "Adding student...." << endl << endl << endl;
            cout << "What is the student's first name?   : ";
            cin >> fname;
            cout << endl << "What is the student's last name?   : ";
            cin >> lname;
            cout << endl << "What is the student's student number?  : ";
            cin >> ssn;
            Student tempStu(fname,lname,ssn);
            

            vecStudent.push_back(tempStu);

            //How many assignments/grades do you want to put in?
            //loop inputting grades into Student grade vector

            printOut(vecStudent);
            break;
            }
        case 2:
            {
            //modify and student
            cout << "Modifing a student......" << endl << endl << endl;
            cout << "What is the student's student number\n who you want to modify?" << endl << endl;
            cin >> ssn;
            
            //search for student
            for (vector<Student>::iterator it = vecStudent.begin();
         it != vecStudent.end(); it++)
            {
                //THIS DOESNT WORK*******
                if (!strcmp((*it).getStudentNumber, ssn))
                {
                    cout << "Student found......" << endl;
                    
                //display menu for changing a student's stats
                while ( ( choice2 = enterModChoice() ) != 0)
                {
                    switch ( choice2 )
                    {
                    case 1:
                        //set/change students first name
                        cout << "Enter student's new first name: ";
                        cin >> result;
                        (*it).setFirstName( result );
                        break;
                    case 2:
                        //set/change student's last name
                        cout << "Enter student's new last name: ";
                        cin >> result;
                        (*it).setLastName( result );
                        break;
                    case 3:
                        //set/change student's student number
                        cout << "Enter student's new student number: ";
                        cin >> result;
                        (*it).setStudentNumber( result );
                        break;
                    case 4:
                        //print off assignment list (vector of struct Grade's inside Student) w/grades
                        (*it).printGrades();
                        //Bring up another menu for what assignment to change
                        
                        //enter assignemnt # 1-10
                        // change 1: name or 2: grade
                        // if 
                        break;
                    case 0:
                        
                        break;
                    default:
                        cout << "You entered a wrong number" << endl;
                        break;
                    }
                }
                }

                
                else
                {
                    cout << "Sorry, either the number was incorrectly inputted"
                        << "\n or the student does not exist." << endl;

                }

            }
            break;
            }
        case 3:
            {
            //delete a student
            cout << "Deleting a student......" << endl << endl << endl;
            cout << "What is the student's student number\n who you want to delete?" << endl << endl;
            cin >> ssn;
            
            for (vector<Student>::iterator it = vecStudent.begin();
                 it != vecStudent.end(); it++)
            {
                //THIS DOESNT WORK
                if ( !strcmp((*it).getStudentNumber, ssn))
                {
                    cout << "Sorry, either the number was incorrectly inputted"
                        << "\n or the student does not exist." << endl;
                }
                else
                {
                    cout << "Student found......" << endl;
                    cout << "Deleting...." << endl;
                    
                    //DOESNT WORK, i guess i have to delete it from the vector somehow aswell?
                    delete (*it);
                }
            }
            break;
            }
        case 0:
            {
            //exit


            //save Student vector to file, outputting everything
                
                ofstream myFile("studentData.txt");
                myFile.trunc;
            
                for (vector<Student>::iterator it = vecStudent.begin();
         it != vecStudent.end(); it++)
                {
                myFile >> (*it).getFirstName() >> " " >>
            (*it).getLastName() >> " :" >> endl;
                //print out grades
                myFile >>(*it).printGrades() >> endl;
                }
                myFile.close;

                return 0;
            }
        default:
            {//error msg, 
            cout << "You have put in an incorrect choice" << endl;
            printOut();
            }
            break;
        }

    }


    


    return 0;
}

>Here is my bug ridden code
Bug-ridden? It won't even compile!

There's way too many for me to fix now, how about posting the error messages you receive so other people can help you find what is making them occur?

OKay , here is the udpated code, a bit more sorted out, just a few problems generating 21 errors.

First of all I'm not using the right fstream commands or something for output to a text file. Please help. (line 389-402)

Second, when doing a comparison of strings, like "if ( ((*it).getStudentNumber) == ssn)" doesnt work, how do i do this properly?
(line 268 etc)

Lastly, how do i properly delete a student from the vector of students? "delete (*it);" not working. (line 377)

Also, am i declaring the struct properly in the student.h?
Also, what am i forgetting with my printGrade function for student, it doesnt work, here is my list of errors the compiler throws at me.

1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(147) : error C2784: 'bool std::operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\string(91) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(147) : error C2784: 'bool std::operator ==(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\string(81) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(147) : error C2784: 'bool std::operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\string(71) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(147) : error C2784: 'bool std::operator ==(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\vector(1259) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(147) : error C2784: 'bool std::operator ==(const std::istream_iterator<_Ty,_Elem,_Traits,_Diff> &,const std::istream_iterator<_Ty,_Elem,_Traits,_Diff> &)' : could not deduce template argument for 'const std::istream_iterator<_Ty,_Elem,_Traits,_Diff> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\iterator(266) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(147) : error C2784: 'bool std::operator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\xmemory(174) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(147) : error C2784: 'bool std::operator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\xutility(2143) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(147) : error C2784: 'bool std::operator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\xutility(1826) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(147) : error C2784: 'bool std::operator ==(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\utility(60) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(147) : error C2677: binary '==' : no global operator found which takes type 'std::string' (or there is no acceptable conversion)
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(245) : error C2784: 'bool std::operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\string(91) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(245) : error C2784: 'bool std::operator ==(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\string(81) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(245) : error C2784: 'bool std::operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\string(71) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(245) : error C2784: 'bool std::operator ==(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\vector(1259) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(245) : error C2784: 'bool std::operator ==(const std::istream_iterator<_Ty,_Elem,_Traits,_Diff> &,const std::istream_iterator<_Ty,_Elem,_Traits,_Diff> &)' : could not deduce template argument for 'const std::istream_iterator<_Ty,_Elem,_Traits,_Diff> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\iterator(266) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(245) : error C2784: 'bool std::operator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\xmemory(174) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(245) : error C2784: 'bool std::operator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\xutility(2143) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(245) : error C2784: 'bool std::operator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\xutility(1826) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(245) : error C2784: 'bool std::operator ==(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'overloaded-function'
1> c:\program files\microsoft visual studio 8\vc\include\utility(60) : see declaration of 'std::operator =='
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(245) : error C2677: binary '==' : no global operator found which takes type 'std::string' (or there is no acceptable conversion)
1>c:\documents and settings\dev\my documents\c++\p4\main\main\main.cpp(256) : error C2440: 'delete' : cannot convert from 'Student' to 'void *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>Student.cpp
1>Generating Code...
1>c:\documents and settings\dev\my documents\c++\p4\main\main\student.cpp(61) : warning C4715: 'Student::printGrades' : not all control paths return a value

//******************
//STUDENT.h
//**************
#ifndef _Student_HG_
#define _Student_HG_
#include <string>
#include <vector>

using std::string;

class Student 
{
public:
    Student( const string &, const string &, const string & );//i should have an int and assign it to a vector instead of vector here?
    ~Student(); //Destructor
    void setFirstName( const string & );//set first name
    string getFirstName() const;

    void setLastName( const string & );
    string getLastName() const;

    void setStudentNumber( const string & );
    string getStudentNumber() const;

    string printGrades() ;
    
    struct Grade
    {
        string assignmentName;
        int assignmentGrade;
    };
    //void addGrade
    //vector <Grade> vecGrade;
    std::vector<Grade> vecGrade;


private:
    string firstName;
    string lastName;
    string studentNumber;
    


};
#endif




//*************
//Student.cpp
//**************

#include <iostream>
#include <sstream>
#include <string>
using namespace std;
#include "Student.h"

//, const int &grade

Student::Student( const string &first, const string &last, const string &snum )
: firstName( first ), lastName( last ), studentNumber( snum )
{
}

Student::~Student()
{
}

void Student::setFirstName( const string &first)
{
    firstName = first;
}

string Student::getFirstName() const
{
    return firstName;
}

void Student::setLastName( const string &last)
{
    lastName = last;
}

string Student::getLastName() const
{
    return lastName;
}

void Student::setStudentNumber(const string &snum)
{
    studentNumber = snum;
}

string Student::getStudentNumber() const
{
    return studentNumber;
}

string Student::printGrades()
{
    std::stringstream ss;
    string st;
    string s;
    for (vector<Grade>::iterator it = vecGrade.begin();
         it != vecGrade.end(); it++)
    {
        ss << (*it).assignmentGrade;
        ss >> st;
        s = (*it).assignmentName + " " + st + "\n";
        return s;
    }
}


//**************
//Main.cpp
//**********

#include <iostream>
#include <iomanip>
#include <vector>        
#include <string>
#include <sstream>
#include <fstream>
#include "Student.h"

using namespace std;




int enterChoice()
{
    cout << "\nEnter your choice" << endl
        << "1 - Add a student" << endl
        << "2 - Modify a student" << endl
        << "3 - Delete a student" << endl
        << "0 - Exit\n" << endl << endl << endl;
    
        int menuChoice;
        cin >> menuChoice;
        return menuChoice;
}

int enterModChoice()
{
    cout << "\nEnter your choice" << endl
        << "1 - Change student's first name" << endl
        << "2 - Change student's last name" << endl
        << "3 - Change student's student number" << endl
        << "4 - change students assignment/grades" << endl
        << "0 - Exit\n" << endl << endl << endl;
    
        int menuChoice;
        cin >> menuChoice;
        return menuChoice;
}



void printOut(vector<Student> &vecStud)
{
    cout << "Student" << setw(25) << "Grade" <<endl;
    for (vector<Student>::iterator it = vecStud.begin();
         it != vecStud.end(); it++)
    {
        cout << (*it).getFirstName() << " " <<
            (*it).getLastName() << " :" <<
                 endl;
    }

}


int main()
{
    //Load up the student data text file into vector
    vector < Student > vecStudent;
    ifstream myFile("studentData.txt");
    string fname;
    string lname;
    string    ssn;
    int numMarks;
    string assName;
    int assGrade;
    
    Student::Grade tempGrade;

    while (myFile >> fname >> lname >> ssn)
    {
    Student tempStu(fname,lname,ssn);
    
    while (myFile >> assName >> assGrade)
    {
        tempGrade.assignmentName = assName;
        tempGrade.assignmentGrade = assGrade;
        tempStu.vecGrade.push_back(tempGrade);
    }
    vecStudent.push_back(tempStu);
    }

    start:
    printOut(vecStudent);


    int choice;
    int choice2;
    int c;
    string result;
    while ( ( choice = enterChoice() ) != 0)
    {
        
        switch ( choice )
        {
        case 1:
            {//add a student
            
            cout << endl << endl << endl;
            cout << "Adding student...." << endl << endl << endl;
            cout << "What is the student's first name?   : ";
            cin >> fname;
            cout << endl << "What is the student's last name?   : ";
            cin >> lname;
            cout << endl << "What is the student's student number?  : ";
            cin >> ssn;

            Student tempStu(fname,lname,ssn);

            cout << endl << "How many assignments do you want to enter /w marks?" << endl;
            cin >> c;
            for (int x=0; x < c; x++)
            {

                cout << endl << "What's the assignment's title?" << endl;
                cin >> assName;
                tempGrade.assignmentName = assName;
                cout << endl << "What's the assignment's grade?" << endl;
                cin >> assGrade;
                tempGrade.assignmentGrade = assGrade;
                tempStu.vecGrade.push_back(tempGrade);

            }
            

            vecStudent.push_back(tempStu);

            //How many assignments/grades do you want to put in?
            //loop inputting grades into Student grade vector

            printOut(vecStudent);
            break;
            }
        case 2:
            {
            //modify and student
            cout << "Modifing a student......" << endl << endl << endl;
            cout << "What is the student's student number\n who you want to modify?" << endl << endl;
            cin >> ssn;
            
            //search for student
            for (vector<Student>::iterator it = vecStudent.begin();
         it != vecStudent.end(); it++)
            {
                //THIS DOESNT WORK*******
                if ((*it).getStudentNumber == ssn)
                {
                    cout << "Student found......" << endl;
                    
                //display menu for changing a student's stats
                while ( ( choice2 = enterModChoice() ) != 0)
                {
                    switch ( choice2 )
                    {
                    case 1:
                        //set/change students first name
                        cout << "Enter student's new first name: ";
                        cin >> result;
                        (*it).setFirstName( result );
                        break;
                    case 2:
                        //set/change student's last name
                        cout << "Enter student's new last name: ";
                        cin >> result;
                        (*it).setLastName( result );
                        break;
                    case 3:
                        //set/change student's student number
                        cout << "Enter student's new student number: ";
                        cin >> result;
                        (*it).setStudentNumber( result );
                        break;
                    case 4:
                        //print off assignment list (vector of struct Grade's inside Student) w/grades
                        cout << (*it).printGrades();
                        //Bring up another menu for what assignment to change
                        
                        cout << "\nEnter your choice" << endl
                        << "1 - Modify Grade Name/Mark" << endl
                        << "0 - Exit\n" << endl << endl << endl;
                        int cc;
                        cin >> cc;

                        if (cc=0)
                            break;
                        else
                        {
                            cout << "which assignment do you want to change? (1-10);" << endl;
                            cin >> cc;

                            cout << endl <<  "What do you want the new assignment name to be? :";
                            cin >> assName;
                            cout << endl << "what do you want the new assignment grade to be? :";
                            cin >> assGrade;
                            
                            vector<Student::Grade>::iterator itv = (*it).vecGrade.begin();
                            itv += cc;
                            
                            (*itv).assignmentName = assName;
                            (*itv).assignmentGrade = assGrade;
                            cout << (*it).printGrades();
                                break;
                        }



                        //enter assignemnt # 1-10
                        // change 1: name or 2: grade
                        // if 
                        break;
                    case 0:
                        
                        break;
                    default:
                        cout << "You entered a wrong number" << endl;
                        goto start;
                        break;
                    }
                }
                }

                
                else
                {
                    cout << "Sorry, either the number was incorrectly inputted"
                        << "\n or the student does not exist." << endl;
                        goto start;
                }

            }
            break;
            }
        case 3:
            {
            //delete a student
            cout << "Deleting a student......" << endl << endl << endl;
            cout << "What is the student's student number\n who you want to delete?" << endl << endl;
            cin >> ssn;
            
            for (vector<Student>::iterator it = vecStudent.begin();
                 it != vecStudent.end(); it++)
            {
                //THIS DOESNT WORK, how do i compare the strings properly?
                if ( ((*it).getStudentNumber) == ssn)
                {
                    cout << "Sorry, either the number was incorrectly inputted"
                        << "\n or the student does not exist." << endl;
                }
                else
                {
                    cout << "Student found......" << endl;
                    cout << "Deleting...." << endl;
                    
                    //DOESNT WORK, i guess i have to delete it from the vector somehow aswell?
                    delete (*it);
                }
            }
            break;
            }
        case 0:
            {
            //exit


            //save Student vector to file, outputting everything
                
                fstream myFile("studentData.txt",ios::out);
                myFile.trunc;
            
                for (vector<Student>::iterator it = vecStudent.begin();
         it != vecStudent.end(); it++)
                {
                
                    myFile << (*it).getFirstName() << " " <<
            (*it).getLastName() << " " << (*it).getStudentNumber() << endl;
                //print out grades
                myFile << (*it).printGrades() << endl;
                
                }
                myFile.close();

                return 0;
            }
        default:
            {//error msg, 
            cout << "You have put in an incorrect choice" << endl;
            goto start;
            }
            break;
        }

    }


    


    return 0;
}

Good job, you've definitely fixed a number of syntax errors already.

Basically 2 things I saw:

if ((*it).getStudentNumber) == ssn)

Since getStudentNumber is a function, you'll have to put () after the function name. Otherwise you're comparing function pointers, which is something entirely different.

Using delete to deallocate a vector? If you need to empty it, you can always use vector::clear , but the destructor of std::vector automatically takes care of this, so no worries here.

But if you still want to use delete (which would be a good thing), consider dynamically allocating the vector using the new operator.

commented: silly, vectors don't need dynamic allocation using new. -2

Okay, Got everything error free , thanks alot, however there is some runtime difficulties.

First, and hopefully only, when I load up the student and the grades, it doesnt work :p it worked initially, but now when it displays the student when it first loads and displays the students, its not workin. So any help, much appreciated....

//*******************
//studentData.txt example
//*******************
Devin Grove 222-234-567
history111 85
calculus222 99

Kath Puza 345-678-665
history111 85
calculus222 99

Tom Geonger 325-235-256
history111 85
calculus222 99
history111 85

Dude Willis 123-157-643
history111 85
calculus222 99

Oscar Myer 305-246-789
history111 85
calculus222 99

Julia Wicchaa 242-657-543
history111 85
calculus222 99
calculus222 99

//***********
//student.h
 
#ifndef _Student_HG_
#define _Student_HG_
#include <string>
#include <vector>
using std::string;
class Student 
{
public:
Student( const string &, const string &, const string & );//i should have an int and assign it to a vector instead of vector here?
~Student(); //Destructor
void setFirstName( const string & );//set first name
string getFirstName() const;
void setLastName( const string & );
string getLastName() const;
void setStudentNumber( const string & );
string getStudentNumber() const;
string printGrades() ;
 
struct Grade
{
string assignmentName;
int assignmentGrade;
};
//void addGrade
//vector <Grade> vecGrade;
std::vector<Grade> vecGrade;
 
private:
string firstName;
string lastName;
string studentNumber;
 
 
};
#endif
 
 
 
//*************
//Student.cpp
//*************
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
#include "Student.h"
//, const int &grade
Student::Student( const string &first, const string &last, const string &snum )
: firstName( first ), lastName( last ), studentNumber( snum )
{
}
Student::~Student()
{
}
void Student::setFirstName( const string &first)
{
firstName = first;
}
string Student::getFirstName() const
{
return firstName;
}
void Student::setLastName( const string &last)
{
lastName = last;
}
string Student::getLastName() const
{
return lastName;
}
void Student::setStudentNumber(const string &snum)
{
studentNumber = snum;
}
string Student::getStudentNumber() const
{
return studentNumber;
}
string Student::printGrades()
{
std::stringstream ss;
string st;
string s;
for (vector<Grade>::iterator it = vecGrade.begin();
it != vecGrade.end(); it++)
{
ss << (*it).assignmentGrade;
ss >> st;
s = (*it).assignmentName + " " + st + "\n";
return s;
}
 
 
//*************************
//main.cpp
//**************************
#include <iostream>
#include <iomanip>
#include <vector> 
#include <string>
#include <sstream>
#include <fstream>
#include "Student.h"
using namespace std;
 
 
 
int enterChoice()
{
cout << "\nEnter your choice" << endl
<< "1 - Add a student" << endl
<< "2 - Modify a student" << endl
<< "3 - Delete a student" << endl
<< "0 - Exit\n" << endl << endl << endl;
 
int menuChoice;
cin >> menuChoice;
return menuChoice;
}
int enterModChoice()
{
cout << "\nEnter your choice" << endl
<< "1 - Change student's first name" << endl
<< "2 - Change student's last name" << endl
<< "3 - Change student's student number" << endl
<< "4 - change students assignment/grades" << endl
<< "0 - Exit\n" << endl << endl << endl;
 
int menuChoice;
cin >> menuChoice;
return menuChoice;
}
 
 
void printOut(vector<Student> &vecStud)
{
cout << "Student" << setw(25) << "Grade" <<endl;
for (vector<Student>::iterator it = vecStud.begin();
it != vecStud.end(); it++)
{
cout << (*it).getFirstName() << " " <<
(*it).getLastName() << " :" <<
endl;
}
}
 
int main()
{
//Load up the student data text file into vector
vector < Student > vecStudent;
ifstream myFile("studentData.txt");
string fname;
string lname;
string ssn;
int numMarks;
string assName;
int assGrade;
 
Student::Grade tempGrade;
while (myFile >> fname >> lname >> ssn)
{
Student tempStu(fname,lname,ssn);
 
while (myFile >> assName >> assGrade)
{
tempGrade.assignmentName = assName;
tempGrade.assignmentGrade = assGrade;
tempStu.vecGrade.push_back(tempGrade);
}
vecStudent.push_back(tempStu);
}
start:
printOut(vecStudent);
 
int choice;
int choice2;
int c;
string result;
while ( ( choice = enterChoice() ) != 0)
{
 
switch ( choice )
{
case 1:
{//add a student

cout << endl << endl << endl;
cout << "Adding student...." << endl << endl << endl;
cout << "What is the student's first name? : ";
cin >> fname;
cout << endl << "What is the student's last name? : ";
cin >> lname;
cout << endl << "What is the student's student number? : ";
cin >> ssn;
Student tempStu(fname,lname,ssn);
cout << endl << "How many assignments do you want to enter /w marks?" << endl;
cin >> c;
for (int x=0; x < c; x++)
{
cout << endl << "What's the assignment's title?" << endl;
cin >> assName;
tempGrade.assignmentName = assName;
cout << endl << "What's the assignment's grade?" << endl;
cin >> assGrade;
tempGrade.assignmentGrade = assGrade;
tempStu.vecGrade.push_back(tempGrade);
}
 
vecStudent.push_back(tempStu);
//How many assignments/grades do you want to put in?
//loop inputting grades into Student grade vector
printOut(vecStudent);
break;
}
case 2:
{
//modify and student
cout << "Modifing a student......" << endl << endl << endl;
cout << "What is the student's student number\n who you want to modify?" << endl << endl;
cin >> ssn;
 
//search for student
for (vector<Student>::iterator it = vecStudent.begin();
it != vecStudent.end(); it++)
{
//THIS DOESNT WORK*******
if ((*it).getStudentNumber() == ssn)
{
cout << "Student found......" << endl;
 
//display menu for changing a student's stats
while ( ( choice2 = enterModChoice() ) != 0)
{
switch ( choice2 )
{
case 1:
//set/change students first name
cout << "Enter student's new first name: ";
cin >> result;
(*it).setFirstName( result );
break;
case 2:
//set/change student's last name
cout << "Enter student's new last name: ";
cin >> result;
(*it).setLastName( result );
break;
case 3:
//set/change student's student number
cout << "Enter student's new student number: ";
cin >> result;
(*it).setStudentNumber( result );
break;
case 4:
//print off assignment list (vector of struct Grade's inside Student) w/grades
cout << (*it).printGrades();
//Bring up another menu for what assignment to change

cout << "\nEnter your choice" << endl
<< "1 - Modify Grade Name/Mark" << endl
<< "0 - Exit\n" << endl << endl << endl;
int cc;
cin >> cc;
if (cc=0)
break;
else
{
cout << "which assignment do you want to change? (1-10);" << endl;
cin >> cc;
cout << endl << "What do you want the new assignment name to be? :";
cin >> assName;
cout << endl << "what do you want the new assignment grade to be? :";
cin >> assGrade;
 
vector<Student::Grade>::iterator itv = (*it).vecGrade.begin();
itv += cc;
 
(*itv).assignmentName = assName;
(*itv).assignmentGrade = assGrade;
cout << (*it).printGrades();
break;
}
 
 
//enter assignemnt # 1-10
// change 1: name or 2: grade
// if 
break;
case 0:
 
break;
default:
cout << "You entered a wrong number" << endl;
goto start;
break;
}
}
}
 
else
{
cout << "Sorry, either the number was incorrectly inputted"
<< "\n or the student does not exist." << endl;
goto start;
}
}
break;
}
case 3:
{
//delete a student
cout << "Deleting a student......" << endl << endl << endl;
cout << "What is the student's student number\n who you want to delete?" << endl << endl;
cin >> ssn;
 
for (vector<Student>::iterator it = vecStudent.begin();
it != vecStudent.end(); it++)
{
//THIS DOESNT WORK, how do i compare the strings properly?
if ( (*it).getStudentNumber() == ssn)
{
cout << "Sorry, either the number was incorrectly inputted"
<< "\n or the student does not exist." << endl;
}
else
{
cout << "Student found......" << endl;
cout << "Deleting...." << endl;
 
//DOESNT WORK, i guess i have to delete it from the vector somehow aswell?
vecStudent.erase(it, it+1);
//delete (*it);
}
}
break;
}
case 0:
{
//exit
 
//save Student vector to file, outputting everything

fstream myFile("studentData.txt",ios::out);
myFile.trunc;
 
for (vector<Student>::iterator it = vecStudent.begin();
it != vecStudent.end(); it++)
{
 
myFile << (*it).getFirstName() << " " <<
(*it).getLastName() << " " << (*it).getStudentNumber() << endl;
//print out grades
myFile << (*it).printGrades() << endl;
 
}
myFile.close();
return 0;
}
default:
{//error msg, 
cout << "You have put in an incorrect choice" << endl;
goto start;
}
break;
}
}
 
 
 
return 0;
}
 
 
 
}

double post

Member Avatar for iamthwee

//THIS DOESNT WORK, how do i compare the strings properly?

if ( (*it).getStudentNumber() == ssn)
{
cout << "Sorry, either the number was incorrectly inputted"
<< "\n or the student does not exist." << endl;
}
else
{
cout << "Student found......" << endl;
cout << "Deleting...." << endl;
}

Erm, don't you think you have your logic mixed up?

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.