1#ifndef STUDENT_H
2#define STUDENT_H
3
4#include <string>
5#include <iostream>
6
7/**
8 * @brief Represents a student with basic academic information
9 *
10 * This class demonstrates:
11 * - Encapsulation with private members and public accessors
12 * - Operator overloading for comparison and output
13 * - String serialization for persistence
14 */
15class Student {
16private:
17 int id;
18 std::string name;
19 std::string major;
20 double gpa;
21
22public:
23 // Constructor
24 Student(int id, const std::string& name, const std::string& major, double gpa);
25
26 // Default constructor
27 Student() : id(0), name(""), major(""), gpa(0.0) {}
28
29 // Getters
30 int getId() const { return id; }
31 std::string getName() const { return name; }
32 std::string getMajor() const { return major; }
33 double getGpa() const { return gpa; }
34
35 // Setters
36 void setName(const std::string& newName) { name = newName; }
37 void setMajor(const std::string& newMajor) { major = newMajor; }
38 void setGpa(double newGpa) { gpa = newGpa; }
39
40 // Comparison operators (for sorting)
41 bool operator<(const Student& other) const { return id < other.id; }
42 bool operator==(const Student& other) const { return id == other.id; }
43
44 // Serialization
45 std::string toCSV() const;
46 static Student fromCSV(const std::string& csvLine);
47
48 // Stream insertion operator
49 friend std::ostream& operator<<(std::ostream& os, const Student& student);
50};
51
52#endif // STUDENT_H