#WSQ07

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.

Code

#include
#include
#include
using namespace std;

float suma (vector list)
{
float suma=0, n=0;
for (int count=0; count<10; count++)
{
suma+=list[count];
} return suma;
}

float average(vector list)
{
float average;
average=suma(list)/10;
return average;
}

float stdv(vector 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 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;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s