* --Originally published at Franco TC1017*

This program asks the user for 10 numbers and then stores them in a list. Then the average and the standard deviation of these 10 numbers is calculated.

Skip to content
# Tag: #WSQ07

# WSQ 07 Lists

# WSQ 07 Lists

# Lists

# WSQ 07

# #WSQ07

## Code

# Lists!… #WSQ07

# Cout << “List” << endl; // WSQ07

# “List”

# THE List -.-‘! (WSQ07)

# WSQ07 Lists

# RZArector

Solving Problems with Programming

* --Originally published at Franco TC1017*

This program asks the user for 10 numbers and then stores them in a list. Then the average and the standard deviation of these 10 numbers is calculated.

* --Originally published at Franco TC1017*

This program asks the user for 10 numbers and then stores them in a list. Then the average and the standard deviation of these 10 numbers is calculated.

* --Originally published at RAMGGV*

Para este programa se nos pidió la suma, promedio y desviación estándar de una lista.

* --Originally published at blog de Horacio*

Create a program that asks the user for 10 numbers (floating point). Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers.

Before we get started, let’s define the average and the standard deviation.

- Standard deviation: Is a measure that is used to quantify the amount of variation or dispersion of a set of data values. (Source: https://en.wikipedia.org/wiki/Standard_deviation)
- Average: Is the sume of all the elements of a list divided by the number of elements.
code:#include <iostream>

#include <math.h>

using namespace std;int main(){

float numeros [10];

float suma =0, prom =0, desv, desv1;

cout << “Introduce 10 numeros para saber la suma, el promedio, y desviación estandar: ” << endl;

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

cin >> numeros[i];

suma += numeros[i];

}

prom = suma/10;

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

desv += pow((numeros[i] – prom),2);

desv1 = sqrt(desv/9);

cout << “\nLa suma es: ” << suma;

cout << “\nEl promedio es: ” << prom;

cout << “\nLa desviacion estandar es: ” << desv1;

return 0;

};

* --Originally published at OlafGC / Class #TC1017*

Here it is, the first time I used vectors. You have to get used to it because the logic of calling a function and then the parameter is not something we are pretty used to, so I need a lot of practice. Also, a friend of mine helped me realizing I have committed a mistake: calling a function “sum”. Please, if you are going to name functions, use another name. If you need help, just send me a Twitter.

#include <iostream>

#include <vector>

#include <cmath>

using namespace std;

float suma (vector<float> list)

{

float suma=0, n=0;

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

{

suma+=list[count];

} return suma;

}

float average(vector<float> list)

{

float average;

average=suma(list)/10;

return average;

}

float stdv(vector<float> list)

{

float sigma=0, stdv=0;

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

{

sigma+=pow(list [count]-average(list), 2);

}

stdv=sqrt(sigma/10);

return stdv;

}

int main()

{

vector <float> list;

float n,av,dev,sum;

cout<<“Please insert 10 numbers:”<<endl;

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

{

cin>>n;

list.push_back(n);

}

cout<<“The sum of the numbers is “<<suma(list)<<“.”<<endl;

cout<<“The average of the numbers is “<<average(list)<<“.”<<endl;

cout<<“The standart deviation of the numers is “<<stdv(list)<<“.”<<endl;

}

* --Originally published at It's me*

This program was a little more difficult. We needed to create a program that asks the user for 10 numbers and those numbers have to be stored in a list. With those numbers the program will calculate their total, average and standard deviation. I searched a lot and found information but I really didn’t understand how to do it, so I asked help of a friend of mine that know how to program in C++ and watching my classmates works as example. Here is my code:

* --Originally published at Alvaro_246*

En esta tarea hice un programa que le pidiera al usuario 10 números y realizara las siguientes funciones

Este programa tiene 3 funciones:

1- La “**sumatoria”**de los números:

*float Sumatoria(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j){*

* float Rsum;*

* Rsum = (a + b + c + d + e + f + g + h + i + j);*

* return Rsum; *

2- El “**promedio** “de los 10 números:

*float Promedio(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j){*

* float Rprom;*

* Rprom = ((a + b + c + d + e + f + g + h + i + j)/10);*

* return Rprom;*

3- Por ultimo y más complicado la “**Desviación estándar”** entre los 10 números:

*float Varianza(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j){*

* float Rvari, Pizza, Total, DesvSTD;*

* Total = (a + b + c + d + e + f + g + h + i + j);*

* Pizza = Total/10;*

* Rvari = pow(a-Pizza,2)+pow(b-Pizza,2)+pow(c-Pizza,2)+pow(d-Pizza,2)+pow(e-Pizza,2)+pow(f-Pizza,2)+pow(g-Pizza,2)+pow(h-Pizza,2)+pow(i-Pizza,2)+pow(j-Pizza,2);*

* DesvSTD = sqrt(Rvari/10);*

* return DesvSTD;*

**Código y Resultados:**

* --Originally published at Programming Path*

What a way to give me stress! This task gave me a lot of problems, because it was the first time for me to use arrays, and I looked it in the textbook of the course but didn’t help that much. Then I looked for arrays in the net. I found a tutorial of arrays that explains what are they for and how to use them.

Anyway, the task was this:

Create a program that asks the user for 10 numbers (floating point). Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers.

We could use arrays or vectors. I didn’t know neither of those, but is never too late to try learn something new. After I understood a little about how do the arrays work I started writing my code. Everything was fine until I needed the standard deviation. To be honest, I did not know what was the standard deviation until this task, I don’t even remember seeing it in elementary school, or middle school, so I had to look for the formula. Here is the formula:

After finding the formula, it gave me a lot more trouble because I had to assign more variables. And that is how I ended up with this code. Not vary proud of this:

#include <iostream>

#include <cmath>

using namespace std;float total, av, stde, s;

float StandardD (float,float,float,float,float,float,float,float,float,float);int main () {

Continue reading "THE List -.-‘! (WSQ07)"

float a, b, c, d, e, f, g, h, i, j;

float foo [] = {a, b, c, d, e, f, g, h, i, j};

cout << “Enter 10 numbers. I will give you the total, average and stadard deviation of them.” << endl;

cout << endl << “Number 1: “;

cin >> a;

cout << endl

* --Originally published at Solving problems with programming*

In this homework what we had to do is ask for the user for 10 numbers, save them, display them and with all of them calculate the avegrage and the standart deviation. To start with we need to use an array. An array is a variable that can save multiple variables. How they work is like the other variables , you need to specify that is a variable.

float array[10];

This means that the variable in the array are going to be floating point and the [10], means that the array is going to consist of 10 variables, you can save 10 numbers in that array.

To fill data in the array, you do it like with any other variable.

cin>>array[0];

But in the arrays you need to spicify wich variable of the 10 spaces you created, you are going to save. In This code i’m saying that i’m gong to enter variable of the first spot. In arrays you start counting the spots from 0. Being that have 10 spots y can enter variables from the spot 0 to the spot 9.

So at the beggining of the program i wil ask for 10 variables. I’m going to use a for loop to enter all these variables in my array. The key here is to change the spot of what i’m entering to my array, every repetition i’m going to enter the next spot available in my array.

for(int i=0;i<10;i++){ cout<<"Escribe tu valor "<<i+1<<endl; cin>>array[i];

The other important information we need for this program, is to calculate the **sanadart deviation.** I didn’ what it was but in this page I understood it excellent. To get the standart deviation you also need arrays, but I’ll let you think how to do it. Anyway if there is any problem I let

* --Originally published at prgrm.co*

Alright WSQ07.

This one had me smacking my pencil against my head for a while. We needed to make a program that asks the user for values and then it gives back the sum, average and standard deviation, using vectors.

Ok, piece of cake! Yeah right, Ken came along and told me to do it with functions, at this point it got interesting.

This is the main() of the program, let’s check it out by parts:

nt main(){ int i, n, thesum = 0; cout << "Insert the values you want: "; cin >> n; vector <float> values(n); for (i=0; i<n; i++){ cout << "Insert number: " ; cin >> values[i]; } cout << endl << "The sum of the values you have selected is: " << sum(values); cout << endl << "The average of the values you have selected is: " << average(values); cout << endl << "The standart deviaton of this set of number is: " << standart(values) << endl; return 0; }

- First important part: vector <float> values(n). As you can see here the vector is being declared then in between “< >” you determine the type variable and finally the name of the vector and how many numbers it will have.
- Then the number of values the user will provide the program with:

int i, n, thesum = 0; cout << "Insert the values you want: "; cin >> n; vector <float> values(n); for (i=0; i<n; i++){ cout << "Insert number: " ; cin >> values[i]; }

As you can see here, the program ask the user for the values wanted and then a for loop will store this values in the vector <float> values (n);

That was the easy part now let’s move on to the functions, the first one will add up all

Continue reading "RZArector"