/*******************************Libraries********************************/
#include <iostream.h>
#include<stdlib.h>
#include <math.h>
/************************************************************************/
/***************************Function Prototype***************************/
void speed(double []);
void light(double []);
double leaving();
/************************************************************************/
/*******************************Main Program*****************************/
void main()
{
//opens main programdouble Velocity[10];
speed(Velocity);
for (int k = 1;k<=10;k++)
{
//opens for loopcout << Velocity[k]<<endl;
}
//closes looplight(Velocity);
}
//ends main program/************************************************************************/
/******************************Function Speed****************************/
void speed(double Avg[])
{
//opens function//Variables
double time_interval=0.1;
double acceleration=10.0;
float S[50];
float x[50];
float time[50];
int j= 3;
S[0]=0.0;
Avg[0]=0.0;
x[0]=0.0;
time[0]=0.0;
for (int n=1; n<=j; n++)
{
//opens looptime[n]= time[n-1] + time_interval;
S[n]=time[n]*acceleration;
Avg[n]= (S[n]+S[n-1])/2.0;
x[n]=time_interval*Avg[n]+x[n-1];
cout<<n<<" "<<time[n]<<" "<<S[n]<<" "<<Avg[n]<<" "<<x[n]<<endl;
}
//ends loop}
//ends function/**********************************************************************/
/****************************Function Light****************************/
void light(double V[])
{
//opens functiondouble c;
//the rate of the cars leaving the lightdouble v2;
//velocity of cars leaving S.L.double x;
//distance between front bumpers of cars entering S.L.double d;
//distance between front bumpers of cars leaving S.L.double t;
//time the light is greendouble c1;
//The rate of cars arriving at the lightint i,j;
double speed2;
//Speed of cars leaving in mphdouble w;
//The exponetial function for the lightdouble z;
//the number of cars at the lightint count=0;
c = 1.0;
for( j=1; j<11; j++)
{
//opens loopcout<<"Velocity equals "<<V[j]<<" "<<"ft/sec"<<endl;
x=50.0;
cout<<endl;
c1=V[j]/x;
cout<<"The rate of cars entering is "<<c1<<" cars/sec"<<endl;
cout<<endl;
//Allows for random speeds to be read into the program
speed2=leaving();
//Changes speed to feet per second
v2=(speed2*5280.0)/3600.0;
//converts mph to ft/seccout<<"The velocity of the cars leaving is "<<v2<<" ft/sec"<<endl;
count++;
cout<<"Count = "<<count<<endl;
d=60.0;
cout<<endl;
t=1;
w=((V[j]/x)-(v2/d));
cout<<"w equals "<<w<<endl;
for( i=0; i<=8; i++)
{
//opens loopif (c!=0.0)
{
//Opens the if statementc=c1-(c1*(pow(2.718281828,(w*t))));
z=c1-c;
cout<<"At light "<<c<<" "<<"Leaving "<<z<<endl;
cout<<"The length of the green light was "<<t<<" sec"<<endl;
cout<<endl;
t=t++;
}
//Closes the if statement}
//ends loop}
// Ends first for loop}
//ends function
/********************************************************************/
//function to find the speed2 -- speed of car leaving stop sign
/********************************************************************/
double leaving()
{
//opens functionconst double a=5.0;
const double b=20.0;
double xx;
xx=a+double(rand())*((b-a)/RAND_MAX);
cout <<"speed2 = "<<xx<<" mph"<<endl;
return(xx);
}
//ends function