Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define pi 3.146
#define brakeFactor 0.7
double readVal (char *carModel,double *rSlope, double *sLength);
double calculateSpeed (double rSlope, double sLength);
double averageSpeed(double sLengthArray,double speedArray);
void dataSort(double sLengthArray,double rSlopeArray,double speedArray)
void listValues ()
int main ()
{
char option;
listValue (); /* calling module, not sure what to put for the arguments*/
while(option != d)
{
printf ("Please enter the letter of your chosen option.\n);
printf("a. Display the historical data\nb. Find the historical data for a specific car.\nc. Display the average speed.\nd. END");
scanf ("%c", &option);
if (option == a)
{
dataSort(double sLengthArray,double rSlopeArray,double speedArray)
printf ("|\n");
printf ("|\tHISTORICAL DATA FROM SPEEDING CARS\n");
printf ("|\tSkidlength\tRoadSlope\tSpeed\n");
for (i=1; i<=count; i++)
{
printf("|\t%.3lf\t\t%0.lf\t\t%.2lf\n", sLengthArray[i], rSlopeArray[i], speedArray[i]);
}
printf ("|\n");
}
if (option == b)
{
}
if (option == c)
{
double averageSpeed(sLengthArray, speedArray);
}
if (option == d)
{
printf("You have chosen to end the program");
break;
}
}
system ("pause");
return 0;
}
listValue () /* Called module,need to return the the arrays and sum and count for use in main*/
{
double slopeRad, slopeTangent, speedArray[200]={0}, sum=0, speed, sLength, *sLengthP, sLengthArray[200]={0},rSlope, *rSlopeP,rSlopeArray[200]={0};
char carModel[1000], carModelArray[200][1000],*carModelP;
int count=0, i;
carModelP=carModel;
sLengthP = &sLength;
rSlopeP = &rSlope;
while (sLength != 999)
{
readVal(carModel,&rSlope,&sLength);
if (sLength == 999)
{
break;
}
else
{
speed = calculateSpeed(rSlope,sLength);
sum = sum + speed;
count = count + 1;
for (i=0;i<count;i++)
{
sLengthArray[count]= sLength;
rSlopeArray[count]= rSlope;
strcpy(carModelArray[count],carModel);
speedArray[count]= speed;
}
}
}
printf ("|\n");
printf ("|\tHISTORICAL DATA FROM SPEEDING CARS\n");
printf ("|\tSkidlength\tRoadSlope\tSpeed\n");
for (i=1; i<=count; i++)
{
printf("|\t%.3lf\t\t%0.lf\t\t%.2lf\n", sLengthArray[i], rSlopeArray[i], speedArray[i]);
}
printf ("|\n");
}
double readVal (char *carModel,double *rSlope, double *sLength)
{
double all [300];
int i;
printf ("Please enter the car model.\n");
scanf ("%s", carModel);
do
{
printf ("Please enter a skid length.If 999 is entered, no calculations will be done.\n");
scanf ("%lf", sLength);
}
while(sLength <0);
do
{
printf ("Please enter a road slope between -30 and 30.\n");
scanf ("%lf",rSlope);
}
while (*rSlope<-30||*rSlope>30);
}
double calculateSpeed (double rSlope, double sLength)
{
double slopeRad, slopeTangent, speed;
slopeRad = rSlope*(pi/180);
slopeTangent= sin(slopeRad)/cos(slopeRad);
speed = sqrt(30*sLength*(slopeTangent + brakeFactor));
return speed;
}