Question

In C language make a structure called funds funds should have variable fields of type int...

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.

Homework Answers

Answer #1
#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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
A. Write C code to create a structure called time_of_day, which stores the current time in...
A. Write C code to create a structure called time_of_day, which stores the current time in hours, minutes, and seconds. All the fields should be integers except for seconds, which should be a floating point value. B. Write a C function called check_time, which takes a pointer to a time_of_day structure as input, and return 1 if the time is valid (0 to 23 hours, 0 to 59 minutes, 0 to 59.999999 seconds) and 0 otherwise. Assume that times are...
IntNode class I am providing the IntNode class you are required to use. Place this class...
IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined inline (within the class declaration). Do not write any other functions for the IntNode class. Use as is. struct IntNode { int data; IntNode *next;...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
Problem: Our Armstrong number Please write code for C language So far we have worked on...
Problem: Our Armstrong number Please write code for C language So far we have worked on obtaining individual digits from 4 digits or 5 digit numbers. Then added them to find the sum of digits in various examples and assignments. However, the process of extracting individual digits is actually can be solved using a loop as you were doing a repetitive task by using mod operation and division operation. Now, we know how loops work and we can remove the...
Need in C language also need full documentation/explanation of each line A student has established the...
Need in C language also need full documentation/explanation of each line A student has established the following monthly budget: Budget Categories Budgeted amount ----------------------------------------------------- Housing $ 580.00 Utilities $ 150.00 Household Expenses     $ 65.00 Transportation $ 50.00 Food $ 250.00 Medical $ 30.00 Insurance $ 100.00 Entertainment $ 150.00 Clothing $ 75.00 Miscellaneous $ 50.00 ---------------------------------------------------- Write a program that declares a MonthlyBudget structure designed with member variables to hold each of these expense categories. The program should define...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features...
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features the design of a calculator program using pseudocode and a Python program that uses a list and functions with variable scope to add, subtract, multiply, and divide. Open the M4Lab1ii.py program in IDLE and save it as M4Lab1ii.py with your initials instead of ii. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called keys with other objects called values. It is implemented as a Java class that uses arrays internally. 1. Theory. A map is a set of key-value pairs. Each key is said to be associated with its corresponding value, so there is at most one pair in the set with a given key. You can perform the following operations on maps. You can test if...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT