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;
}