需要有关功能程序的帮助 [英] Need Help with the functions program

查看:125
本文介绍了需要有关功能程序的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要立即帮助编写功能程序。我必须在函数中编写一个

程序并使用数组来存储它们。我不熟悉

有功能,我试图创建它,但我无法运行,但是,我的b $ b只是在数组中创建这个程序,它运行良好,除了我不能

弄清楚如何计算标准偏差。编码如下。

任何帮助将不胜感激。


1)本程序将提示用户输入六个等级(一个

,一次读取用户的每个等级,以及六个

元素的数组。


2)平均值等级(再次,在0.0-4.0的范围内),再次循环通过

数组;


3)程序将计算标准偏差6个b / b
平均个人成绩按照以下公式计算:


n-1

E(x [i] - avg )2

I = 0 ___________________


n-1

其中n是平均值的数量(在此为6) case),

x [i]是一个特定的值,并且是所有n个值的avd。即,对于每个

的n值,你取得该值与

平均值之差,平方差值和所有n个平方值之和。然后将n $ 1的和b $ b总和,并取该商的平方根。这给你

的标准偏差。


#include< iostream>


using namespace std;


int main()

{

const int SIZE = 6;

双倍得分[SIZE ];

int i = 0;

double sum = 0;

string grade;


for(i = 0; i< SIZE; i ++)


{

cout<< 输入分数 << i + 1<< ":" ;

cin>得分[i];


而得分(得分[i] 4 ||得分[i]< 0)

{

cout<<""成绩无效 - 请重新输入成绩

<< "介于0和4.0之间:;

cin>得分[i];

}

sum = sum +得分[i] ;

}


双倍平均值= sum / 6;

if(平均值< = 4.0&& average 3.2) )

{

grade =" A";

}

if(average< = 3.2& ;&平均2.4)

{

grade =" B";

}

if(average) < = 2.4&&平均1.6)

{

grade =" C";

}

if(平均< = 1.6&&平均0.8)

{

grade =" D";

}

if(平均< = 0.8&&平均0)

{

grade =" F";

}


//输出结果:

cout<< 平均值是指 <<平均<< "。" << endl;


cout<< 最终的字母等级是 <<等级<< endl;

返回0;

} //功能主

I need immediate help in writing a function program. I have to write a
program in functions and use array to store them. I am not familiar
with functions and i tried to create it but i fails to run, However, i
simply created this program in arrays and it runs good except i cant
figure out how to compute the standard deviation. The coding is below.
Any help will be appreciated.

1) The Program will prompt the user for six grades to be entered (one
at a time, read in each grade by the user , and them in an array of six
elements.

2) The average grade (again, on a 0.0 - 4.0 scale), by looping through
the array again;

3) The program will compute the standard deviation of the six
individual grades from the average according to following formula:

n-1
E (x[i] - avg)2
I=0___________________

n-1
where n is the number of values that were averaged (6 in this case),
x[i] is a particular value, and avd of all n values. I.e for each of
the n values, you take the difference between that value and the
average, square that difference, and sum all n squares. Then divid that
sum by n-1 and take the square root of that quotient. This gives you
the standard deviation.

#include <iostream>

using namespace std;

int main()
{
const int SIZE = 6;
double score[SIZE];
int i =0;
double sum = 0;
string grade;

for ( i = 0; i < SIZE; i++)

{
cout << "Input a Score " << i+1 << ":" ;
cin >score[i];

while (score[i] 4 || score[i] < 0)
{
cout <<" Invalid grade - please re-enter a grade"
<< " between 0 and 4.0 inclusive : ";
cin >score[i];
}
sum = sum + score[i];
}

double average = sum / 6 ;
if (average <= 4.0 && average 3.2)
{
grade = "A";
}
if (average <= 3.2 && average 2.4)
{
grade = "B";
}
if (average <= 2.4 && average 1.6)
{
grade = "C";
}
if (average <= 1.6 && average 0.8)
{
grade = "D";
}
if (average <= 0.8 && average 0)
{
grade = "F";
}

// Output the result:
cout << "The average is " << average << "." << endl;

cout << "The final letter grade is " << grade << endl;
return 0;
} // function main

推荐答案

< as ***** @ hotmail.comwrote in message

news:11 ********************* @ l12g2000cwl。 googlegro ups.com
<as*****@hotmail.comwrote in message
news:11*********************@l12g2000cwl.googlegro ups.com

我需要立即帮助编写函数程序。我必须在函数中编写一个

程序并使用数组来存储它们。我不熟悉

有功能,我试图创建它,但我无法运行,
I need immediate help in writing a function program. I have to write a
program in functions and use array to store them. I am not familiar
with functions and i tried to create it but i fails to run,



没有你的课程封面功能?不是你的教科书吗?


我认为你被要求做的就是将在main()中进行的操作分解为几个步骤,每个都由一个

函数执行。


我建议你在这里发布你的函数尝试,我们可以给你

关于你哪里出错的建议。

Didn''t your class cover functions? Doesn''t your textbook?

I presume that what you are being asked to do is break up the operations
conducted in main() into several steps, each of which is performed by a
function.

I suggest you post your attempt with functions here and we can give
suggestions as to where you are going wrong.


但是,我只需要在数组中创建这个程序,它运行良好,除了我不能

弄清楚如何计算标准偏差。
However, i
simply created this program in arrays and it runs good except i cant
figure out how to compute the standard deviation.



使用for()循环。在每个

迭代中计算(得分[i] - 平均值)*(得分[i] - 平均值)。你可以搞清楚其余部分。

Use a for() loop. Compute (score[i] - average)*(score[i]-average) at each
iteration. You can figure out the rest.


编码是

以下。任何帮助将不胜感激。


1)本程序将提示用户输入六个等级(一个

,每个等级读一次由用户和他们组成的元素

六元素。


2)平均等级(再次,在0.0-4.0范围内),循环再次通过

阵列;


3)该程序将计算6个

个别等级的标准差。平均值根据以下公式:


n-1

E(x [i] - avg)2

I = 0 ___________________


n-1

其中n是平均值的数量(在这种情况下为6),

x [i ]是一个特定值,并且是所有n个值的avd。即,对于每个

的n值,你取得该值与

平均值之差,平方差值和所有n个平方值之和。然后divid

总和n-1并取该商的平方根。这给你

你的标准偏差。


#include< iostream>


使用命名空间std;


int main()

{

const int SIZE = 6;

双倍得分[SIZE ];

int i = 0;

double sum = 0;

string grade;


for(i = 0; i< SIZE; i ++)


{

cout<< 输入分数 << i + 1<< ":" ;

cin>得分[i];


而得分(得分[i] 4 ||得分[i]< 0)

{

cout<<""成绩无效 - 请重新输入成绩

<< "介于0和4.0之间:;

cin>得分[i];

}

sum = sum +得分[i] ;

}


双倍平均值= sum / 6;


if(平均值< = 4.0& & average 3.2)

{

grade =" A";

}

if(average< ; = 3.2&&平均2.4)

{

grade =" B";

}

如果(平均< = 2.4&&平均1.6)

{

grade =" C";

}

if(平均< = 1.6&&平均0.8)

{

grade =" D";

}

if(平均< = 0.8&&平均0)

{

grade =" F" ;; < br $>
}


//输出结果:

cout<< 平均值是指 <<平均<< "。" << endl;


cout<< 最终的字母等级是 <<等级<< endl;

返回0;

} //功能主
The coding is
below. Any help will be appreciated.

1) The Program will prompt the user for six grades to be entered (one
at a time, read in each grade by the user , and them in an array of
six elements.

2) The average grade (again, on a 0.0 - 4.0 scale), by looping through
the array again;

3) The program will compute the standard deviation of the six
individual grades from the average according to following formula:

n-1
E (x[i] - avg)2
I=0___________________

n-1
where n is the number of values that were averaged (6 in this case),
x[i] is a particular value, and avd of all n values. I.e for each of
the n values, you take the difference between that value and the
average, square that difference, and sum all n squares. Then divid
that sum by n-1 and take the square root of that quotient. This gives
you the standard deviation.

#include <iostream>

using namespace std;

int main()
{
const int SIZE = 6;
double score[SIZE];
int i =0;
double sum = 0;
string grade;

for ( i = 0; i < SIZE; i++)

{
cout << "Input a Score " << i+1 << ":" ;
cin >score[i];

while (score[i] 4 || score[i] < 0)
{
cout <<" Invalid grade - please re-enter a grade"
<< " between 0 and 4.0 inclusive : ";
cin >score[i];
}
sum = sum + score[i];
}

double average = sum / 6 ;
if (average <= 4.0 && average 3.2)
{
grade = "A";
}
if (average <= 3.2 && average 2.4)
{
grade = "B";
}
if (average <= 2.4 && average 1.6)
{
grade = "C";
}
if (average <= 1.6 && average 0.8)
{
grade = "D";
}
if (average <= 0.8 && average 0)
{
grade = "F";
}

// Output the result:
cout << "The average is " << average << "." << endl;

cout << "The final letter grade is " << grade << endl;
return 0;
} // function main



-

John Carson



--
John Carson





John Carson写道:

John Carson wrote:

< as ***** @ hotmail.comwrote in message

news:11 ******************** *@l12g2000cwl.googlegro ups.com
<as*****@hotmail.comwrote in message
news:11*********************@l12g2000cwl.googlegro ups.com

我需要立即帮助编写函数程序。我必须在函数中编写一个

程序并使用数组来存储它们。我不熟悉

有功能,我试图创建它,但我无法运行,
I need immediate help in writing a function program. I have to write a
program in functions and use array to store them. I am not familiar
with functions and i tried to create it but i fails to run,



没有你的课程封面功能?不是你的教科书吗?


我认为你被要求做的就是将在main()中进行的操作分解为几个步骤,每个都由一个

函数执行。


我建议你在这里发布你的函数尝试,我们可以给你

关于你哪里出错的建议。


Didn''t your class cover functions? Doesn''t your textbook?

I presume that what you are being asked to do is break up the operations
conducted in main() into several steps, each of which is performed by a
function.

I suggest you post your attempt with functions here and we can give
suggestions as to where you are going wrong.


但是,我只需要在数组中创建这个程序,它运行良好,除了我不能

弄清楚如何计算标准偏差。
However, i
simply created this program in arrays and it runs good except i cant
figure out how to compute the standard deviation.



使用for()循环。在每个

迭代中计算(得分[i] - 平均值)*(得分[i] - 平均值)。你可以搞清楚其余部分。


Use a for() loop. Compute (score[i] - average)*(score[i]-average) at each
iteration. You can figure out the rest.


编码是

以下。任何帮助将不胜感激。


1)本程序将提示用户输入六个等级(一个

,每个等级读一次由用户和他们组成的元素

六元素。


2)平均等级(再次,在0.0-4.0范围内),循环再次通过

阵列;


3)该程序将计算6个

个别等级的标准差。平均值根据以下公式:


n-1

E(x [i] - avg)2

I = 0 ___________________


n-1

其中n是平均值的数量(在这种情况下为6),

x [i ]是一个特定值,并且是所有n个值的avd。即,对于每个

的n值,你取得该值与

平均值之差,平方差值和所有n个平方值之和。然后divid

总和n-1并取该商的平方根。这给你

你的标准偏差。


#include< iostream>


使用命名空间std;


int main()

{

const int SIZE = 6;

双倍得分[SIZE ];

int i = 0;

double sum = 0;

string grade;


for(i = 0; i< SIZE; i ++)


{

cout<< 输入分数 << i + 1<< ":" ;

cin>得分[i];


而得分(得分[i] 4 ||得分[i]< 0)

{

cout<<""成绩无效 - 请重新输入成绩

<< "介于0和4.0之间:;

cin>得分[i];

}

sum = sum +得分[i] ;

}


双倍平均值= sum / 6;

if(平均值< = 4.0&& average 3.2) )

{

grade =" A";

}

if(average< = 3.2& ;&平均2.4)

{

grade =" B";

}

if(average) < = 2.4&&平均1.6)

{

grade =" C";

}

if(平均< = 1.6&&平均0.8)

{

grade =" D";

}

if(平均< = 0.8&&平均0)

{

grade =" F";

}


//输出结果:

cout<< 平均值是指 <<平均<< "。" << endl;


cout<< 最终的字母等级是 <<等级<< endl;

返回0;

} //功能主
The coding is
below. Any help will be appreciated.

1) The Program will prompt the user for six grades to be entered (one
at a time, read in each grade by the user , and them in an array of
six elements.

2) The average grade (again, on a 0.0 - 4.0 scale), by looping through
the array again;

3) The program will compute the standard deviation of the six
individual grades from the average according to following formula:

n-1
E (x[i] - avg)2
I=0___________________

n-1
where n is the number of values that were averaged (6 in this case),
x[i] is a particular value, and avd of all n values. I.e for each of
the n values, you take the difference between that value and the
average, square that difference, and sum all n squares. Then divid
that sum by n-1 and take the square root of that quotient. This gives
you the standard deviation.

#include <iostream>

using namespace std;

int main()
{
const int SIZE = 6;
double score[SIZE];
int i =0;
double sum = 0;
string grade;

for ( i = 0; i < SIZE; i++)

{
cout << "Input a Score " << i+1 << ":" ;
cin >score[i];

while (score[i] 4 || score[i] < 0)
{
cout <<" Invalid grade - please re-enter a grade"
<< " between 0 and 4.0 inclusive : ";
cin >score[i];
}
sum = sum + score[i];
}

double average = sum / 6 ;
if (average <= 4.0 && average 3.2)
{
grade = "A";
}
if (average <= 3.2 && average 2.4)
{
grade = "B";
}
if (average <= 2.4 && average 1.6)
{
grade = "C";
}
if (average <= 1.6 && average 0.8)
{
grade = "D";
}
if (average <= 0.8 && average 0)
{
grade = "F";
}

// Output the result:
cout << "The average is " << average << "." << endl;

cout << "The final letter grade is " << grade << endl;
return 0;
} // function main




-

John Carson



--
John Carson


你的课程覆盖功能不是吗?不是你的教科书吗?
Didn''t your class cover functions? Doesn''t your textbook?



相信我,他们教导它的方式,我需要天真才能理解。

我对函数没有任何理解所有。相信我

我不会自己做的。请在某种程度上帮助我。

可以做点什么。

Believe me, the way they teach it, i need to be genious to understand.
I dont have any any understanding of functions at all. Belive me
otherewise i wouldve done it by myself. Please help me in some extent i
could do something.


我认为你被要求做的就是打破行动

在main()中进行了几个步骤,每个步骤由一个

函数执行
I presume that what you are being asked to do is break up the operations
conducted in main() into several steps, each of which is performed by a
function



是你是对的。所有我知道他们宣布全局变量并且在main()之前做了
循环。

请在这里帮助我。

Yes you are right. All i know they declare the Global varaibles and do
loop before the main().
Please help me here.




John Carson写道:

John Carson wrote:

< as ***** @ hotmail.comwrote in message

新闻:11 ********************* @ l12g2000cwl.googlegro ups.com
<as*****@hotmail.comwrote in message
news:11*********************@l12g2000cwl.googlegro ups.com

我需要立即帮助编写功能程序。我必须在函数中编写一个

程序并使用数组来存储它们。我不熟悉

有功能,我试图创建它,但我无法运行,
I need immediate help in writing a function program. I have to write a
program in functions and use array to store them. I am not familiar
with functions and i tried to create it but i fails to run,



没有你的课程封面功能?不是你的教科书吗?


我认为你被要求做的就是将在main()中进行的操作分解为几个步骤,每个都由一个

函数执行。


我建议你在这里发布你的函数尝试,我们可以给你

关于你哪里出错的建议。


Didn''t your class cover functions? Doesn''t your textbook?

I presume that what you are being asked to do is break up the operations
conducted in main() into several steps, each of which is performed by a
function.

I suggest you post your attempt with functions here and we can give
suggestions as to where you are going wrong.


但是,我只需要在数组中创建这个程序,它运行良好,除了我不能

弄清楚如何计算标准偏差。
However, i
simply created this program in arrays and it runs good except i cant
figure out how to compute the standard deviation.



使用for()循环。在每个

迭代中计算(得分[i] - 平均值)*(得分[i] - 平均值)。你可以搞清楚其余部分。


Use a for() loop. Compute (score[i] - average)*(score[i]-average) at each
iteration. You can figure out the rest.


编码是

以下。任何帮助将不胜感激。


1)本程序将提示用户输入六个等级(一个

,每个等级读一次由用户和他们组成的元素

六元素。


2)平均等级(再次,在0.0-4.0范围内),循环再次通过

阵列;


3)该程序将计算6个

个别等级的标准差。平均值根据以下公式:


n-1

E(x [i] - avg)2

I = 0 ___________________


n-1

其中n是平均值的数量(在这种情况下为6),

x [i ]是一个特定值,并且是所有n个值的avd。即,对于每个

的n值,你取得该值与

平均值之差,平方差值和所有n个平方值之和。然后divid

总和n-1并取该商的平方根。这给你

你的标准偏差。


#include< iostream>


使用命名空间std;


int main()

{

const int SIZE = 6;

双倍得分[SIZE ];

int i = 0;

double sum = 0;

string grade;


for(i = 0; i< SIZE; i ++)


{

cout<< 输入分数 << i + 1<< ":" ;

cin>得分[i];


而得分(得分[i] 4 ||得分[i]< 0)

{

cout<<""成绩无效 - 请重新输入成绩

<< "介于0和4.0之间:;

cin>得分[i];

}

sum = sum +得分[i] ;

}


双倍平均值= sum / 6;

if(平均值< = 4.0&& average 3.2) )

{

grade =" A";

}

if(average< = 3.2& ;&平均2.4)

{

grade =" B";

}

if(average) < = 2.4&&平均1.6)

{

grade =" C";

}

if(平均< = 1.6&&平均0.8)

{

grade =" D";

}

if(平均< = 0.8&&平均0)

{

grade =" F";

}


//输出结果:

cout<< 平均值是指 <<平均<< "。" << endl;


cout<< 最终的字母等级是 <<等级<< endl;

返回0;

} //功能主
The coding is
below. Any help will be appreciated.

1) The Program will prompt the user for six grades to be entered (one
at a time, read in each grade by the user , and them in an array of
six elements.

2) The average grade (again, on a 0.0 - 4.0 scale), by looping through
the array again;

3) The program will compute the standard deviation of the six
individual grades from the average according to following formula:

n-1
E (x[i] - avg)2
I=0___________________

n-1
where n is the number of values that were averaged (6 in this case),
x[i] is a particular value, and avd of all n values. I.e for each of
the n values, you take the difference between that value and the
average, square that difference, and sum all n squares. Then divid
that sum by n-1 and take the square root of that quotient. This gives
you the standard deviation.

#include <iostream>

using namespace std;

int main()
{
const int SIZE = 6;
double score[SIZE];
int i =0;
double sum = 0;
string grade;

for ( i = 0; i < SIZE; i++)

{
cout << "Input a Score " << i+1 << ":" ;
cin >score[i];

while (score[i] 4 || score[i] < 0)
{
cout <<" Invalid grade - please re-enter a grade"
<< " between 0 and 4.0 inclusive : ";
cin >score[i];
}
sum = sum + score[i];
}

double average = sum / 6 ;
if (average <= 4.0 && average 3.2)
{
grade = "A";
}
if (average <= 3.2 && average 2.4)
{
grade = "B";
}
if (average <= 2.4 && average 1.6)
{
grade = "C";
}
if (average <= 1.6 && average 0.8)
{
grade = "D";
}
if (average <= 0.8 && average 0)
{
grade = "F";
}

// Output the result:
cout << "The average is " << average << "." << endl;

cout << "The final letter grade is " << grade << endl;
return 0;
} // function main




-

John Carson



--
John Carson


你的课程覆盖功能不是吗?不是你的教科书吗?
Didn''t your class cover functions? Doesn''t your textbook?



相信我,他们教导它的方式,我需要天真才能理解。

我对函数没有任何理解所有。相信我

我不会自己做的。请在某种程度上帮助我。

可以做点什么。

Believe me, the way they teach it, i need to be genious to understand.
I dont have any any understanding of functions at all. Belive me
otherewise i wouldve done it by myself. Please help me in some extent i
could do something.


我认为你被要求做的就是打破行动

在main()中进行了几个步骤,每个步骤由一个

函数执行
I presume that what you are being asked to do is break up the operations
conducted in main() into several steps, each of which is performed by a
function



是你是对的。所有我知道他们宣布全局变量并且在main()之前做了
循环。

请在这里帮助我。

Yes you are right. All i know they declare the Global varaibles and do
loop before the main().
Please help me here.


这篇关于需要有关功能程序的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆