0% found this document useful (0 votes)
4 views

c++ lab

The document contains a C++ program that collects and displays information about students, including their ID, names, department, and grades based on midterm and final exam scores. It calculates individual and average grades, and allows the user to count the number of students in a specified department. The program utilizes a structure to store student data and employs loops for data input and output formatting.

Uploaded by

ytbare.nurlign
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

c++ lab

The document contains a C++ program that collects and displays information about students, including their ID, names, department, and grades based on midterm and final exam scores. It calculates individual and average grades, and allows the user to count the number of students in a specified department. The program utilizes a structure to store student data and employs loops for data input and output formatting.

Uploaded by

ytbare.nurlign
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#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;
};

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];
// 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;
}

// 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;

}
// 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<<" average grade of all students :"<<grade<<endl;
//count number of students per department
M:
int counter=0;
string check;
cout<<"enter the department you want to count number of student";
cin>>check;
for (int i=0;i<n;i++){
if(check==students[i].dept){
counter++;
}
}
cout<<"\nTotal student for "<<check<<" is : "<<counter<<endl;
cout<<"Do you want to check other department ? Y/N";
string des;
cin>>des;
if(des=="Y"||des=="y"){
goto M;
}
else if(des=="N"||des=="n"){
cout<<"10Q";
}
return 0;
}

You might also like