Answer to Question #293713 in C++ for Mohammed

Question #293713

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.




1
Expert's answer
2022-02-03T11:35:38-0500
#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;


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog