It 2nd Year Group 5 c++ Group Assignment(1) (1)
It 2nd Year Group 5 c++ Group Assignment(1) (1)
GROUP NAME ID No
1.ALAFI TESHOMA……………………Ru0432\16
2.AYANTU MELAKU………………….Ru0502\16
3.GELGELU WABE…………………….Ru0333\16
4.KALID ABDURHMAN……………….Ru0689\16
5.MITIKU AYELE………………………Ru0170\16
SUBMITTED TO:Mr.KELEMU
SUBMITION DATE:22/04/2017
1
BULE HORA,ETHIOPIA
C++ Console Group Assignment:
Student Grade Management System with OOP
Scenario:
You are tasked with developing a Student Grade Management
System for BHU. The system should help teachers manage and
track student grades efficiently. The following features need to
be implemented using OOP principles using c++program:
Student Management:
Create a Student class with properties such as Name,
StudentID, Class, and other necessary attributes
Add methods to the Student class for updating student
details.
Grade Management:
Create a Grade class with properties such as Subject, Score,
and StudentID.
Add methods to the Grade class for updating and deleting
grades.
Grade Calculation:
Create a GradeCalculator class with methods to calculate
the average grade for each student, determine the highest
and lowest grades in each subject, and provide a summary
of grades for each class.
User Interaction:
Implement a console-based menu system to navigate
through the different functionalities.
2
Use c++ collections (e.g., Vectors) to store instances of
Student and Grade objects.
Ensure the system can handle multiple students and
subjects, providing accurate calculations.
Requirements: You are expected to
Use classes and objects to encapsulate data and
functionality.
Implement inheritance and polymorphism where
appropriate.
Reuse code by creating methods that can be called fro m
different parts of the application.
Implement error handling to manage invalid inputs.
Ensure the application can handle basic operations without
a graphical user interface.
Expected Outcome(Deliverables):
A C++ console application project file with all the
necessary classes and code.
A brief report explaining the design, functionality, and
OOP principles used in the system
3
Example Emplementation
Here is a brief examples of how to you might begin coding the
Bhu student grade management system with OOP
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#include <limits>
using namespace std;
// Student Class
class Student {
private:
int studentID;
string name;
string department;
public:
// Constructor
Student(int id, string n, string dept) : studentID(id), name(n),
department(dept) {}
// Getters
int getStudentID() const { return studentID; }
4
string getName() const { return name; }
string getDepartment() const { return department; }
5
int getStudentID() const { return studentID; }
string getSubject() const { return subject; }
float getScore() const { return score; }
// Update grade details
void updateGrade(float newScore) {
score = newScore;
}
// Display grade
void display() const {
cout << "Student ID: " << studentID << ", Subject: " <<
subject << ", Score: " << score << endl;
}
};
// GradeCalculator Class
class GradeCalculator {
public:
// Calculate average grade for a student
static float calculateAverage(const vector<Grade>& grades,
int studentID) {
float totalScore = 0;
int count = 0;
for (const Grade& grade : grades) {
if (grade.getStudentID() == studentID) {
totalScore += grade.getScore();
count++;
6
}
}
if (count == 0) return 0; // No grades for the student
return totalScore / count;
}
// Find the highest and lowest grades in a subject
static pair<float, float> findHighLowInSubject(const
vector<Grade>& grades, const string& subject) {
float highest = numeric_limits<float>::min();
float lowest = numeric_limits<float>::max();
bool found = false;
7
static void displayGradeSummary(const vector<Student>&
students, const vector<Grade>& grades) {
for (const Student& student : students) {
cout << "Summary for " << student.getName() << " (ID:
" << student.getStudentID() << "):" << endl;
float avg = calculateAverage(grades,
student.getStudentID());
cout << "Average Grade: " << avg << endl;
cout << "--------------------------------------" << endl;
}
}
};
// Main Application
int main() {
vector<Student> students;
vector<Grade> grades;
while (true) {
cout << "\n BHU STUDENT GRADE MANAGEMENT
SYSTEM " << endl;
cout << "1. Add Student" << endl;
cout << "2. Update Student Details" << endl;
cout << "3. Add Grade" << endl;
cout << "4. Update Grade" << endl;
cout << "5. Calculate Average Grade for a Student" <<
endl;
8
cout << "6. Find Highest and Lowest Grades in a Subject"
<< endl;
cout << "7. Display Grade Summary for All Students" <<
endl;
cout << "8. Exit" << endl;
cout << "Enter your choice: ";
int choice;
cin >> choice;
switch (choice) {
case 1: {
// Add a new student
int id;
string name, department;
cout << "Enter Student ID: ";
cin >> id;
cin.ignore();
cout << "Enter Student Name: ";
getline(cin, name);
cout << "Enter Department: ";
getline(cin, department);
students.push_back(Student(id, name, department));
cout << "Student added successfully!" << endl;
break;
}
case 2: {
9
// Update student details
int id;
cout << "Enter Student ID to update: ";
cin >> id;
auto it = find_if(students.begin(), students.end(),
[id](const Student& s) {
return s.getStudentID() == id;
});
if (it != students.end()) {
string newName, newDept;
cin.ignore();
cout << "Enter New Name: ";
getline(cin, newName);
cout << "Enter New Department: ";
getline(cin, newDept);
it->updateDetails(newName, newDept);
cout << "Student details updated successfully!" <<
endl;
} else {
cout << "Student not found!" << endl;
}
break;
}
case 3: {
// Add a grade
10
int id;
string subject;
float score;
cout << "Enter Student ID: ";
cin >> id;
cin.ignore();
cout << "Enter Subject: ";
getline(cin, subject);
cout << "Enter Score: ";
cin >> score;
grades.push_back(Grade(id, subject, score));
cout << "Grade added successfully!" << endl;
break;
}
case 4: {
// Update grade details
int id;
string subject;
cout << "Enter Student ID: ";
cin >> id;
cin.ignore();
cout << "Enter Subject: ";
getline(cin, subject);
auto it = find_if(grades.begin(), grades.end(), [id,
subject](const Grade& g) {
11
return g.getStudentID() == id && g.getSubject() ==
subject;
});
if (it != grades.end()) {
float newScore;
cout << "Enter New Score: ";
cin >> newScore;
it->updateGrade(newScore);
cout << "Grade updated successfully!" << endl;
} else {
cout << "Grade not found!" << endl;
}
break;
}
case 5: {
// Calculate average grade for a student
int id;
cout << "Enter Student ID: ";
cin >> id;
12
}
break;
}
case 6: {
// Find highest and lowest grades in a subject
string subject;
cin.ignore();
cout << "Enter Subject: ";
getline(cin, subject);
auto [highest, lowest] =
GradeCalculator::findHighLowInSubject(grades, subject);
if (highest == 0 && lowest == 0) {
cout << "No grades found for the subject!" << endl;
} else {
cout << "Highest Grade: " << highest << ", Lowest
Grade: " << lowest << endl;
}
break;
}
case 7: {
// Display grade summary for all students
GradeCalculator::displayGradeSummary(students,
grades);
break;
}
13
case 8: {
// Exit
cout << "Exiting... Goodbye!" << endl;
return 0;
}
default: {
cout << "Invalid choice! Please try again." << endl;
}
}
}
return 0;
}
4 Brief Report:
Key Components:
Student Class:
14
Properties: StudentID, Name, Grade.
Grade Class:
GradeCalculator Class:
User Interaction:
15
1. Encapsulation: Encapsulation is the concept of bundling the
data (attributes) and methods (functions) that operate on the data
into a single unit, or class. This principle is used extensively in
the system to group related properties and methods within
classes.
Student Class:
Grade Class:
GradeCalculator Class:
16
5. Error Handling: While the provided code focuses on
functionality, error handling mechanisms are crucial for a robust
system. Implementing input validation and error messages can
ensure that the system handles invalid inputs gracefully and
provides feedback to users.
Conclusion
17