sorting the result

Hello

here is a code. When i try to compile it it shows a n error ** error: 'stod' is not a member of 'std'** even though i have included string library. Can someone give a solution to it? It is suppose to give an output as follows:

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
** Showing populated data...
Grading Percentage Raw-Score Adj-Score
Quiz 5% B- 3.34
Quiz 5% C+ 2.91
Quiz 5% A 5.00
Midterm 10% 50.000000 5.00
Final 30% 85.500000 25.65
Project 5% A- 4.59
Project 15% B- 10.01
Project 15% B- 10.01
Demo 10% C 5.00
100% 71.51


** Showing sorted by name...
Grading Percentage Raw-Score Adj-Score
Demo 10% C 5.00
Final 30% 85.500000 25.65
Midterm 10% 50.000000 5.00
Project 15% B- 10.01
Project 15% B- 10.01
Project 5% A- 4.59
Quiz 5% A 5.00
Quiz 5% B- 3.34
Quiz 5% C+ 2.91
100% 71.51


** Showing sorted by score...
Grading Percentage Raw-Score Adj-Score
Final 30% 85.500000 25.65
Project 15% B- 10.01
Project 15% B- 10.01
Demo 10% C 5.00
Midterm 10% 50.000000 5.00
Quiz 5% A 5.00
Project 5% A- 4.59
Quiz 5% B- 3.34
Quiz 5% C+ 2.91
100% 71.51
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------




#include <iostream>
#include <vector>
#include <string>
using namespace std;

struct Grading{
string name;
int percentage;
virtual ~Grading(){}
virtual std::string get_raw_score() = 0; //make pure virtual since we only use Grading as a base class
void* get_adj_score(){return 0;}
};

struct Quiz:public Grading{
string letter_grade;
Quiz(const string title, const int weight, const string grade){
name=title;
percentage=weight;
letter_grade=grade;
}
virtual std::string get_raw_score(){return letter_grade;}
};

struct Exam:public Grading{
double score; // this does not need to be a pointer
Exam(const string title, const int weight, const double grade){
name=title;
percentage=weight;
score=grade; // no more dereference
}
virtual std::string get_raw_score(){return std::stod(score);} // now the score is represented as a string
};

struct Project:public Grading{
string letter_grade;
Project(const string title, const int weight, const string grade){
name=title;
percentage=weight;
letter_grade=grade;
}
virtual std::string get_raw_score(){return letter_grade;}
};

struct CourseWork{
vector<Grading*> gs;
void push_back(Grading* g){
gs.push_back(g);
}
void sort_name(){}
void sort_score(){}
};

ostream& operator<<(ostream& o,const CourseWork c){ //output the raw score here.
//static_cast<struct Grading*>(c.gs[0]);
o<<c.gs[0]->name<<endl<<c.gs[0]->percentage<<c.gs[0]->get_raw_score()<<endl;
return o;
}
int main() {

CourseWork c;

c.push_back(new Quiz("Quiz", 5, "B-"));
c.push_back(new Quiz("Quiz", 5, "C+"));
c.push_back(new Quiz("Quiz", 5, "A"));
c.push_back(new Exam("Midterm", 10, 50));
c.push_back(new Exam("Final", 30, 85.5));
c.push_back(new Project("Project", 5, "A-"));
c.push_back(new Project("Project", 15, "B-"));
c.push_back(new Project("Project", 15, "B-"));
c.push_back(new Project("Demo", 10, "C"));

cout << "** Showing populated data..." << endl;
cout << c << endl << endl;;

c.sort_name();
cout << "** Showing sorted by name..." << endl;
cout << c << endl << endl;

c.sort_score();
cout << "** Showing sorted by score..." << endl;
cout << c << endl;

return 0;
}
Last edited on
virtual get raw score return std::stod which does not exist and is not a string
how can i fix this?
return std::to_string(score); i guess
Topic archived. No new replies allowed.