-
A challenge program
Any expert can do this difficult question?
You have joined a small software company as a junior programmer. The company mainly takes in software development jobs for small and medium enterprises. A charity body has
contracted the company to develop a system that handles donor relations. Part of the system is on keeping donation records of the donors for promotional and marketing purposes.
You are given the task of designing and implementing a component for keeping donation records. Your component will receive and supply data to other components; therefore you
spent a lot of time liaising with other programmers on their requirements. The following lists the functionality required of your component.
* Records a donation record.
* Gets the total amount of donation made by a donor.
* Gets the number of donations made by a donor.
* Gets the top five donors in the amount of donation made.
* Prints the donor list in an order of amount of donation made.
You have decided to design an Abstract Data Type for keeping donation records. Your task
now is to implement the functions for the ADT.
Data Part
The following shows the declaration of data structures for the ADT.
Code:
#define MAX_DONORS 256
struct donorrecord {
char name[256]; /* name of donor */
float totalAmount; /* total amount of donation made */
int frequency; /* total number of donation made */ };
typedef struct donorrecord DonorRecord;
struct donationrecord {
DonorRecord donor[MAX_DONORS]; /* an array of donor records */
int count; /* number of donor records actually used */ };
typedef struct donationrecord DonationRecord;
Implement the following ADT functions for the Donation Record ADT.
Code:
/* This function adds the given donation record to the ADT */
void addDonation(DonationRecord* drecord, char* name, float amount);
/* This function returns the total amount of donation made by donor
name */
float getDonationAmount(DonationRecord* drecord, char* name);
/* This function saves all the donation records in the ADT to the given
filename */
/* Returns 1 if successful, 0 if failed */
int saveDonationRecord(DonationRecord* drecord, char* filename);
/* This function loads all the donation records in the ADT from the
given filename */
/* Returns 1 if successful, 0 if failed */
int loadDonationRecord(DonationRecord* drecord, char* filename);
/* This function returns the donor record whose donation amount is
at the top */
DonorRecord* getTopDonor(DonationRecord* drecord);
/* This function sorts the donation records using the given order on
the total donation amount in ascending order */
void sortDonationRecord(DonationRecord* drecord, int order);
-
>Any expert can do this difficult question?
It isn't a difficult problem, but yes, I'm fully capable of solving it.
-
here is what I probably would do, I would have a Linked list of donors, and each one of them would have a field which points a list of donations, each donation would be a structure, telling the amount and any other necessary information, then it is just simple algorithms.
-
can someone show me how to solve the question...
thk a lot..
-
You do know how to loop through an array don't you? That's all you need for this program, a for loop. This entire program can be solved with only for loops. It's nothing complex.
Oh, by the way, no, no one here will do your program for you. You have made no effort. Read the nice little Announcements at the top of the board.
Now read them again.
Quzah.