#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// Define a structure to store student information
struct Student {
int Sno;
string Student_Id;
string First_Name;
string Father_Name;
string G_Father_Name;
string Sex;
string dept;
int Mid;
int final;
string Grade;
};
void dispbydept(int n, struct Student students[]);
void overallgrade(int n, struct Student students[]);
void addstud(int n, struct Student students[]);
void display(int n, struct Student students[]);
void countdep(int n,struct Student students[]);
void Exit();
void Exit(){
cout<<"\ Have a nice time\n";
}
void addstud(int n, struct Student students[]){
// Loop to get information for each student
for (int i = 0; i < n; ++i) {
students[i].Sno=i+1;
cout << "Enter information for student " << i + 1 << ":" << endl;
cout << "Student Id: ";
cin >> students[i].Student_Id;
cout << "First Name: ";
cin >> students[i].First_Name;
cout << "Father Name: ";
cin >> students[i].Father_Name;
cout << "G.Father Name: ";
cin >> students[i].G_Father_Name;
cout << "Sex: ";
cin >> students[i].Sex;
cout << "Department: ";
cin >> students[i].dept;
cout << "Mid(40%): ";
cin >> students[i].Mid;
cout << "final(60%): ";
cin >> students[i].final;
}
}
void display(int n, struct Student students[]) {
// Q.2 Display the information
cout << endl<<"Displaying Information of Students:" << endl;
cout << "Sno |";
cout <<setw(15)<< "Student Id | ";
cout<<setw(15) << "First Name |";
cout <<setw(15)<< "Father Name |";
cout <<setw(16)<<"G.Father Name |";
cout <<setw(5)<< "Sex |";
cout <<setw(5)<< "dept |";
cout <<setw(10)<< "Mid(40%)|";
cout <<setw(10)<< "final(60%)|";
cout <<setw(5)<< "Grade |"<<endl;
for (int i = 0; i < n; ++i) {
cout<<"____________________________________________________________________________
_________________________________\n";
cout <<setw(3)<<students[i].Sno<<"|" ;
cout <<setw(14)<< students[i].Student_Id <<"|";
cout <<setw(15)<< students[i].First_Name <<"|";
cout <<setw(15)<< students[i].Father_Name <<"|";
cout <<setw(14)<< students[i].G_Father_Name<<"|" ;
cout <<setw(5)<< students[i].Sex<<"|" ;
cout <<setw(5)<< students[i].dept<<"|" ;
cout <<setw(10)<< students[i].Mid <<"|";
cout <<setw(10)<< students[i].final<<"|";
int total=students[i].Mid + students[i].final;
string grade;
if(total>=90){
grade="A+";
}
else if (total>=85){
grade="A";
}
else if (total>=80){
grade="A-";
}
else if (total>=75){
grade="B+";
}
else if (total>=70){
grade="B";
}
else if (total>=65){
grade="B-";
}
else if (total>=60){
grade="C+";
}
else if (total>=55){
grade="C";
}
else if (total>=50){
grade="C-";
}
else if (total>=45){
grade="D";
}
else {
grade="F";
}
students[i].Grade=grade;
cout <<setw(5) <<grade<< "|"<< endl;
}
}
void countdep(int n, struct Student students[]) {
//count number of students per department
M:
int counter=0;
string check;
cout<<"enter the department you want to count number of student \n";
cin>>check;
for (int i=0;i<n;i++){
if(check==students[i].dept){
counter++;
cout<<"____________________________________________________________________________
_________________________________\n";
cout <<setw(3)<<students[i].Sno<<"|" ;
cout <<setw(14)<< students[i].Student_Id <<"|";
cout <<setw(15)<< students[i].First_Name <<"|";
cout <<setw(15)<< students[i].Father_Name <<"|";
cout <<setw(14)<< students[i].G_Father_Name<<"|" ;
cout <<setw(5)<< students[i].Sex<<"|" ;
cout <<setw(5)<< students[i].dept<<"|" ;
cout <<setw(10)<< students[i].Mid <<"|";
cout <<setw(10)<< students[i].final<<"|";
int total=students[i].Mid + students[i].final;
string grade;
if(total>=90){
grade="A+";
}
else if (total>=85){
grade="A";
}
else if (total>=80){
grade="A-";
}
else if (total>=75){
grade="B+";
}
else if (total>=70){
grade="B";
}
else if (total>=65){
grade="B-";
}
else if (total>=60){
grade="C+";
}
else if (total>=55){
grade="C";
}
else if (total>=50){
grade="C-";
}
else if (total>=45){
grade="D";
}
else {
grade="F";
}
students[i].Grade=grade;
cout <<setw(5) <<grade<< "|"<< endl;
}
}
cout<<"\n Total student for \""<<check<<"\" Department is : "<<counter<<endl;
cout<<"\n Do you want to check other department ? Y/N \n";
string des;
cin>>des;
if((des=="Y")||(des=="y")){
goto M;
}
else if((des=="N")||(des=="n")){
cout<<"10Q \n";
}
}
void overallgrade(int n, struct Student students[]){
// grade for total student average
int sum=0;
int average;
for(int i=0;i<n;i++){
sum +=students[i].Mid + students[i].final;
}
average=sum/n;
string grade;
if(average>=90){
grade="A+";
}
else if (average>=85){
grade="A";
}
else if (average>=80){
grade="A-";
}
else if (average>=75){
grade="B+";
}
else if (average>=70){
grade="B";
}
else if (average>=65){
grade="B-";
}
else if (average>=60){
grade="C+";
}
else if (average>=55){
grade="C";
}
else if (average>=50){
grade="C-";
}
else if (average>=45){
grade="D";
}
else {
grade="F";
}
cout<<"\n average grade of all students is :"<<grade<<endl;
}
void dispbydept(int n, struct Student students[]) {
// Create a fixed-size array to hold department names and counts
string dept[n][2] = {};
// Initialize department counts to zero
for (int i = 0; i < n; ++i) {
dept[i][1] = "0"; // Initialize count as string "0"
}
// Traverse through the students array and count each department
for (int i = 0; i < n; ++i) {
string currentDept = students[i].dept;
int check = 0;
// Check if the current department already exists in dept array
for (int j = 0; j < n; ++j) {
if (dept[j][0] == currentDept) {
int count = stoi(dept[j][1]);
dept[j][1] = to_string(count + 1);
check = 1;
break;
}
}
if (check==0) {
for (int j = 0; j < n; ++j) {
if (dept[j][0]=="") {
dept[j][0] = currentDept;
dept[j][1] = "1";
break;
}
}
}
}
cout << "\nDepartment summary:\n";
cout << "Sno |";
cout <<setw(15)<< "Student Id | ";
cout<<setw(15) << "First Name |";
cout <<setw(15)<< "Father Name |";
cout <<setw(16)<<"G.Father Name |";
cout <<setw(5)<< "Sex |";
cout <<setw(5)<< "dept |";
cout <<setw(10)<< "Mid(40%)|";
cout <<setw(10)<< "final(60%)|";
cout <<setw(5)<< "Grade |"<<endl;
for (int j = 0; j < n; ++j) {
for (int i=0;i<n;i++){
if(dept[j][0]==students[i].dept){
cout <<"Department " <<dept[j][0] << " has: " << dept[j][1]<<"
students";
cout<<" view the details bellow \n";
cout<<"____________________________________________________________________________
_________________________________\n";
cout <<setw(3)<<students[i].Sno<<"|" ;
cout <<setw(14)<< students[i].Student_Id <<"|";
cout <<setw(15)<< students[i].First_Name <<"|";
cout <<setw(15)<< students[i].Father_Name <<"|";
cout <<setw(14)<< students[i].G_Father_Name<<"|" ;
cout <<setw(5)<< students[i].Sex<<"|" ;
cout <<setw(5)<< students[i].dept<<"|" ;
cout <<setw(10)<< students[i].Mid <<"|";
cout <<setw(10)<< students[i].final<<"|";
int total=students[i].Mid + students[i].final;
string grade;
if(total>=90){
grade="A+";
}
else if (total>=85){
grade="A";
}
else if (total>=80){
grade="A-";
}
else if (total>=75){
grade="B+";
}
else if (total>=70){
grade="B";
}
else if (total>=65){
grade="B-";
}
else if (total>=60){
grade="C+";
}
else if (total>=55){
grade="C";
}
else if (total>=50){
grade="C-";
}
else if (total>=45){
grade="D";
}
else {
grade="F";
}
students[i].Grade=grade;
cout <<setw(5) <<grade<< "|"<< endl;
}}
}}
int main() {
int n;
cout << "Enter the number of students: ";
cin >> n;
// Create an array of structures to store multiple student records
Student students[n];
M:
cout<<"*****************************************************";
cout<<"\n **** Enter your choose ****************\n";
cout<<"*****************************************************";
cout<<"\n *** 1: to register ***\n";
cout<<" *** ***";
cout<<"\n *** 2: to display all ***\n";
cout<<" *** ***";
cout<<"\n *** 3: to count & display by Department ***\n";
cout<<" *** ***";
cout<<"\n *** 4: to display grade of overall average ***\n";
cout<<" *** ***";
cout<<"\n *** 5: to display by department ***\n";
cout<<" *** ***";
cout<<"\n *** 6: to Exite ***\n";
cout<<"******************************************************\n\n";
//cout<<" *** ***";
int op;
cin>>op;
if(op==1){
addstud(n, students);
goto M;
}
else if(op==2){
display(n, students);
goto M;
}
else if(op==3) {
countdep(n, students);
goto M;
}
else if(op==4) {
overallgrade(n, students);
goto M;
}
else if(op==5) {
dispbydept(n, students);
goto M;
}
else if(op==6) {
Exit();
}else{
cout<<"you had enter invalid input: Please try again \n \n";
goto M;
}
return 0;
}