You're helping Professor Joy to calculate the grades for his course. The way his course is organised, students take two exams and their final grade is the weighted average of the two scores, where their lowest score weights 70% and their highest score 30%.

To accomplish this, you are going to need to do the following:

(1) Build the Student named tuple with the following attributes:

name (string)
exam1 (float)
exam2 (float)
(2) Write a function create_student, which will ask the user to input a single student's name, exam 1 score, and exam 2 score. The function will then create a named tuple with this information and return it.

(3) Write a function create_class, which takes as input an integer n, calls create_student n times and returns a list with the n students created.

(4) Write a function calculate_score, which takes a single Student named tuple as input, and returns the final score, where their lowest grade is weighted 70% and their highest grade is weighted 30%.

(5) Print the value returned by calculate_score for each student created in main. Round each score to two decimal places (using round(value, 2)).

Example 1: if the input is:

1
Student 1
10
0
then the output is:

3.0
Example 2: if the input is:

2
Student 1
10
0
Student 2
7
8
then the output is:

3.0
7.3
Example 3: if the input is:

0
then the output is:

Code:

from collections import namedtuple

''' Build named tuple here '''

''' Write Functions Here '''

if __name__ == "__main__":
''' Call functions and print here '''

Respuesta :

Answer:

C++.

Explanation:

#include <iostream>

#include <string>

using namespace std;

///////////////////////////////////////////////////////////////////

struct Student {

   string name;

   float exam1;

   float exam2;

};

///////////////////////////////////////////////////////////////////

Student create_student() {

   string name;

   cout<<"Name: ";

   cin>>name;

   float exam1;

   cout<<"Exam 1: ";

   cin>>exam1;

   

   float exam2;

   cout<<"Exam 2: ";

   cin>>exam2;

   

   Student s;

   s.name = name;

   s.exam1 = exam1;

   s.exam2 = exam2;

   return s;

}

///////////////////////////////////////////

Student* create_class(int n) {

   Student* arr = new Student[n];

   

   for (int i=0; i<n; i++) {

       cout<<"Student "<<i+1<<endl;

       arr[i] = create_student();

       cout<<endl;

   }

   

   return arr;

}

///////////////////////////////////////////

float calculate_score(Student s) {

   int final_score = 0;

   

   if (s.exam1 >= s.exam2) {

       final_score = (s.exam1 * 0.3) + (s.exam2 * 0.7);

   }

   else {

       final_score = (s.exam1 * 0.7) + (s.exam2 * 0.3);

   }

   

   return final_score;

}

///////////////////////////////////////////////////////////////////

int main() {

   Student* s;

   int n;

   ////////////////////////////////////

   cout<<"How many students? ";

   cin>>n;

   cout<<endl;

   s = create_class(n);

   ////////////////////////////////////

   for(int i=0; i<n; i++) {

       float final_score = calculate_score(s[i]);

       printf("Final score for Student %d %.2f", i+1, final_score);

       cout<<endl;

   }

   ////////////////////////////////////

   return 0;

}