Answer to Question #293677 in C++ for mohammed

Question #293677

write c++ programming input each student name each student father name each student id no each subject credit hour each subject grade then calculate gpa output student name


1
Expert's answer
2022-02-03T11:35:53-0500
#include <iostream>
#include <string>


using namespace std;


struct Student{
	string name;
	string fatherName;
	int id;
	int creditHour;
	char grade;
	int gpa;
};


int main(){
	int numberStudents;
	Student students[1000];


	cout<<"Enter the number of students: ";
	cin>>numberStudents;
	cin.ignore();
	//student name each student father name each student id 
	//no each subject credit hour each subject grade 
	//calculate gpa output student name
	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;
		cout<<"Enter the subject credit hour: ";
		cin>>students[i].creditHour;
		cout<<"Enter the subject grade: ";
		cin>>students[i].grade;


		//A 4 grade points
		//B 3 grade points
		//C 2 grade points
		//D 1 grade point
		//F 0 grade points
		int points=0;
		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=points;
		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";
		cout<<"The subject credit hour: "<<students[i].creditHour<<"\n";
		cout<<"The subject grade:"<< students[i].grade<<"\n";
		cout<<"gpa:"<< students[i].gpa<<"\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