Question

In: Computer Science

Need someone to fix my code: based on this version, give me another version without adding...

Need someone to fix my code: based on this version, give me another version without adding struct student.

#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;
}

Programming language: C++
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;
   }
  
}

Programming language: C++

Requirement: based on this version, give me another version without adding struct student.

Solutions

Expert Solution

code:

#include <iostream>
#include <iomanip>
using namespace std;

void getStudentData(string &name, double &firstQuizz, double &secondQuizz, double &midTermMarks, double &finalTerm);
void calcPercentage(double firstQuizz, double secondQuizz, double midTermMarks, double finalTerm, double &overallScore);
void getGradeLetter(double overallScore, char &gradeLetter);
void display(string name[], double overallScore[], char gradeLetter[], int n);

int main()
{

    int n;
    cout << "enter the number of students" << endl;
    cin >> n;

    double firstQuizz[n];
    double secondQuizz[n];
    double midTermMarks[n];
    double finalTerm[n];
    double overallScore[n];
    char gradeLetter[n];
    string name[n];

    int i;
    for (i = 0; i < n; i++)
    {
        cout << ":: Student#" << (i + 1) << " ::" << endl;
        getStudentData(name[i], firstQuizz[i], secondQuizz[i], midTermMarks[i], finalTerm[i]);
    }

    for (i = 0; i < n; i++)
    {
        calcPercentage(firstQuizz[i], secondQuizz[i], midTermMarks[i], finalTerm[i], overallScore[i]);
        getGradeLetter(overallScore[i], gradeLetter[i]);
    }

    display(name, overallScore, gradeLetter, n);

    return 0;
}

void getStudentData(string &name, double &firstQuizz, double &secondQuizz, double &midTermMarks, double &finalTerm)
{
    cin.ignore();
    cout << "Student name?";
    getline(cin, name);
    cout << "Enter marks in first quizz :";
    cin >> firstQuizz;
    cout << "Enter marks in second quizz :";
    cin >> secondQuizz;
    cout << "Enter marks in mid term :";
    cin >> midTermMarks;
    cout << "Enter marks in final term :";
    cin >> finalTerm;
}

void calcPercentage(double firstQuizz, double secondQuizz, double midTermMarks, double finalTerm, double &overallScore)
{
    overallScore = (firstQuizz + secondQuizz) * 0.25 + midTermMarks * 0.25 + finalTerm * 0.50;
}
void getGradeLetter(double overallScore, char &gradeLetter)
{
    double average = overallScore;

    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';
}
void display(string name[], double overallScore[], char gradeLetter[], 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 << name[i] << setw(15) << right << overallScore[i] << setw(15) << right << gradeLetter[i] << endl;
    }
}

Code ScreenShot:

output:

//for any query regarding the answer please ask in comment.


Related Solutions

Can someone tell me how to fix warning msg in my code of C ++? I...
Can someone tell me how to fix warning msg in my code of C ++? I got run-time error for this question please help me asap! Errors are: In function 'void bfs(int, int)': warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int j = 0; j < adj[pppp].size(); j++){ ^ In function 'int main()': warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d %d %d %d", &a, &q, &c, &N, &m); ^...
Python programming: can someone please fix my code to get it to work correctly? The program...
Python programming: can someone please fix my code to get it to work correctly? The program should print "car already started" if you try to start the car twice. And, should print "Car is already stopped" if you try to stop the car twice. Please add comments to explain why my code isn't working. Thanks! # Program goals: # To simulate a car game. Focus is to build the engine for this game. # When we run the program, it...
I need to fix this code, and could you please tell me what was the problem...
I need to fix this code, and could you please tell me what was the problem options 1 and 9 don't work #include <stdio.h> #include <time.h> #include <stdlib.h> // generate a random integer between lower and upper values int GenerateRandomInt(int lower, int upper){     int num =(rand()% (upper - lower+1))+lower;     return num; } // use random numbers to set the values of the matrix void InitializeMatrix(int row, int column, int dimension, int mat[][dimension]){     for(int i =0; i<row; i++){...
Need to fix this code for tc -tac-toe game .. see the code below and fix...
Need to fix this code for tc -tac-toe game .. see the code below and fix it #include <iostream> using namespace std; void display_board(); void player_turn(); bool gameover (); char turn ; bool draw = false; char board [3][3] = { {'1', '2', '3'}, { '4', '5', '6'}, { '7', '8', '9'}}; int main() { cout << " Lets play Tc- Tac- toe game " <<endl ; cout << " Player 1 [X] ----- player 2 [0] " <<endl <<endl;...
I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------...
I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------ class Robot{ int serialNumber; boolean flies,autonomous,teleoperated; public void setCapabilities(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated){ this.serialNumber = serialNumber; this.flies = flies; this.autonomous = autonomous; this.teleoperated = teleoperated; } public int getSerialNumber(){ return this.serialNumber; } public boolean canFly(){ return this.flies; } public boolean isAutonomous(){ return this.autonomous; } public boolean isTeleoperated(){ return this.teleoperated; } public String getCapabilities(){ StringBuilder str = new StringBuilder(); if(this.flies){str.append("canFly");str.append(" ");} if(this.autonomous){str.append("autonomous");str.append("...
can someone finish and check my code on main. cpp? Its not working for me even...
can someone finish and check my code on main. cpp? Its not working for me even though im sure my code make sense is it possible to output each function to show they work. this is supposed to be a vector class library made from allocated memory i have included templated functions in the class file to help create the rest of the functions. Thank you so much note: i did not include main.cpp because it  was empty- im hoping someone...
hi i need a code that will give me this output, For the multiply_list, the user...
hi i need a code that will give me this output, For the multiply_list, the user will be asked to input the length of the list, then to input each element of the list. For the repeat_tuple, the user is only asked to enter the repetition factor, but not the tuple. Your program should take the list created before and convert it to a tuple. output expected: (**user input**) ******Create your List ****** Enter length of your list: 3 ******...
please, can someone give me a rationale, onjectives, programs and budget for my project proposal. It...
please, can someone give me a rationale, onjectives, programs and budget for my project proposal. It is a scholarship program for medical students who pass the online examination. Please answer it as soon as possible.
I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
fix this code in python and show me the output. do not change the code import...
fix this code in python and show me the output. do not change the code import random #variables and constants MAX_ROLLS = 5 MAX_DICE_VAL = 6 #declare a list of roll types ROLLS_TYPES = [ "Junk" , "Pair" , "3 of a kind" , "5 of a kind" ] #set this to the value MAX_ROLLS pdice = [0,0,0,0,0] cdice = [0,0,0,0,0] #set this to the value MAX_DICE_VAL pdice = [0,0,0,0,0,0] cdice = [0,0,0,0,0,0] #INPUT - get the dice rolls i...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT