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...
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...
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...
Use C++ write a "Design and implement a class of infix calculators" ,simply write a function...
Use C++ write a "Design and implement a class of infix calculators" ,simply write a function named "evaluateInfix()" that evaluates infix expressions. It should have one string parameter and should return an int result. It should call a separate function named "infixToPostfix()" to convert the infix expression into a postfix expression, and then it should do the work of evaluating the resulting postfix expression. Then write a main() function to thoroughly test the function. Use the pseudocode algorithm that evaluates...
A tree can be considered as a structured graph. Write a C++ function that receives a...
A tree can be considered as a structured graph. Write a C++ function that receives a BST object and returns its corresponding graph representation, implemented via an adjacency list. What will be the impact on the search complexity?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT