GIDForums

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Apr-2007, 18:35
devster420 devster420 is offline
New Member
 
Join Date: Apr 2007
Posts: 2
devster420 is on a distinguished road

Multiple questions for C++ project


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
-Have a menu system for navigation
-add a student
-delete a student
-modify a student
-quit (save vector in text file on quit

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.

Code:
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




CPP / C++ / C Code:


//******************
//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



CPP / C++ / C Code:
//*************
//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;
    }
}

CPP / C++ / C Code:
//**************
//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;
}

Last edited by admin II : 20-Apr-2007 at 19:36. Reason: Please surround your C++ code with [CPP] ... [/CPP] [CODE] tag for compiler output
  #2  
Old 20-Apr-2007, 21:26
devster420 devster420 is offline
New Member
 
Join Date: Apr 2007
Posts: 2
devster420 is on a distinguished road

Re: Multiple questions for C++ project


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 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....

Code:
//******************* //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

CPP / C++ / C Code:
//***********
//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

CPP / C++ / C Code:
//*************
//Student.cpp
//*************
#include<iostream>
#include<sstream>
#include<string>
usingnamespace 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;
}

CPP / C++ / C Code:
//*************************
//main.cpp
//**************************
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<sstream>
#include<fstream>
#include"Student.h"
usingnamespace 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;
}
 
 
 
}
Last edited by LuciWiz : 21-Apr-2007 at 18:37. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
 

Recent GIDBlogUpdates On The All New Toyota VIOS - Part III by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VPS at ArteryPlanet.Net - Virtuozzo/cPanel/ WHM/Fantastico Multiple Free domain names arteryplanet Web Hosting Advertisements & Offers 0 07-Apr-2006 12:23
Need help with Simple 1D Array coding project rho CPP / C++ Forum 2 27-Jun-2005 19:05
Linker errors with multiple file progam nkhambal C Programming Language 2 24-Apr-2005 02:37
Community Project Proposal dsmith Miscellaneous Programming Forum 71 19-Feb-2005 12:26
Help! Some basal questions about MFC xutingnjupt MS Visual C++ / MFC Forum 1 05-Dec-2004 03:38

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:58.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.