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;...
C++ 1a) Assume that you have an integer variable named myint. Call xyzfunc and pass myint...
C++ 1a) Assume that you have an integer variable named myint. Call xyzfunc and pass myint as a parameter. a) xyzfunc(myint) b) myint(xyzfunc) c) xyzfunc(&myint) c) call xyzfunc(myint) 1b) Code the function definition for xyzfunc, picking up a local copy of myint. xyzfunc has no return value. a) void xyzfunc (int &myint); b) void xyzfunc (myint); c) void xyzfunc (local myint); d) void xyzfunc (int myint); 1c) If xyzfunc executes myint++, what happens to the copy of myint in the...
C++ 5a)We have the following class: class Banana { private:      string s;      int y;...
C++ 5a)We have the following class: class Banana { private:      string s;      int y; public: bool theMemberFunc (string); void setterForS(string); // setter for s string getterForS(); // getter for s }; Instantiate a static object of Banana named co. a)int Banana; b)co.Banana = new; c)Banana = new class; d)Banana co; 5b)Code a call to function aNonclassFunction passing co. a)aNonclassFunction (co); b)aNonclassFunction (* co); c)aNonclassFunction (aGoodClass.co); d)aNonclassFunction (aGoodClass); 5c)Code the function definition for aNonclassFunction, picking up co. aNonclassFunction has...
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...
Write in C++. Define a class called Text whose objects store lists of words. The class...
Write in C++. Define a class called Text whose objects store lists of words. The class Text will be just like the class StringVar except that the class Text will use a dy- namic array with base type StringVar rather than base type char and will mark the end of the array with a StringVar object consisting of a single blank, rather than using '\0' as the end marker. Intuitively, an object of the class Text represents some text consisting...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT