Associative container, data structure in C++

Thread Starter

sakpase

Joined Mar 22, 2012
3
Hi, I would like to get some help with this program


I am trying to implement a student grading system.
-Use an Associative container, multimap.
-Search record by Student name (the key) and the data consists of student ID and GPA.
Since more than one student can have the same name, use
multimap.

progam does the following:
1. It will use a multimap as the container.
2. It will use the Student class to describe the
ID and GPA. multimap will be declared:
multimap<string, Student> grades;
3. use data(names, IDs and GPAs)
4. The main() driver will display a menu of commands available to
the user: The commands are:
a. insert a student’s data into the system, The program will
allow duplicate names to be inserted.
b. Find a student’s data, given the student’s name(key). If
there are multiple students in the container with the given
name, display information about all of them.
c.. Exit the system

d. it should have files (.h and .cpp)
 

Thread Starter

sakpase

Joined Mar 22, 2012
3
Rich (BB code):
using namespace std;
int main()
{
typedef multimap<string, Student, less<string>> grades1;
typedef multimap<Student, string, less<Student>> grades2;
grades1 a1; 
grades2 a2;  
Student s;
s = Student(12345, 3.3); a1["Fr"] = s; a2 = "Fr";
s = Student(32322, 3.9); a1["Al"] = s; a2 = "Al";
s = Student(13131, 2.5); a1["Jo"] = s; a2 = "Jo";
s = Student(22121, 4.0); a1["Ba"] = s; a2 = "Ba";
s = Student(28888, 2.9); a1["Ge"] = s; a2 = "Ge";
s = Student(19981, 3.0); a1["Do"] = s; a2 = "Do";
s = Student(20012, 2.9); a1["Su"] = s; a2 = "Su";
string name;
cout << "name: ";
cin >> name;
grades1::iterator it1 = a1.find(name);
cout << name << " has ";
if (it1 == a1.end())
cout << "noinfo";
else
cout << a1[name];
cout << endl;
Student aStudent;
cout << "Enter id & GPA: ";
cin >> aStudent;
grades2::iterator it2 = a2.find(aStudent);
cout << "Student " << aStudent << " is ";
if (it2 == a2.end())
cout << "noinfo";
else
cout << a2[aStudent];
cout << endl;
}
 
Last edited by a moderator:

vpoko

Joined Jan 5, 2012
267
I'm not sure what your question is. I doubt anyone will finish your assignment for you, but if you're having difficulties with something specific we might be able to help. Where are you stuck?
 

Thread Starter

sakpase

Joined Mar 22, 2012
3
I am not sure if I implemented the MultiMap correct and .h (header files). because I need to have .h and .cpp files. my code has just one file. please organize the program the right way. thanks
 
Top