gpt4 book ai didi

c - void函数和float函数有什么区别?

转载 作者:太空宇宙 更新时间:2023-11-04 06:22:04 25 4
gpt4 key购买 nike

我还在学习但是......我不认为这些功能:

void CalculateGross(float hours, float payrate, float *gross) //3.4
float CalculateGross(float hours, float payrate) //3.4

做同样的事情。那么哪个更好呢?我假设 void 更好?

/*

3.0 Payroll Application

3.1 PrintReportHeadings(inout reportFile as file)
3.2 InitializeAccumulators(out totreg, totovt,totpayrate,totgross,totfed,
totstate,totssi,totdefr, totnet as real)
3.3 InputEmployeeData(out lastname, firstname as string,
out hours, payrate, defr as real)
3.4 CalculateGross(in hours, payrate as real, out gross as real)
3.5 computeTaxes(in g,d as real, out ft, st, ssit as real)
3.5.1 cFed(in g,d as real, out fed as real)
3.5.2 cState(in ft as real,out state as real)
3.5.3 cSSI(in g,d as real, out ssi as real)
3.7 PrintSummaryReport( ......)
3.7.1 printTotals( ....)
3.7.2 printAverages( ....)

*/

#include <stdio.h>
#include "TAXRATES.h"

void InputEmployeeData(char *lastname,char *firstname, // 3.3
float *hours,float *payrate, float *defr);
void CalculateGross(float hours, float payrate, float * gross); //3.4
float CalculateGross(float hours,float payrate); //3.4
extern void computeTaxes(float g,float d,float * ft,float *st,float *ssit); //3.5

int main(void)
{
char ln[15+1];
char fn[10+1];
float fed,state,ssi;
float g,h,p,d,n;

InputEmployeeData(&ln[0],&fn[0],&h,&p,&d); // call 3.3
g = CalculateGross(h,p); // call 3.4
// vs
//CalculateGross(40.00,25.00,&g); // alternate call 3.4
computeTaxes(g,d,ADDR(fed),ADDR(state),ADDR(ssi)); // call 3.5
n = g-fed-state-ssi-d;
printf(" Fed = %8.2f\n",fed);
printf(" State = %8.2f\n",state);
printf(" SSI = %8.2f\n",ssi);
printf(" Net = %8.2f\n",n);
while(getchar() != '\n'); // flush(stdin)
return 0;
}

void CalculateGross(float hours, float payrate, float * gross) //3.4
{
if (hours <= 40)
*gross = hours * payrate;
else
*gross = 40* payrate + 1.5 * payrate * (hours-40);

}

float CalculateGross(float hours,float payrate) .. //3.4
{
if (hours <= 40)
return hours * payrate;
else
return 40* payrate + 1.5 * payrate * (hours-40);
}

void InputEmployeeData(char *lastname,char *firstname, // 3.3
float *hours,float *payrate, float *defr)
{
printf(" Enter the name ==> ");
scanf("%s%s",firstname,lastname);
printf(" Enter the hours and payrate ==> ");
scanf("%f%f",hours,payrate);
printf(" Enter the deferred earning amount ==> ");
scanf("%f",defr);
}

最佳答案

函数应该有输入和单个输出。虚空说做点什么。指针很棒,但目的是计算一些东西。当然,尽可能使用 f(x) = y,而不是 f(x, out y)。

关于c - void函数和float函数有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33049241/

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