Fix this code, answer code text & upload output, pointer p, intialize arrays, follow directions #include #include int ma

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Fix this code, answer code text & upload output, pointer p, intialize arrays, follow directions #include #include int ma

Post by answerhappygod »

Fix this code, answer code text & upload output,
pointer p, intialize arrays, follow directions
#include
#include
int main( )
{
int *p;
typedef struct funds
{
int id;
char bank[10];
float balance;
}fund;
float sum(fund *);
int cust()
{
fund record1 = {1, "BOA ", $1023.43}; /*char values
would need to be converted to integer or float for structure
fields*/
fund record2 = {2, "Chase ", $4239.87};
float s;
s = sum(&record1);
s = sum(&record2);
printf("Customer has a total of $
%0.2f",s);
return 0;
}
float sum(fund *record)
{
static float total;
total = total + record->balance;
return total;
}
int cust[6] = { 0, 1023.43, 4239.87,
0, 0, 0 } ;
p =
&cust[0];
for ( int i = 0 ; i<6 ; i++
)
{
printf("cust[%d]:
balance is %d and address is %p\n", i, *p, p);
p++;
}
return 0;
}
float data type so it retains its value between functions
declare pointer variable p
Make a structure called funds with
these variable fields and data types: int id;
char bank[10];
float balance;

The program has a function
called sum without a return
statement. record is a pointer to
the funds structure.

Program’s function main is to
Declare and initialize
char type array called cust with data
{“1”, "BOA", “1023.43, “2”, "Chase", “4239.87”}
Initialize record fields to equal using pointer to array values
the values of cust[0] cust[1] cust[2]

Then call sum pass using a unary operator the
memory address of record, the function keeps
cumulative sum of all balance as float data type in local variable
total.

Initialize record fields to equal using pointer to
array values the values of cust[3] cust[4] cust[5]

Then call sum pass using a unary operator the
memory address of record, the function keeps
cumulative sum of all balance as float data type in local variable
total.
In function main produce with one statement one line the output
“Customer has a total balance of $5,263.30.” The total
balance is referenced by the pointer p and not hard coded.
Make sure currency uses the USD symbol $ comma two decimal places
format. Advance one line.
The sum function receives as a pointer
record to funds structure. Thus,
passing the memory address of record from main to function sum
causes the pointer record in sum to point to the
funds structure. In the sum function
use the -> operator to gain the
balance values.
The function should have float data type variable called
total to retain a “running sum of balance” and
variable p which holds the memory address of
total. Assign value of total to pointer p. Use pointer p to make
the value of total known in main.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply