-
Notifications
You must be signed in to change notification settings - Fork 21.1k
Expand file tree
/
Copy pathStudent.cpp
More file actions
40 lines (34 loc) · 816 Bytes
/
Student.cpp
File metadata and controls
40 lines (34 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
int id;
string name;
double grade;
public:
// Constructor
Student(int id, string name, double grade) {
this->id = id;
this->name = name;
this->grade = grade;
}
// Getters
int getId() { return id; }
string getName() { return name; }
double getGrade() { return grade; }
// Setters
void setId(int id) { this->id = id; }
void setName(string name) { this->name = name; }
void setGrade(double grade) { this->grade = grade; }
// Display
void display() {
cout << "ID: " << id << ", Name: " << name << ", Grade: " << grade << endl;
}
};
// Example usage
int main() {
Student s1(1, "Alice", 95.5);
s1.display();
return 0;
}