gpt4 book ai didi

vb.net - 伪代码检查。需要验证分配

转载 作者:行者123 更新时间:2023-12-04 18:54:32 24 4
gpt4 key购买 nike

我已经上交了,所以您不会帮我作弊。只是想知道这看起来是否正确:

那作业:
输入员工姓名和工资列表,然后确定
平均(平均)薪水以及以上薪水和
低于均值。

计划:
允许输入姓名和工资
计算均值
排序值
计数高于平均值
计数低于均值

//This program will allow a user to input an employee name and salary
//The output will contain the mean salary
//as well as the number of salaries above and below the mean
//
//Arrays Used:
//Name(K) = Array for employee names
//Salary(K) = Array for salaries
//
//Variables Used:
//Mean = Mean of all employees Salaries
//UpMean = Number of Employees making more than the mean
//DwnMean = Number of Employees making less than the mean
//Sum = Sum of all salaries
//CountM = Counter for Mean
//CountUp = Counter for # of salaries above mean
//CountDwn = Counter for # of salaries below mean

Main
Call WelcomeMessage
Call InputData
Call Calculate
Call OutputData
End Program

WelcomeMessage
Write, “Beginning the Salary Program”
End WelcomeMessage

InputData
Declare Name(100) Of Strings
Declare Salary(100) Of Real
Declare Mean, UpMean, DwnMean As Real
Set Sum = 0
Set CountM = 0
Set CountUp = 0
Set CountDwn = 0
Write, "Enter Employee name and Salary."
Write, "Enter *,0 when done."
Input Name(K), Salary(K)
While Name(K) <> "*"
Set CountM = CountM + 1
Set Sum = Sum + Salary
Write, "Enter Employee name and Salary."
Write, "Enter *,0 when done."
Input Name(K), Salary(K)
End While
End InputData

Calculation
//Here Mean is found
Set Mean = Sum / CountM
//Here Number of Employees making more than the mean is found
For K = Step 1 to CountM
If Salary(K) > Mean Then
Set CountUp = CountUp + 1
End If
//Here Number of Employees making more than the mean is found
Set CountDwn = CountM - CountUp
//The above algorythm doesn't account for the possibility
//of someone making exactly the average so subtract 1 to reconcile
If Salary(K) = Mean Then
Set CountDwn = CountDwn - 1
End If
End Calculation

OutputData
Write, "There were," CountM, "salaries entered."
Write, "The mean salary is:", Mean
Write, "There are", CountUp, "employees who make more than the average"
Write, "There are", CountDwn, "employees who make less than the average"
End OutputData

最佳答案

关于计算CountDwn的说明:

您的“减1调和”将取决于For循环在实现语言中的工作方式,(a)生成“未声明变量”类型的错误,(b)生成“索引超出范围”的错误,或者( c)减去一个IFF,最后的工资与平均工资完全相等。 (此外,您的代码在End For中不包含Calculation,但是我认为它应该紧接在该函数中的第一个End If之后。)

我建议不要在CountDwn中计算CountUp(毕竟,每个薪水都可以等于平均值​​),建议在循环中将其包括在内:

Calculation
//Here Mean is found
Set Mean = Sum / CountM

For K = Step 1 to CountM
//Here Number of Employees making more than the mean is found
If Salary(K) > Mean Then
Set CountUp = CountUp + 1
End If

//Here Number of Employees making less than the mean is found
If Salary(K) < Mean Then
Set CountDwn = CountDwn + 1
End If
End For
End Calculation

注意 CountUp + CountDwn不一定等于 CountM

关于vb.net - 伪代码检查。需要验证分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/984218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com