Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.4k views
in Technique[技术] by (71.8m points)

c++ - using map for an array of objects where the data members are to be mapped

I want to store the roll and score of the students in a map in the sorted order of roll and also retrieve the score for a given roll. The student information are to be stored in a class. I referred to a no. of past stack overflow posts where mapping of data members was explained but they were not specifically working on array of objects, here I want a an array or vector of students and their roll and scores are to be mapped.

following is my class design but now I am clueless how to advance on the same, please help

#include <iostream>
#include <map>
#include <cstring>
#incude <utility>
using namespace std;
class Student
{
    int roll;
    float score;
    map<int,float>stdt;
    public:
        Student(int r=0,float s=0.0)
        {
            roll=r;
            score=s;
            stdt[roll]=score;
        }
        void insert_data(int n, float f)
        {
            stdt.insert(pair<int,float>(n,f));
        }

};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...