Skip to content

Instantly share code, notes, and snippets.

@mauricio
Created January 5, 2012 12:56
Show Gist options
  • Save mauricio/1565152 to your computer and use it in GitHub Desktop.
Save mauricio/1565152 to your computer and use it in GitHub Desktop.
#include "studentinfo.h"
bool compare( const StudentInfo& x, const StudentInfo& y )
{
return x.name() < y.name();
}
StudentInfo::StudentInfo() : midterm(0), final(0) {}
StudentInfo::StudentInfo( double _midterm, double _final, std::vector<double> _homework ) {
this->final = _final;
this->midterm = _midterm;
this->homework = _homework;
}
#ifndef STUDENTINFO_H
#define STUDENTINFO_H
#include <istream>
#include <string>
#include <vector>
class StudentInfo
{
public:
StudentInfo();
StudentInfo( double _midterm, double _final, std::vector<double>& _homework );
double grade() const;
std::istream& read(std::istream&);
std::string name() const { return _name; }
private:
std::string _name;
double midterm, final;
std::vector<double> homework;
};
bool compare( const StudentInfo& x, const StudentInfo& y );
#endif // STUDENTINFO_H
@rscarvalho
Copy link

you can replace this constructor:

StudentInfo::StudentInfo( double _midterm, double _final, std::vector<double> _homework ) {
    this->final = _final;
    this->midterm = _midterm;
    this->homework = _homework;
}

by this (write this in the header file):

/* ... */
public:
StudentInfo( double _midterm, double _final, std::vector<double> _homework )
  : final(_final), midterm(_midterm), homework(_homework) {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment