#include<stdio.h>
#include<string.h>
#include<stdlib.h>typedefstructBank{structBank*this;intnum_customers;intrating;char*address;floatreserve_amt;void(*deposit)(structBank*,float);void(*withdraw)(structBank*,float);void(*change_address)(structBank*,char*);void(*customer_enter)(structBank*);void(*customer_exit)(structBank*);}Bank;voiddeposit(structBank*bank,floatamt);voidwithdraw(structBank*bank,floatamt);voidcustomer_enter(structBank*bank);voidcustomer_exit(structBank*bank);Bank*create_bank(char*address);intmain(){Bank*bank=create_bank("2424 Blackwater Street");bank->deposit(bank,15);bank->withdraw(bank,13);printf("The total is %f\n",bank->reserve_amt);}Bank*create_bank(char*address){Bank*b=calloc(1,sizeof(Bank));b->this=b;b->num_customers=0;b->rating=0;b->address=calloc(strlen(address)+1,1);memcpy(b->address,address,strlen(address)+1);b->reserve_amt=0;b->withdraw=withdraw;b->deposit=deposit;b->customer_enter=customer_enter;b->customer_exit=customer_exit;returnb;}voiddeposit(structBank*bank,floatamt){bank->reserve_amt+=amt;}voidwithdraw(structBank*bank,floatamt){bank->reserve_amt-=amt;}voidcustomer_enter(structBank*bank){return;}voidcustomer_exit(structBank*bank){return;}
Top comments (0)
Subscribe
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)