and i want to do followig things i didn't get them....can u pls help me to do that
(1) Constructor ITECH7603Class() and the destructor:
A default constructor initializes dynamically the group field.
The destructor deletes the group pointer.
(2) Constructor ITECH7603Class(int dummy):
This constructor does not require any parameter. However, to distinguish it from the default constructor you should use some dummy argument (say of int type). This constructor opens the “ITECH7603Students.bin” file, if such file exists, and reads information from the file into the (*group) map using addStudent() function. If the file “ITECH7603Students.bin” does not exist, the constructor behaves as the default constructor.
(3) Constructor ITECH7603Class(set<Student>* students):
This constructor takes a set of Student objects (in fact, a pointer to the set) as an argument and adds students from the set to the (*group) map, i.e. initializes the group field.
hey guys....I got your suggesion....I tried a lot....man....but I haven't done pointer any where...in my whole study.....that's y I am asking..this quesion is not just i asked u...there are so manu other things I did my self...this is just bit part of it...If it will be solved I can go ahead...that's y guys.....
I am sorry abt asking u same question again.....
Pls help me in this case guys.....
Thanking u for your concern...(whether u reply or not..)
class Student{
public:
Student();
Student(string name,string surname,int a1, int a2, int test, int exam);
string getName()const;
string getSurname()const;
int getAssignment1Mark()const;
int getAssignment2Mark()const;
int getLabTestMark()const;
int getExamMark()const;
The save function should be ITECH7603Class::save rather than a global save function. It might be better to pass a stream to save onto rather than doing the file stuff in the save function. More on that later.
The syntax for iterating the map would be something like:
1 2 3
for (std::map<std::string, Student>::iterator iter = group->begin(); iter != group->end(); ++iter)
{
}
I also think that making group a pointer to a map is unnecessary it this instance.
Next is serialisation. If you want to save a collection of things, you should ask each element to save itself. The save function you posted attempts to save the elements itself. It can't do it properly because the data in the objects is private (as it should be). If you added the ability to read/write Students on streams, your life would be much simpler. You already have half of it.
1 2 3 4 5 6 7 8 9
std::ostream& Student::operator<<(std::ostream &os, const Student &s)
{
os << s.name << std::endl;
os << s.surname << std::endl;
os << s.assignment1Mark << ' ';
os << s.assignment2Mark << ' ';
os << s.labTestMark << ' '
os << s.examMark << std::endl;
}
Back to the save function. It might be better to write code like:
So putting it all together, your save function looks like:
1 2 3 4 5 6 7 8
void ITECH7603Class::save(std::ostream &os)
{
// if we declare group as a map rather than a pointer to a map
for (std::map<std::string, Student>::iterator iter = group.begin(); iter != group.end(); ++iter)
{
os << *iter;
}
}
Do I need to initialize group filed any where else in my code..?
I have changed the save function like below:
void ITECH7603Class::save(std::ostream &os)
{
std::map<std::string, Student>::iterator iter;
for (iter = group.begin(); iter != group.end(); ++iter)
{
os << *iter;
}
}
Note : I have to use pointer to map cause that's description in my assignment...so what would b the other way to solve this problem using pointer to map.
but it gives me error like
"error: request for member `begin' in `((ITECH7603Class*)this)->ITECH7603Class::group', which is of non-class type `std::map<std::string, Student, std::less<std::string>, std::allocator<std::pair<const std::string, Student> > >*'"