Skip to content

Commit ddab38b

Browse files
author
Anika
committed
Add Student.cpp class
1 parent 0ff2c06 commit ddab38b

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Student.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <iostream>
2+
#include <string>
3+
using namespace std;
4+
5+
class Student {
6+
private:
7+
int id;
8+
string name;
9+
double grade;
10+
11+
public:
12+
// Constructor
13+
Student(int id, string name, double grade) {
14+
this->id = id;
15+
this->name = name;
16+
this->grade = grade;
17+
}
18+
19+
// Getters
20+
int getId() { return id; }
21+
string getName() { return name; }
22+
double getGrade() { return grade; }
23+
24+
// Setters
25+
void setId(int id) { this->id = id; }
26+
void setName(string name) { this->name = name; }
27+
void setGrade(double grade) { this->grade = grade; }
28+
29+
// Display
30+
void display() {
31+
cout << "ID: " << id << ", Name: " << name << ", Grade: " << grade << endl;
32+
}
33+
};
34+
35+
// Example usage
36+
int main() {
37+
Student s1(1, "Alice", 95.5);
38+
s1.display();
39+
return 0;
40+
}

0 commit comments

Comments
 (0)