Question

Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double...

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++

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in airplane const int COLS = 4; void menu(); //displays options void displaySeats(char[][COLS]); void reserveSeat(char [ROWS][COLS]); int main() { int number=0; //holder variable char seatChar[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { seatChar[i][j] = '-'; } } int choice; //input from menu bool repeat = true; //needed for switch loop while (repeat...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std;...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std; int main() {        int x;        cout << "Selection option " << endl;        cin >> x;        if (x == 1)               cout << "You select option 1" << endl;        else if (x >= 2 || x <= 4)               cout << "You select options 2 or 3 or 4" << endl;               else if (x == 10)               cout << "You select option 10" << endl;               else...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Your code here ----------------- } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to...
Analyze the following program and write down the output. # include <iostream> using namespace std;    void...
Analyze the following program and write down the output. # include <iostream> using namespace std;    void modifyArray( int [ ], int );    void modifyElement ( int );      int main( ) {   const int arraySize = 8;   int a[arraySize] = { 2, -2, 10, -3, -1 ,0, 10, -5 };      modifyArray ( a, arraySize);      for ( int i =0; i < arraySize; i++)               cout << a[i] << ‘  ’;         modifyElement ( a[4] );          for ( int i =0; i <...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Code here } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to manipulate the elements...
Consider the following program: #include #include #include using namespace std; int main() { int num1; int...
Consider the following program: #include #include #include using namespace std; int main() { int num1; int num2; cout << fixed << showpoint << setprecision(2); cout << "Enter two integers: "; cin >> num1 >> num2; cout << endl; if (num1 != 0 && num2 != 0) cout << sqrt(abs(num1 + num2) + 0.5) << endl; else if (num1 != 0) cout << floor(num1 + 0.5) << endl; else if (num2 != 0) cout << ceil(num2 + 0.5) << endl; else...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std;...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std; int fib(int n) { int temp; if (n <= 0)    return 0; else if (n <= 2)    return 1; else {    temp = fib(n – 1);    return temp + fib(n-2); } } int main() {    int num;    cout << "Which fibonacci number? ";    cin >> num;    cout << fib(num) << endl;    return 0; } You...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
Language : C ++ #include #include #include #include #include using namespace std; void DisplayMenu() {   ...
Language : C ++ #include #include #include #include #include using namespace std; void DisplayMenu() {    cout << "1. E games\n";    cout << "2. T games\n";    cout << "3. M games\n";    cout << "4. Total Games\n";    cout << "5. Exit\n"; } double total(double egames, double tgames, double mgames) {    int totalgames = egames + tgames + mgames;    cout << "There are " << totalgames << " games\n";    return totalgames; } double Egames(double egames,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT