About assignment of c++
In put
Each Student name
Each Student father name
Each Student id number
Number of students
Number of subject
Each subject
Each subject credit hours
Each subject grade
Then calculate GPA
Out put
Student name
Student father name
Student Id number
GPA
If grade is F the student is fail.
The program must be display if you ask one student information.
#include <iostream>
#include <string>
using namespace std;
struct Student{
string name;
string fatherName;
int id;
int creditHour;
char grade;
float gpa;
};
int main(){
int numberStudents;
Student students[100];
cout<<"Enter the number of students: ";
cin>>numberStudents;
cin.ignore();
for(int i=0;i<numberStudents;i++){
cout<<"Enter the student name: ";
getline(cin,students[i].name);
cout<<"Enter the student father name: ";
getline(cin,students[i].fatherName);
cout<<"Enter the student id: ";
cin>>students[i].id;
int numberSubject;
cout<<"Enter Number of subjects: ";
cin>>numberSubject;
int points=0;
for(int j=0;j<numberSubject;j++){
cout<<"Enter the subject credit hour: ";
cin>>students[i].creditHour;
cout<<"Enter the subject grade: ";
cin>>students[i].grade;
if(students[i].grade=='A' || students[i].grade=='a'){
points+=4;
}
if(students[i].grade=='B' || students[i].grade=='b'){
points+=3;
}
if(students[i].grade=='C' || students[i].grade=='c'){
points+=2;
}
if(students[i].grade=='D' || students[i].grade=='d'){
points+=1;
}
}
students[i].gpa=(float)points/(float)numberSubject;
cin.ignore();
}
for(int i=0;i<numberStudents;i++){
cout<<"The student name: "<<students[i].name<<"\n";
cout<<"The student father name: "<<students[i].fatherName<<"\n";
cout<<"The student id: "<<students[i].id<<"\n";
if(students[i].gpa>0){
cout<<"GPA: "<< students[i].gpa<<"\n\n";
}else{
cout<<"The student is fail.\n\n";
}
}
cin>>numberStudents;
return 0;
}
Comments
Leave a comment