Commit 5c4d448
committed
feat: Add Student class with methods for total, average, grade, and details
WHAT the code does:
Defines Student class with public fields:
- rollno, name, course, and three marks (m1, m2, m3).
Implements methods:
- total(): returns sum of marks.
- average(): returns average as float.
- grade(): assigns grade based on average (A, B, or C).
- Details(): returns formatted string with student information.
Defines StudentTest with main():
- Creates a Student object, sets properties manually.
- Prints total, average, and details.
WHY this matters:
Demonstrates basic OOP design with attributes (fields) and behaviors (methods).
Encapsulates common student operations like total, average, and grading into methods.
Illustrates how methods can reuse each other (average() calls total()).
Provides a real-world example of class modeling for education-related applications.
HOW it works:
Student object is created and initialized with rollno=1, name="Don", course="CSE", marks=70,60,50.
total() → 180.
average() → 60.0.
grade() would return 'B' (though unused in main).
Details() prints student info, but concatenates marks without spaces (705060).
Tips and gotchas:
Field names are public, breaking encapsulation; prefer private fields with getters/setters.
Details() concatenates marks directly; adding spaces or formatting would improve readability.
grade() is implemented but never called in StudentTest.
Naming conventions: Course should be lowercase course, and method names should start with lowercase (details()).
For multiple students, using arrays or lists would make this more scalable.
Use-cases:
Educational example of combining fields and methods in a class.
Foundation for a grading or student management system.
Practical demonstration of OOP concepts for beginners.
Short key: class-student methods total-average-grade details.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent dc61946 commit 5c4d448
1 file changed
+16
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
| |||
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
41 | 32 | | |
42 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
43 | 36 | | |
44 | | - | |
45 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
46 | 40 | | |
47 | | - | |
| 41 | + | |
48 | 42 | | |
49 | | - | |
50 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
0 commit comments