In C language
make a structure called funds
funds should have variable fields of type int id; char bank[10]; float balance;
The program would have a function called sum which returns a float. To sum pass structure funds and a pointer called record.
initialize record to equal {1, "BOA", 10023.43} call sum passing the pointer record , the function returns a float value into variable result.
initialize record to equal {2, "Chase", 4239.87} call sum passing the pointer record ,
the function returns a float value into variable result. The sum( ) function has a pointer record to a funds structure.
This function has access to the & operator to get the structure address. Passing the address to the function causes the pointer record to point to the structure funds. In the function use the -> operator to gain the balance values. The function should have an static variable called total to keep a running sum of balance and return the variable total float value. Main program should produce with one statement one line the output “Customer has a total of $5263.30.” Advance one line.
#include <stdio.h>
/* declared funds structure */
typedef struct funds
{
int id;
char bank[10];
float balance;
}funds;
/*sum function that recieves address of funds structure as argument and return float */
float sum(funds *record)
{
static float sum = 0; //static variable sum, its valuw will be persisted between function calls
sum += record->balance; /* access balance using -> operator */
return sum;
}
int main()
{
float sumBalance;
funds record1 = {1,"BOA",1023.43}; /* declared record1 and passed its address to sum function */
sumBalance = sum(&record1);
funds record2 = {2,"Chase",4239.87}; /* declared record2 and passed its address to sum function */
sumBalance = sum(&record2);
printf("Customer has a total of $%.2f.\n",sumBalance); /* print sum on cconsole */
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.