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...
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...
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...
//evil_server.cpp #include <string> #include <cstdlib> #include <iostream> #include "evil_server.h" using namespace std; EvilServer :: EvilServer() {...
//evil_server.cpp #include <string> #include <cstdlib> #include <iostream> #include "evil_server.h" using namespace std; EvilServer :: EvilServer() {    hacked[0] = hacked[1] = hacked[2] = false;    passwords[agent_index(MrMean)] = random_pw(MrMean);    passwords[agent_index(MsChief)] = random_pw(MsChief);    passwords[agent_index(DrEvil)] = random_pw(DrEvil); } void EvilServer :: change_pw(EvilAgent agent, string new_pw) {    int index = agent_index(agent);    if (new_pw == passwords[index])        return;    hacked[index] = false;    passwords[index] = new_pw; } string EvilServer :: random_pw(EvilAgent agent) {    string password;    int length;   ...
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 theArray[] = { 5, 11, -29, 45, 9, -1}; void sumPos(int ary[], int len, int &sum) {    sum = 0;    for (int i = 0; i < len; i++)            if (ary[i] > 0)                sum = sum + ary[i]; } int main() {    int total;    sumPos(theArray, 6, total);    for (int k=0; k < 6; k++)      cout...
No matter what I do I cannot get this code to compile. I am using Visual...
No matter what I do I cannot get this code to compile. I am using Visual Studio 2015. Please help me because I must be doing something wrong. Here is the code just get it to compile please. Please provide a screenshot of the compiled code because I keep getting responses with just code and it still has errors when I copy it into VS 2015: #include <iostream> #include <conio.h> #include <stdio.h> #include <vector> using namespace std; class addressbook {...
my code has several functions; delete and backward functions are not working, rewrite the code for...
my code has several functions; delete and backward functions are not working, rewrite the code for both functions and check them in the main: #include<iostream> #include<cassert> using namespace std; struct nodeType {    int info;    nodeType *link; }; class linkedList { public:    void initializeList();    bool isEmptyList();    void print();    int length();    void destroyList();    void insertFirst(int newItem);    void insertLast(int newItem);    int front();    linkedList();    void copyList(const linkedList otherList);    void insertNewValue(int value);...
I have an error but i can't correct it #include <iostream> using namespace       std; long reverse...
I have an error but i can't correct it #include <iostream> using namespace       std; long reverse (long       num, long   equation,long reverse = 0); int       main() {               long       num, reverse = 0;        cout << "Enter       the       num:       ";        cin >> num;        cout << "Reverse       num       is       =       "               << reverse << endl;        return       0; } long reverse(long       num, long equation, long reverse = 0) {        while (num)        {               equation...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are pointers or constant pointers. Directions: Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS = 3; // may only be declared within the main function string students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Be sure to compile using g++ -std=c++11 helpWithGradesPtr.cpp Write a C++ program to run a menu-driven program with the...