i want to display the grade report of two students in the table but this code will repeat the grade report of one student in the tables and what is wrong with this code below ?
please guy just help me !!
#include<iostre am>
#include<string >
#include<fstrea m>
using namespace std;
class student{
private:
string fname;
string lname;
char sex;
string id;
char grade[20];
int year;
int semester;
int nocourse;
string coursename[20];
int crhr[20];
int coursecrhr[20];
int totalcrhr = 0;
int point[20];
int totalpoint = 0;
double cgpa;
public:
void acceptdata(){
cout << "Enter year: " << endl;
cin >> year;
cout << "Enter semester: " << endl;
cin >> semester;
cout << "Number of course: " << endl;
cin >> nocourse;
for (int i = 1; i <= nocourse; i++)
{
cout << "Course Name: ";
cin >> coursename[i];
cout << "Credit hour: ";
cin >> crhr[i];
}
}
void studinfo(){
for (int i = 1; i <= nocourse; i++){
cout << "Student name: ";
cin >> fname;
cout << "Student id: ";
cin >> id;
cout << "Student sex: ";
cin >> sex;
}
G:
for (int i = 1; i <= nocourse; i++){
cout << "Grade for " << coursename[i] << ":";
cin >> grade[i];
if (grade[i] == 'A'){
point[i] = 4;
}
else if (grade[i] == 'B')
{
point[i] = 3;
}
else if (grade[i] == 'C'){
point[i] = 2;
}
else if (grade[i] == 'D')
{
point[i] = 1;
}
else if (grade[i] == 'F')
{
point[i] = 0;
}
else
{
cout << "Please enter correct grade in capital letter!" << endl;
goto G;
}
}
}
void gradecalc(){
for (int i = 1; i <= nocourse; i++){
totalcrhr += crhr[i];
totalpoint += crhr[i] * point[i];
}
cgpa = totalpoint / totalcrhr;
cout << "______________ _______________ _______________ _______________ _______________ ___" << endl;
cout << " Jigjiga University " << endl;
cout << " Name: " << fname;
cout << " Sex: " << sex;
cout << " ID: " << id;
cout << " year: " << year;
cout << " Semester: " << semester << endl;
cout << "-----------------------------------------------------------------------------" << endl;
cout << "Sno \t Course Name \t CrHr \t\t Grade \t\t Point" << endl;
cout << "-----------------------------------------------------------------------------" << endl;
for (int i = 1; i <= nocourse; i++){
cout << i << " \t" << coursename[i] << " \t" << crhr[i] << " \t\t" << grade[i] << " \t\t" << point[i] << endl;
}
cout << "______________ _______________ _______________ _______________ _______________ ___" << endl;
cout << "Total Point: " << totalpoint;
cout << "\t\t\t\t CGPA: " << cgpa << endl;
}
};
int main()
{
student s,s1;
s.acceptdata();
s.studinfo();
s.gradecalc();
s1.acceptdata() ;
s1.studinfo();
s1.gradecalc();
return 0;
}
please guy just help me !!
#include<iostre am>
#include<string >
#include<fstrea m>
using namespace std;
class student{
private:
string fname;
string lname;
char sex;
string id;
char grade[20];
int year;
int semester;
int nocourse;
string coursename[20];
int crhr[20];
int coursecrhr[20];
int totalcrhr = 0;
int point[20];
int totalpoint = 0;
double cgpa;
public:
void acceptdata(){
cout << "Enter year: " << endl;
cin >> year;
cout << "Enter semester: " << endl;
cin >> semester;
cout << "Number of course: " << endl;
cin >> nocourse;
for (int i = 1; i <= nocourse; i++)
{
cout << "Course Name: ";
cin >> coursename[i];
cout << "Credit hour: ";
cin >> crhr[i];
}
}
void studinfo(){
for (int i = 1; i <= nocourse; i++){
cout << "Student name: ";
cin >> fname;
cout << "Student id: ";
cin >> id;
cout << "Student sex: ";
cin >> sex;
}
G:
for (int i = 1; i <= nocourse; i++){
cout << "Grade for " << coursename[i] << ":";
cin >> grade[i];
if (grade[i] == 'A'){
point[i] = 4;
}
else if (grade[i] == 'B')
{
point[i] = 3;
}
else if (grade[i] == 'C'){
point[i] = 2;
}
else if (grade[i] == 'D')
{
point[i] = 1;
}
else if (grade[i] == 'F')
{
point[i] = 0;
}
else
{
cout << "Please enter correct grade in capital letter!" << endl;
goto G;
}
}
}
void gradecalc(){
for (int i = 1; i <= nocourse; i++){
totalcrhr += crhr[i];
totalpoint += crhr[i] * point[i];
}
cgpa = totalpoint / totalcrhr;
cout << "______________ _______________ _______________ _______________ _______________ ___" << endl;
cout << " Jigjiga University " << endl;
cout << " Name: " << fname;
cout << " Sex: " << sex;
cout << " ID: " << id;
cout << " year: " << year;
cout << " Semester: " << semester << endl;
cout << "-----------------------------------------------------------------------------" << endl;
cout << "Sno \t Course Name \t CrHr \t\t Grade \t\t Point" << endl;
cout << "-----------------------------------------------------------------------------" << endl;
for (int i = 1; i <= nocourse; i++){
cout << i << " \t" << coursename[i] << " \t" << crhr[i] << " \t\t" << grade[i] << " \t\t" << point[i] << endl;
}
cout << "______________ _______________ _______________ _______________ _______________ ___" << endl;
cout << "Total Point: " << totalpoint;
cout << "\t\t\t\t CGPA: " << cgpa << endl;
}
};
int main()
{
student s,s1;
s.acceptdata();
s.studinfo();
s.gradecalc();
s1.acceptdata() ;
s1.studinfo();
s1.gradecalc();
return 0;
}
Comment