Question

In: Computer Science

A. Arrays An array is basically of collection of related variables of the same type. For...

A. Arrays An array is basically of collection of related variables of the same type. For example, a collection of grades of students, a collection of salary of employees of a company, etc. When working with student grades, for example, we can then perform statistical computations on that set of data to obtain more meaningful information. In this part of the lab, you will write a complete C++ program named Lab6A.cpp that allows the user to enter the grades of 10 students in a class in an array called grades and you will calculate the standard deviation of those grades using the following formula for standard deviation, �: � = #1 �&(�! − �)" # !$% where � is the number of grades, or ����, �! are the individual grades, and � is the mean. Let’s go ahead and start: • First, declare a constant integer called SIZE and initialize it to 10. • Now, declare an array of floating-point numbers called grades that can hold 10 grades, using the constant that you just declared for the size. 2 • Declare three additional floating-point numbers to store the mean (i.e., average), sum, and standard deviation. Initialize both the sum and standard deviation variables to 0. • Process the array of grades using a for loop as follows to read in the grades and calculate the mean: o Prompt for and read in grades into the array. o Add each grade to the current sum. • Calculate the mean by taking the sum of all the grades and dividing by SIZE. • Now, use another for loop to sum the square of the difference of the grades and the mean as follows: o Add the square of the difference of the grade and the mean to the standard deviation. To make things clearer, use the pow() function with the first argument being the current grade in the array minus the mean, and the second argument being 2 for the square. Then, simply add that result to the current standard deviation. • Finally, take the square root of the standard deviation divided by SIZE and print the result. As an example, the standard deviation of 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10 is 2.87228. Once you complete your program, save the file as Lab6A.cpp, making sure to compile and run the program to verify that it produces the correct results. Note that you will submit this file to Canvas.

Solutions

Expert Solution

Here is the C++ code with detailed comments to the given question.

Sample output is added at the end.

Code: Lab6A.cpp :

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    
   const int SIZE=10;  /*declares a constant integer called SIZE and initializes it to 10*/
   
   float grades[SIZE]; /*declares an array of floating-point numbers called grades that can hold 'SIZE' number of grades*/
   
   float mean,sum=0,standardDeviation=0; /*declares three floating-point numbers to store the mean, sum, and standard deviation. sum and standardDeviation areinitialized to 0*/
   
   for(int i=0;i<SIZE;i++){   /*runs the loop from i=0 to i=SIZE-1*/
       
       cout<<"Enter grade "<<i+1<<": ";  /*asks user to enter grade*/
       cin>>grades[i];    /*takes the value of entered grade and stores it ib grades[i]*/
       sum+=grades[i];    /*adds the current grade to sum*/
       
   }
   
   mean=sum/SIZE;   /*calculates mean by divideing sum with SIZE*/
   
   for(int i=0;i<SIZE;i++){    /*runs the loop from i=0 to i=SIZE-1*/
       
       standardDeviation+=pow(grades[i]-mean,2);     /*computes the square of difference between current grade and mean and adds it to standardDeviation*/
       
   }
   
   standardDeviation=sqrt(standardDeviation/SIZE);   /*computes standardDeviation by taking square root of standardDeviation divided by SIZE*/
   
   cout<<"\nStandard deviation of the entered data is "<<standardDeviation;    /*prints the standard deviation */
   
}

Sample output:


Related Solutions

Arrays provide the programmer the ability to store a group of related variables in a list...
Arrays provide the programmer the ability to store a group of related variables in a list that can be accessed via an index. This is often very useful as most programs perform the same series of calculations on every element in the array. To create an array of 10 integers (with predefined values) the following code segment can be utilised: int valueList[10] = {4,7,1,36,23,67,61,887,12,53}; To step through the array the index '[n]' need to be updated. One method of stepping...
You will need to use only two arrays:  One array of type int to store...
You will need to use only two arrays:  One array of type int to store all the ID's  One two‐dimensional array of type double to store all the scores for all quizzes Note: The two dimensional array can be represented also with the rows being the students and the columns being the quizzes. How to proceed: 1. Declare the number of quizzes as a constant, outside the main method. (Recall that identifiers for constants are all in CAPITAL_LETTERS.)...
. As input you are given two arrays: an array of numbers ? and an array...
. As input you are given two arrays: an array of numbers ? and an array ? of queries where each query is a target number. The array ? is unsorted and may contain duplicates. Your goal is, for each query ? in the array ?, count the number of pairs in the array ? that sums up to ?; that is, the number of distinct pairs of indices [?, ?], with ? < ?, such that ?[?] + ?[?]...
You are given an array of arrays a. Your task is to group the arrays a[i]...
You are given an array of arrays a. Your task is to group the arrays a[i] by their mean values, so that arrays with equal mean values are in the same group, and arrays with different mean values are in different groups. Each group should contain a set of indices (i, j, etc), such that the corresponding arrays (a[i], a[j], etc) all have the same mean. Return the set of groups as an array of arrays, where the indices within...
Overlapping Arrays (C++) An array overlaps another array if all elements of the latter array exist...
Overlapping Arrays (C++) An array overlaps another array if all elements of the latter array exist in the former array. They need not necessarily be in the same order. For example, [1,7,3,4,2] overlaps [1,2,3] because 1,2 and 3 exist in [1,7,3,4,2]. To make the implementation easy, [1,7,3,4,2] overlaps [1,1,2,3] as well. We don’t need to check whether 1 appears twice in the first array. Write a program that lets the user enter two arrays and displays whether the first array...
In c++ Array expander Write a function that accepts an int array and the arrays size...
In c++ Array expander Write a function that accepts an int array and the arrays size as arguments. The function should create a new array that is twice the size of the argument array. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array and initialize the unused elements of the second array with 0. The function should return a...
Is it ethical for a company to sell water, which is basically all the same, in...
Is it ethical for a company to sell water, which is basically all the same, in a way that commands such high prices?
1 of 10 When declaring a jagged array, all dimensions must have the same type. True...
1 of 10 When declaring a jagged array, all dimensions must have the same type. True False Question 2 of 10 What is the maximum number of dimensions you can declare for an array in C#? 3 10 5 There is no maximum. Question 3 of 10 When you declare a two-dimensional array, you place two numbers within square brackets. What does the first number represent? Class Index Column Row Question 4 of 10 When declaring a multidimensional array, all...
1. With respect to resizable arrays, establish the relationship between the size of the array and...
1. With respect to resizable arrays, establish the relationship between the size of the array and the time it takes to perform random access (read a the value stored at a given position somewhere in the array). Provide empirical evidence to support your answer.
There is a lab assignment. Basically includes array and some other basic stuff. Comment if you...
There is a lab assignment. Basically includes array and some other basic stuff. Comment if you have any questions. Thank you. I have got all classes here so that it might be more make sense. BUS CLASS package classes; //DO NOT ERASE THE TODO STUBS! WRITE YOUR SOLUTIONS BELOW THE STUBS! public class Bus extends Commercial {       private int numPassengers;       public Bus()    {        super();        numPassengers = 0;    }      ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT