Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In a file named account.c implement all of the functions declared in the account.h file. It's important that you understand everything in account.h , so

In a file named account.c implement all of the functions declared in the account.h file. It's important that you understand everything in account.h, so if there is anything in it that you don't understand, look it up. Make sure that your account.c file works with the following file (main1.c) and produces the output shown below.
All amounts and balances should be positive. Amounts for withdrawals should not be greater than the account balance, and amounts for transfers should not be greater than the balance of the source account. If any of these constraints are violated then the transaction should not be executed and the function should return a negative integer as its return value.
The only function that should print anything is account_print.
Use a command line like this to compile your program:
gcc -o main1 main1.c account.c
That command line tells the compiler to compile main1.c and account.c and to make an executable file named main1.
account.h
#include
#define MAX_NAME_LEN (100)
typedef struct {
int id;
int balance;
char owner[MAX_NAME_LEN]; // USED FOR A STRING
} Account;
int account_init(Account *acct_p, int id, int balance, char *owner);
int account_deposit(Account *acct_p, int amount);
int account_withdraw(Account *acct_p, int amount);
int account_transfer(Account *from_p, Account *to_p, int amount);
int account_print(Account *acct_p);
Link to download file: account.hDownload account.h
main1.c
#include
#include "account.h"
int main(int argc, char *argv[]){
Account a1, a2;
account_init(&a1,1,1000, "Hermione Granger");
account_init(&a2,2,500, "Jack Swallow");
account_deposit(&a1,500);
account_withdraw(&a2,50);
account_withdraw(&a1,100);
account_transfer(&a2, &a1,25);
account_print(&a1);
account_print(&a2);
}
Link to download file: main1.cDownload main1.c
Output
In the output below, the dollar sign represents the shell prompt and the name of the executable file is main1
$ ./main1
1 Hermione Granger $1425
2 Jack Swallow $425

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Distinguish between recruitment sources and recruitment methods.

Answered: 1 week ago

Question

How has social media emerged as an important force in recruiting?

Answered: 1 week ago

Question

5.5 Summarize external recruitment methods.

Answered: 1 week ago