Question
Warm up exerciseswe will discuss the following Linking a libarary into a Visual Sydio Project (must use VS 2010 or 2015) Use of && and
Warm up exerciseswe will discuss the following
Linking a libarary into a Visual Sydio Project (must use VS 2010 or 2015)
Use of && and ||
? : operator
struct
define a structure for student records. fields you needname, id, gpa, major
assign data to this derived data type struct student using dot operator
declare struct student pointer and assign the address of a structure to the pointer
declare an array of 10 struct students
write a function which is passed an array of struct student and the size of the array and computes the average GPA of all the students
write a function which is passed an array of struct student and the size of the array and computes the average GPA of all students with the major ECE
Lab 10 (this is to be turned in)
You need to download the following
Lab10.c,
Lab10_main.c and
Lab10.h.
In this lab we will have 3 files, lab10.c, lab10_main.c and lab10.h. All your work will be done in the lab10_main.c, you don't need to modify lab10.h and lab10.c. The program consists of two array list[], this is an array of char pointers and STRList[] 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
Name Here^2134^IN^317^3411122^245.67
You are to write two functions
ComputeAverageListBalance and SortListByBalance that will operate on the list []
double computeAverageListBalance(char *list[], int listsize);
void sortListByBalance(char * list[], int listsize);
Each array elements in the array STRList have the following format :
struct cellData{
char Name[50];
char account[5];
char state[3];
char areaCode[4];
char mobileNumber[8];
double balance;
}
The account number is unique and it is 3 or 4 digits, the state is a two character abbreviation, the area code is 3 digits, the mobile number is 7 digits and the balance is a floating value
In this part of the your program you are asked to calculate the average of the balances and to sort based on the balance, compute average balance of all accounts with a 317 area code
You should declare and define the following functions :
double computeAverageBalance(struct cellData list[], int listsize);
void sortByBalance(struct cellData list[], int listsize);
double computeAverageBalance_with_317(struct cellData list[], int listsize);
Your main (it is provided to you) should look like this
int main()
{
struct cellData list[25]={NULL};
int seed=715;
int i,listsize;
listsize= generate_list(list, seed);//I wrote in lab9.c generates random strings
printf(" original list *************** ");
for(i=0;i< listsize; i++)
printf("%s ",list[i]);
printf(" sort by balance *************** ");");
sortByBalance(list, listsize);
for(i=0;i< listsize; i++)
printf("%s ",list[i]);
printf(" ");
printf("the average balance is %.2lf \m", computeAverageBalance(list, listsize));
printf(" sort by Account Number *************** ");");
sortByAccountNumber(list, listsize);
for(i=0;i< listsize; i++)
printf("%s ",list[i]);
printf(" ");
quit(list, listsize); //I wrote in lab9.c ignore but needed
}
The function generate_list will generate a random list of size listsize (which is <=25). This is written for you in lab9.c
You need to write your functions (they have a shell of the function) in lab9.c
Given Files:
lab10.h :
#include
#include
#include
#ifndef _TEN_
#define _TEN_
struct cellData{
char Name[50];
char account[5];
char state[3];
char areaCode[4];
char mobileNumber[8];
double balance;
};
#endif
int generate_Structlist(struct cellData* list, int K);
void Structquit(struct cellData* list, int listsize);
int generate_list(char ** list, int K);
void quit(char ** list, int listsize);
lab10.c:
#include
#include "lab10.h"
#define NUMBER_NAME 25
#define UNOCCUPIED 0
char *name_source[]={"Horace Greeley", "Sigourney Weaver", "Wendy Morse", "Cora Simmons", "Phil Donahue", "Dan Crane", "Willie Daniels", "Carl Lewis","Joe Crabb", "Buster Keaton", "Dawn Harris", "Rene Williamson", "Pat Lane", "Jose Richards", "Edward Morris", "Nathan Nevins", "John Doe", "Jane Eyre", "Wednesday Adams", "Annette Wendt", "Yannick Noah", "Christopher Columbus", "George Sims", "Anna Washington", "Marie Curie", "Rhonda White", "Susan Nash", "Mary Wright", "Lily Langely","John Thompson", "Ray Reynolds"};
char *acct_source[]={"122", "3431", "1234", "613", "4112", "122", "245", "908","1091", "1092", "1090", "100", "344", "688", "1331", "5678", "8777", "3344", "2222", "3056" , "900", "4021", "9001", "1059", "8771", "9883", "4447", "2332","5555", "1111"};
char *state[]={ "IN", "IL", "NY", "MD", "NC", "VA", "NJ"};
char * mobile_number_source[]={ "2113344", "6889999", "9781234", "4445555", "2345678", "3121131", "3121131","3121131", "3121101","9121131","3121131", "3121131","4321131","3189001","9121131","3121131", "3121131","3121131","8121101","4121131","5121131", "6421131","2521131","2031101","1021131" };
char * area_code[]={ "317","345", "214", "711", "812", "753", "721", "616", "154", "393", "186", "277"};
char * balance[]={ "832.45","100.13", "650.34", "394", "802.3", "71.4", "7.4", "6.80", "59.45", "93.22", "86.67", "77.23"};
int acct_position[NUMBER_NAME]={UNOCCUPIED};
int name_position[NUMBER_NAME]={UNOCCUPIED};
int mobile_number_position[NUMBER_NAME]={UNOCCUPIED};
int generate_list(char ** list, int K)
{
char buffer[300];
int j,i,listsize;
srand(K);
listsize = rand()%10 +16;
for(i=0;i< listsize; i++)
{
memset(buffer, 0, 200);
j=rand()%25;
while(name_position[j]!= UNOCCUPIED)
j=rand()%25;
name_position[j]++;
strcpy(buffer, name_source[j]);
strcat(buffer, "^");
j=rand()%25;
while(acct_position[j]!= UNOCCUPIED)
j=rand()%25;
acct_position[j]++;
strcat(buffer, acct_source[j]);
strcat(buffer, "^");
j=rand()%7;
strcat(buffer, state[j]);
strcat(buffer, "^");
j=rand()%12;
strcat(buffer, area_code[j]);
strcat(buffer, "^");
j=rand()%25;
while(mobile_number_position[j]!= UNOCCUPIED)
j=rand()%25;
mobile_number_position[j]++;
strcat(buffer, mobile_number_source[j]);
strcat(buffer, "^");
j=rand()%12;
strcat(buffer, balance[j]);
list[i]=(char *)malloc(strlen(buffer)+5);
strcpy(list[i], buffer);
}
return listsize;
}
int generate_Structlist(struct cellData* list, int K)
{
char buffer[300];
int j,i,listsize;
srand(K);
memset(acct_position, 0, sizeof(int)*NUMBER_NAME);
memset(name_position, 0, sizeof(int)*NUMBER_NAME);
memset(mobile_number_position, 0, sizeof(int)*NUMBER_NAME);
listsize = rand()%10 +16;
for(i=0;i< listsize; i++)
{
j=rand()%25;
while(name_position[j]!= UNOCCUPIED)
j=rand()%25;
name_position[j]++;
strcpy (list[i].Name, name_source[j]);
j=rand()%25;
while(acct_position[j]!= UNOCCUPIED)
j=rand()%25;
acct_position[j]++;
strcpy(list[i].account, acct_source[j]);
j=rand()%7;
strcpy(list[i].state , state[j]);
j=rand()%12;
strcpy(list[i].areaCode, area_code[j]);
j=rand()%25;
while(mobile_number_position[j]!= UNOCCUPIED)
j=rand()%25;
mobile_number_position[j]++;
strcpy(list[i].mobileNumber, mobile_number_source[j]);
j=rand()%12;
list[i].balance=atof(balance[j]);
}
return listsize;
}
void quit(char ** list, int K)
{
int i;
for(i=0; i< K;i++)
free(list[i]);
}
lab10_main.c:
#include
#include
#include
#include "lab10.h"
double computeAverageBalance(struct cellData list[], int listsize);
void sortByBalance(struct cellData list[], int listsize);
double computeAverageListBalance(char *list[], int listsize);
void sortListByBalance(char * list[], int listsize);
/*
The program consists of an array list[], this array is an array of pointers which points to strings.
Each string has the following format :
Name^Account Number^STATE^Area Code^Mobile Number^Balance
Example
Name Here^2134^IN^317^3411122^245.67
Remember everything is stored as a string.
The information conveyed concerning: the account number is unique and it is 3 or 4 digits, the state is a two character abbreviation, the area code is 3 digits, the mobile number is 7 digits and the balance is a floating value
*/
int main()
{
char * list[25]={NULL};
struct cellData STRlist[25]={0};
int seed=715;
int i,listsize;
listsize= generate_list(list, seed);
printf(" original list *************** ");
for(i=0;i< listsize; i++)
printf("%s ",list[i]);
printf(" ");
sortListByBalance(list, listsize);
for(i=0;i< listsize; i++)
printf("%s ",list[i]);
printf(" ");
printf("the average balance is %.2lf ", computeAverageListBalance(list, listsize));
quit(list, listsize);
listsize= generate_Structlist(STRlist, seed);
printf(" original list *************** ");
for(i=0;i< listsize; i++)
printf("%24s %5s %2s %3s %7s %7.2lf ",STRlist[i].Name, STRlist[i].account, STRlist[i].state, STRlist[i].areaCode, STRlist[i].mobileNumber, STRlist[i].balance );
printf(" ");
//sort by cell data balance
sortByBalance(STRlist, listsize);
for(i=0;i< listsize; i++)
printf("%24s %5s %2s %3s %7s %7.2lf ",STRlist[i].Name, STRlist[i].account, STRlist[i].state, STRlist[i].areaCode, STRlist[i].mobileNumber, STRlist[i].balance );
printf(" ");
printf("the average balance is %.2lf ", computeAverageBalance(STRlist, listsize));
}
double computeAverageBalance(struct cellData ARlist[], int listsize)
{
return -1.0;
}
void sortByBalance(struct cellData ARlist[], int listsize)
{
}
double computeAverageListBalance(char *list[], int listsize)
{
return -1.0;
}
void sortListByBalance(char * list[], int listsize)
{
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started