Program in C use pointers not array notation int clean_data(int *id, double *amt
ID: 3826519 • Letter: P
Question
Program in C
use pointers not array notation
int clean_data(int *id, double *amt, char *desig, int *idClean, double *amtClean, char *desigClean, int Size):
int * - pointer containing original all account IDs information
double * - pointer containing original all amounts information
char* - pointer containing original all designation information
int * - pointer to hold the valid account IDs information
double * - pointer to hold the corresponding valid amounts information
char * - pointer to hold the corresponding valid designation information.
int – original size
returns int – count of the valid number of IDs.
All the records which conform to the criteria specified by the CS department must be used to fill the second set of int*, double* and char* pointers and then at the end return the count of such valid rows.
In this function, you will loop through the original records and find all those which match the criteria specified and then copy them over to the new set of valid pointers. To do this you should check if each account number is a palindrome (call check_palindrome function on each original ID) and if the corresponding amount value is exactly between $500 and $5000.00 inclusive and the corresponding designation is anything other than P, if these matches then copy that TAs information into the new set of pointers correspondingly and at the end return how many such valid records were copied over. One of the major problems you will run across is indexing, remember that the new valid pointers should start from 0 and must be incremented after every time a new record is added.
Explanation / Answer
ANSWER:
As "original size" is one of the parameter given we can have three arrays:
1.Array of original account ids (size - original size)
2. Array of original amount ids (size - original size)
3. Array of original designations (size - original size)
We can create a list of valid accountids, valid amounts and valid designations as follows:
bool check_palindrome(int accid) {
int rev, rem;
while (accid != 0){
rem = accid % 10;
rev = rev * 10 + rem;
accid = accid/10;
}
if (accid == rev){
return true;
}
else {
return false;
}
}
int clean_data(int occids, double oamnts, char odesg, int vaccids, double vamnts, char vdesg, int orgsize){
int p1, p2, i, valid_count;
double q1, q2;
char r1, r2;
p1 = occids;
q1 = oamnts;
r1 = odesg;
vaccids = (int )malloc(sizeof(int) orgsize);
vamnts = (double )malloc(sizeof(double) orgsize);
vdesg = (char )malloc(sizeof(char) orgsize);
p2 = vaccids;
q2 = vamnts;
r2 = vdesg;
valid_count = 0;
for (i = 0; i<orgsize; i++){
if (check_palidrome(*p1) && (q1 >= 500 && q1 <= 5000) && *r1 != 'P'){
p2 = p1;
q2 = q1;
r2 = r1;
p2++;
q2++;
r2++;
valid_count++;
}
p1++;
q1++;
r1++;
}
return valid_count;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.