Need someone to fix my code:
#include<iostream>
using namespace std;
struct student
{
double firstQuizz;
double secondQuizz;
double midTerm;
double finalTerm;
string name;
};
int main()
{
int n;
cout<<"enter the number of students"<<endl;
cin>>n;
struct student students[n];
int i; struct student istudent;
for(i=0;i<n;i++)
{
cout<<"Student name?";
cin >> istudent.name;
cout<<"enter marks in first quizz , second quizz , mid
term , final term of student "<<i+1<<endl;
cin>>students[i].firstQuizz>>students[i].secondQuizz>>students[i].midTerm>>students[i].finalTerm;
}
for(i=0;i<n;i++)
{
double marks=0;
double
score=students[i].firstQuizz+students[i].secondQuizz+students[i].midTerm+students[i].finalTerm;
marks=(students[i].firstQuizz*0.25)+(students[i].secondQuizz*0.25)+(students[i].midTerm*0.25)+(students[i].finalTerm*0.50);
double totalArrgegateMarks = 10*0.25 + 10 * 0.25 +100 *0.25
+100*0.50;
double percentage = (marks*100)/totalArrgegateMarks;
if(percentage>=90)
cout<<istudent.name<<i<<" score = "<<score<<" numeric average = "<<percentage<<" grade = A"<<endl;
else if(percentage>=80)
cout<<istudent.name<<i<<" score = "<<score<<" numeric average = "<<percentage<<" grade = B"<<endl;
else if(percentage>=70)
cout<<istudent.name<<i<<" score = "<<score<<" numeric average = "<<percentage<<" grade = C"<<endl;
else if(percentage>=60)
cout<<istudent.name<<i<<" score =
"<<score<<" numeric average =
"<<percentage<<" grade = D"<<endl;
else
cout<<istudent.name<<i<<" score = "<<score<<" numeric average = "<<percentage<<" grade = F"<<endl;
}
return 0;
}
requirement
1. The string function (student name) wasn't being added correctly and the main function didn't recognize multiple student's name.
2. Break down more void functions of getting data, printing data and total calculation for the scope of main functions.
3. Use call by reference for void functions.
4. Provide detailed code illustration.
Programming language: C++
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
=================================
#include <iostream>
#include <iomanip>
using namespace std;
struct student
{
double firstQuizz;
double secondQuizz;
double midTerm;
double finalTerm;
double overallScore;
char gradeLetter;
string name;
};
void getStudentData(student &s);
void calcPercentage(student &s);
void gradeLetter(student &s);
void display(student s[],int n);
int main()
{
int n;
cout<<"enter the number of students"<<endl;
cin>>n;
struct student students[n];
int i; struct student istudent;
for(i=0;i<n;i++)
{
cout<<":: Student#"<<(i+1)<<"
::"<<endl;
getStudentData(students[i]);
}
for(i=0;i<n;i++)
{
calcPercentage(students[i]);
gradeLetter(students[i]);
}
display(students,n);
return 0;
}
void getStudentData(student &s)
{
cin.ignore();
cout<<"Student name?";
getline(cin,s.name);
cout<<"Enter marks in first quizz :";
cin>>s.firstQuizz;
cout<<"Enter marks in second quizz :";
cin>>s.secondQuizz;
cout<<"Enter marks in mid term :";
cin>>s.midTerm;
cout<<"Enter marks in final term :";
cin>>s.finalTerm;
}
void calcPercentage(student &s)
{
double overAllScore = (s.firstQuizz + s.secondQuizz)*5 * 0.25 +
s.midTerm * 0.25 + s.finalTerm* 0.50;
s.overallScore=overAllScore;
}
void gradeLetter(student &s)
{
double average=s.overallScore;
char gradeLetter;
if (average >= 90 && average<=100)
gradeLetter = 'A';
else if (average >= 80 && average < 90)
gradeLetter = 'B';
else if (average >= 70 && average < 80)
gradeLetter = 'C';
else if (average >= 60 && average < 70)
gradeLetter = 'D';
else if (average < 60)
gradeLetter = 'F';
s.gradeLetter=gradeLetter;
}
void display(student s[],int n)
{
//setting the precision to two
decimal places
std::cout << std::setprecision(2) <<
std::fixed;
cout<<setw(15)<<left<<"Name"<<setw(15)<<right<<"Overall
Score"<<setw(15)<<right<<"Grade
Letter"<<endl;
cout<<setw(15)<<left<<"----"<<setw(15)<<right<<"-------------"<<setw(15)<<right<<"------------"<<endl;
for(int i=0;i<n;i++)
{
cout<<setw(15)<<left<<s[i].name<<setw(15)<<right<<s[i].overallScore<<setw(15)<<right<<s[i].gradeLetter<<endl;
}
}
=======================================
output:
=====================Could you plz rate me well.Thank
You
Get Answers For Free
Most questions answered within 1 hours.