Question

In: Computer Science

Professor realizes that he hates his class and has decided to give each of his students...

Professor realizes that he hates his class and has decided to give each of his students a 20-point decrease in all their grades for no reason. Help him write the C++ code that will allow him to do this.

Consider the code on the next page. It creates an array of 10 structs called students which contains their name and their grade. It is nearly complete. Your task is the following:

  1. Complete the user-defined function called subtractTwenty.
    1. You will need to create a for-loop that iterates through the 10 students and subtract 20 from their grade.
    2. A student cannot have a grade lower than 0. If their grade falls below 0, you must set it equal to 0

      #include <iostream>

      using namespace std;

      //struct that creates student

      struct student

      {

           string name;

           int grade;

      };

      //user-defined function prototypes

      void subtractTwenty(student[10]);

      void printArray(student[10]);

      int main()

      {

           //array of 10 students

           student arrayOfStudents[10];

           //populate the 10 students

           arrayOfStudents[0] = { "Alice", 78 };

           arrayOfStudents[1] = { "Bobby", 90 };

           arrayOfStudents[2] = { "Casey", 44 };

           arrayOfStudents[3] = { "Devon", 57 };

           arrayOfStudents[4] = { "Ethan", 12 };

           arrayOfStudents[5] = { "Frank", 99 };

           arrayOfStudents[6] = { "Grace", 70 };

           arrayOfStudents[7] = { "Heidi", 80 };

           arrayOfStudents[8] = { "Isaac", 14 };

           arrayOfStudents[9] = { "Jason", 40 };

           cout << endl << "Before subtracting 20: " << endl << endl;

           printArray(arrayOfStudents);

           subtractTwenty(arrayOfStudents);

           cout << endl << "After subtracting 20: " << endl << endl;

           printArray(arrayOfStudents);

           cout << endl << endl;

           return 0;

      }

      void subtractTwenty(student a[10])

      {

      }

      void printArray(student a[10])

      {

           for (int i = 0; i < 10; i++)

           {

                 cout << "Name: " << a[i].name << ", Grade: " << a[i].grade << endl;

           }

      }

Solutions

Expert Solution

Updated code is as follows:

#include <iostream>
using namespace std;

//struct that creates student
struct student
{
    string name;
    int grade;
};

//user-defined function prototypes
void subtractTwenty(student[10]);
void printArray(student[10]);

int main()
{
    //array of 10 students
    student arrayOfStudents[10];

    //populate the 10 students
    arrayOfStudents[0] = { "Alice", 78 };
    arrayOfStudents[1] = { "Bobby", 90 };
    arrayOfStudents[2] = { "Casey", 44 };
    arrayOfStudents[3] = { "Devon", 57 };
    arrayOfStudents[4] = { "Ethan", 12 };
    arrayOfStudents[5] = { "Frank", 99 };
    arrayOfStudents[6] = { "Grace", 70 };
    arrayOfStudents[7] = { "Heidi", 80 };
    arrayOfStudents[8] = { "Isaac", 14 };
    arrayOfStudents[9] = { "Jason", 40 };
  
    cout << endl << "Before subtracting 20: " << endl << endl;
    printArray(arrayOfStudents);
    subtractTwenty(arrayOfStudents);
    cout << endl << "After subtracting 20: " << endl << endl;
    printArray(arrayOfStudents);
    cout << endl << endl;
    return 0;
}

void subtractTwenty(student a[10])
{
    for (int i = 0; i < 10; i++)
    {
        a[i].grade-=20;
        if(a[i].grade<0)
        {
            a[i].grade=0;
        }
    }
}

void printArray(student a[10])
{
    for (int i = 0; i < 10; i++)
    {
        cout << "Name: " << a[i].name << ", Grade: " << a[i].grade << endl;
    }
}
Sample output:

Mention in comments if any mistakes or errors are found. Thank you.


Related Solutions

Professor Bailey wanted to assess his students’ understanding of statistics. He decided to test both their...
Professor Bailey wanted to assess his students’ understanding of statistics. He decided to test both their problem- solving ability, and their conceptual understanding of basic statistics principles governing the topics they had covered so far. He gave his class 2 tests. Test 1 involved problem-solving using statistics formulas and test 2 was conceptual (i.e. it involved students interpreting statistical concepts). The mean on both tests was 70%. However, the standard deviation for the problem-solving test was 5, and the standard...
An MPH professor claims that 50 % of the students in his class has a median...
An MPH professor claims that 50 % of the students in his class has a median weight different from 140 lb. He collects the weight of a random sample of 22 students. Enter the following data in SPSS and perform a binomial test using the standard method. Alpha level = 0.05 (Make sure to save your data before start analyzing the data). 135 119 106 135 180 108 128 160 143 175 170 205 195 185 182 150 175 190...
A statistics professor has stated that 90% of his students pass the class. To check this...
A statistics professor has stated that 90% of his students pass the class. To check this claim, a random sample of 150 students indicated that 129 passed the class. If the professor's claim is correct, what is the probability that 129 or fewer will pass the class this semester? A) 0.0516 B) 0.9484 C) 0.5516 D) 0.4484 please show work
A Discrete Mathematics professor has a class of students. Frustrated with their lack of discipline, he...
A Discrete Mathematics professor has a class of students. Frustrated with their lack of discipline, he decides to cancel class if fewer than some number of students are present when class starts. Arrival times go from on time (arrivalTime < 0) to arrival late (arrivalTime > 0).Given the arrival time of each student and a threshhold number of attendees, determine if the class is canceled. Input Format The first line of input contains t, the number of test cases. Each...
A professor has a class with four recitation sections. Each section has 16 students (rare, but...
A professor has a class with four recitation sections. Each section has 16 students (rare, but there are exactly the same number in each class...how convenient for our purposes, yes?). At first glance, the professor has no reason to assume that these exam scores from the first test would not be independent and normally distributed with equal variance. However, the question is whether or not the section choice (different TAs and different days of the week) has any relationship with...
In a large class of introductory Statistics​ students, the professor has each person toss a coin...
In a large class of introductory Statistics​ students, the professor has each person toss a coin 29 times and calculate the proportion of his or her tosses that were heads. Complete parts a through d below. The Independence Assumption (is or is not) )_____satisfied because the sample proportions (are or are not)_____independent of each other since one sample proportion (can affect or does not affect)______another sample proportion. The​Success/Failure Condition is not satisfied because np=____ and nq=____which are both (less than...
Elliot is enjoying watching his son grow up. He realizes that his son currently has no...
Elliot is enjoying watching his son grow up. He realizes that his son currently has no conception of sex or gender--his own or anyone else's. But as soon as his mind has matured to the point he can recognize constant patterns of male-ness and female-ness, he will develop his gender identity. Which theory in your text best applies to this example of stages? Group of answer choices: social learning theory cognitive development theory gender-role transcendence theory psychosexual theory
4. A teacher believes that whatever he says in class has no effect on his students....
4. A teacher believes that whatever he says in class has no effect on his students. Just as he's about to quit his profession, a statistician enters the room and suggests that the teacher design a study to test his assumption. The study will look at whether providing in-class feedback on homework assignments enhances classroom performance. The teacher wants to know whether providing feedback before or after returning the assignments is most useful. He's also interested in the most effective...
COIN TOSSES In a large class of introductory Statistics students, the professor has each student toss...
COIN TOSSES In a large class of introductory Statistics students, the professor has each student toss a coin 16 times and calculate the proportion of his or her tosses that were heads. The students then report their results, and the professor plots a histogram of these several proportions. What shape would you expect this histogram to be? Why? Where do you expect the histogram to be centred? How much variability would you expect among these proportions? Explain why a Normal...
A statistics professor gave a 5-point quiz to the 50 students in his class. Scores on...
A statistics professor gave a 5-point quiz to the 50 students in his class. Scores on the quiz could range from 0 to 5: The following frequency table resulted: (1.5 points) Quiz Score f rf cf crf c% 5 4 .08 50 1.00 100% 4 10 .20 46 .96 96% 3 14 .28 36 .72 72% 2 10 .20 22 .44 44% 1 8 .16 12 .24 24% 0 4 .08 4 .08 8% 1. Compute the values that define...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT