C++ program Here are some guidance for the lab This is Lab10_main.c ?? This is l
ID: 3706256 • Letter: C
Question
C++ programHere are some guidance for the lab
This is Lab10_main.c ?? This is lab10.h
This is lab10.c
Page of 3 Lab 10 (this is to be turned in) You need to download the following Lab10 main.e and Lab10.h. In this lab we will have 3 files, lab10.c, lab10_main.e and lab10.h. All your work will be done in the lab 10-main.c, you don't need to modify lab 10.h and labi 0.?. The program consists of two array listll, this is an array of char pointers and STRListl this array is an array of struct cellData. Each char pointer is list points to a string of the form Name Account Number STATE Area Code Mobile Number Balance" Example "Brian King 2134 INA3173411122 245.67 You are to write two functions ComputeA verageListBalance and SortListBy Balance that will operate on the list D double computeAverageListBalance(char "listll, int listsize) void sortListByBalance(char listl, int listsize); 20
Explanation / Answer
double computeAverageListBalance(char *list[],int listsize){
double sum = 0;
for (int i = 0; i<listsize; i++){
char *ch;
ch = strtok(list[i],"^");
for (int j = 0; j<4; j++)
ch = strtok(NULL,"^");
double bal = atof(ch);
sum = sum + bal;
}
return sum/listsize;
}
void sortListByBalance(char *list[], int listsize){
for (int i = 0; i<listsize; i++){
char *ch;
ch = strtok(list[i],"^");
for (int k = 0; k<4; k++)
ch = strtok(NULL,"^");
double bal1 = atof(ch);
for (int j = i+1; j<listsize; j++){
ch = strtok(list[j],"^");
for (int k = 0; k<4; k++)
ch = strtok(NULL,"^");
double bal2 = atof(ch);
if (bal1 > bal2){
char *p = list[i];
list[i] = list[j];
list[j] = p;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.