Question

In: Computer Science

use c++ /* The following function receives the class marks for all student in a course...

use c++

/*
The following function receives the class marks for all student in a course and compute standard deviation. Standard deviation is the average of the sum of square of difference of a mark and the average of the marks. For example for marks={25, 16, 22}, then average=(25+16+22)/3=21. Then standard deviation = ((25-21)^2 + (16-21)^2+(22-21)^2)/3.
Implement the function bellow as described above. Then write a test console app to use the function for computing the standard deviation of a list of marks that user inputs as floats in the range of 0.f to 100.f. User signals end of the list by entering -1 as final mark. Make sure to verify user input marks are valid and in the range, before processing them.

*/

float ComputeMarksStandardDeviation(std::array<float> marks)
{
}

Solutions

Expert Solution

C++ PROGRAM:

#include<iostream>

#include<vector>

#include<math.h>

using namespace std;

/**The following function receives the class marks

* for all student in a course and compute standard deviation.

* function for computing the standard deviation of a list of

* marks that user inputs as floats in the range of 0.f to 100.f.*/

float ComputeMarksStandardDeviation(std::vector<float> marks){

    float sum = 0;

    float MarksStandardDeviation;

    // find the size of the vector

    int n = marks.size();

    // calculate the sum of all marks

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

        sum+=marks[i];

    }

    /**For example for marks={25, 16, 22}, then average=(25+16+22)/3=21. Then

     * standard deviation = ((25-21)^2 + (16-21)^2+(22-21)^2)/3.

     * calculate the average of marks*/

    float average = sum/n;

    // calculate the standard deviation

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

        MarksStandardDeviation += pow(marks[i] - average, 2);

    }

    // return the standard deviation

    return MarksStandardDeviation/n;

}

// main() function

int main()

{   

    float num;

    vector<float> marks;

    while(true){

        cout<<"Enter marks: ";

        cin>>num;

        // User signals end of the list by entering -1 as final mark.

        if(num==-1) break;

        // Make sure to verify user input marks are valid and in the range,

        // between 0-100f

        while(num<0 || num>100){

            cout<<"Out of range"<<endl;

            cout<<"Enter marks between 0-100: ";

            cin>>num;

        }

       // push_back into the vector marks

        marks.push_back(num);

    }

   // calling and print the standard Deviation

    // Standard deviation is the average of the sum

    // of square of difference of a mark and the average of the marks

    cout<<"Standard Deviation: "<<ComputeMarksStandardDeviation(marks);

    return 0;

}

OUTPUT:

NOTE: If you don't understand any step please let me know at once.


Related Solutions

/* The following function receives the class marks for all student in a course and compute...
/* The following function receives the class marks for all student in a course and compute standard deviation. Standard deviation is the average of the sum of square of difference of a mark and the average of the marks. For example for marks={25, 16, 22}, then average=(25+16+22)/3=21. Then standard deviation = ((25-21)^2 + (16-21)^2+(22-21)^2)/3. Implement the function bellow as described above. Then write a test console app to use the function for computing the standard deviation of a list of...
Language C++ Student-Report Card Generator: create a class called student and class called course. student class...
Language C++ Student-Report Card Generator: create a class called student and class called course. student class this class should contain the following private data types: - name (string) - id number (string) - email (s) - phone number (string) - number of courses (int) - a dynamic array of course objects. the user will specify how many courses are there in the array. the following are public members of the student class: - default constructor (in this constructor, prompt the...
***Given a class called Student and a class called Course that contains an ArrayList of Student....
***Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called dropStudent() as described below. Refer to Student.java below to learn what methods are available.*** Course.java import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{ /** collection of Students */ private ArrayList<Student> roster; /***************************************************** Constructor for objects of class Course *****************************************************/ public Course(){ roster = new ArrayList<Student>(); } /***************************************************** Remove student with the...
C++ Write the implementation of the function concatenateIntArrays. This function receives 4 parameters in the following...
C++ Write the implementation of the function concatenateIntArrays. This function receives 4 parameters in the following order: An array of integer values (array1). An integer representing the size of array1 (size1). An array of integer values (array2). An integer representing the size of array2 (size). The function creates a dynamic array of integers of size size1+size2 to store all the values in array1, followed by all the values in array2. The function returns the pointer used to create the dynamic...
2. Create two class, a student class, and a course class, take advantage of the codes...
2. Create two class, a student class, and a course class, take advantage of the codes provided in the class slides and sample codes. python Student Course __Username:str __Courses:list __courseName:str __students: list addCourse():None dropCourse():None getCourse():list addStudent:None dropStudent:None getStudents():list getNumber of students:int 3. Create a student object for every student in the UD.txt (you can use a loop for this) 4. Create 6 course objects: 1. CS131 2. CS132 3. EE210 4. EE310 5. Math320 6. Math220 5. After the student...
In order to access this course, attend this class as an on-line student, and participate in...
In order to access this course, attend this class as an on-line student, and participate in class discussions, you need to use a specific course management system. Answer the following questions about this system. 1. What is the name of the course management system? 2. Who created this system? 3. Other than your instructor, name three ways to get technical help with this product. 4. Other than class discussions, talk about one function of this product. Define its purpose and...
Define and implement class Course. This class should contain the following fields: course name, course description,...
Define and implement class Course. This class should contain the following fields: course name, course description, department, time the course starts, weekday the course is held on (for simplicity, let us assume the course only meets once a week). This class should contain getters and setters for all its attributes. This class also needs at least one constructor. Save this class and its definition into a file named Course.java. Define and implement class Student. This class should contain the following...
Write a C++ function that receives an integer array along with its specified length. The function...
Write a C++ function that receives an integer array along with its specified length. The function will replace only one of the smallest integers and one of the largest integers by 0. Then the function will return the average for the rest of the values in the array. Test case array: 3, 8, 2, 6, 5, 3, 4, 7, 8, 2, 10, 7 Function should return: 5.3
Use the class definition below to answer the following questions. [Total 8 Marks] public class TrafficLight...
Use the class definition below to answer the following questions. [Total 8 Marks] public class TrafficLight { String stopLight = "red"; String waitLight; String goLight; public void setStopLight(String colour) { stopLight = colour; } public String getGreenLight() { return goLight; } } Question 21 Not yet answered Marked out of 1.00 Flag question Question text D3a - [1 Mark] How many field attributes are there in the TrafficLight class? Answer: Question 22 Not yet answered Marked out of 1.00 Flag...
Use the class definition below to answer the following questions. [Total 8 Marks] public class TrafficLight...
Use the class definition below to answer the following questions. [Total 8 Marks] public class TrafficLight { String stopLight = "red"; String waitLight; String goLight; public void setStopLight(String colour) { stopLight = colour; } public String getGreenLight() { return goLight; } } 1 :How many field attributes are there in the TrafficLight class? 2 :Name a field attribute for this class. 3 :What is the name of the method that is an accessor? 4 :What is the name of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT