im supposed to build a simple traffic control program.. i'm done but i kno its full of errors it runs but not the results i want.. can someone please help me implement some pointers or string manipulation into the code.. i'm having problems with that.. the code is completely commented, so you may get an idea of the results desired
// A program to control the flow of traffic between two streets
// Juice
// Traffic Control v1 29-10-2013
#include <iostream>
#include <cstring> // to do string manipulations
usingnamespace std;
void streetsA();
void streetsB();
void lanesA();
void lanesB();
// using array to represent streets and lanes
string streetA [1] [2] = {"StreetALane1", "StreetALane2"};
string streetB [1] [2] = {"StreetBLane1", "StreetBLane2"};
string laneA [1] [2]= {"LaneAL1", "LaneALane2"};
string laneB [1] [2] = {"LaneBLane1", "LaneBLane2"};
int main()
{
// variable declaration
int approach;
// the for loop to represent two drivers to test program
for (int car = 2; car < 3; car++)
{
// do loop to get the driver experience
do
{
// Streets and Lanes
cout << "1. STREET A\n";
cout << "2. STREET B\n";
cout << "3. LANE A\n";
cout << "4. LANE B\n";
do
{
// driver chooses the street route before intersection
cout << " Choose Street Or Lane To Approach Intersection: ";
cin >> approach;
cout << "\n\n\n";
} // end do
while (approach <1 || approach >4);
// switch statement to choose which from street A or B and Lane A or B driver will be approaching intersection
switch (approach)
{
case 1:
//flash yellow light to indicate that driver should slow down as he approches intersection
cout << "\t\t\t\tYellow Light\n\n\n\n\n";
streetsA();
break;
case 2:
cout << "\t\t\t\tYellow Light\n\n\n\n\n";
streetsB();
break;
case 3:
cout << "\t\t\t\tYellow Light\n\n\n\n\n";
lanesA();
break;
case 4:
cout << "\t\t\t\tYellow Light\n\n\n\n\n";
lanesB();
break;
} // end switch
} // end do
while(approach == car);
} // end for loop
return 0;
} // end main
// operations of streetA
void streetsA()
{
// variable declaration
int lane;
// streets and lanes driver can take from position
cout << "1." << streetA[1][1] << "\n";
cout << "2." << streetB[1][1] << "\n";
cout << "3." << laneA[1][1] << "\n";
cout << "4." << laneB[1][1] << "\n";
// driver is at intersection
cout << "\n\t\t\t\tRed Light\n\n\n\n\n";
cout << "Choose route Desired: ";
cin >> lane;
cout << "\n\n";
// switch statement for driver route options
switch (lane)
{
case 1:
//make lane clear from streetA lane1 to streetB lane2
streetA[0][1] = streetB[1][1];
// if lane is clear flash green light, if not flash red light
if(streetA[0][1] == streetB[1][1])
{ cout << "\t\t\t\tGreen Light\n"; }
else cout << "Red Light\n";
// stop all other traffic that can possibly go to streetB lane2
if(laneB[0][1] == streetB[1][1])
{ cout << "\t\t\t\tRed Light\n"; }
break;
case 2:
streetA[0][1] = laneA[1][1];
if (streetA[0][1] == laneA[1][1])
{ cout << "\t\t\t\tGreen Light\n"; }
else cout << "Red Light\n";
if (streetB[0][1] == laneA[1][1] || laneB[0][1] == laneA[1][1])
{ cout << "\t\t\t\tRed Light\n"; }
break;
case 3:
streetA[0][1] = laneB[1][1];
if (streetA[0][1]== laneB[1][1] )
{ cout << "\t\t\t\tGreen Light\n"; }
else cout << "Red Light\n";
if(streetB[0][1] == laneB[1][1])
{ cout << "\t\t\t\tRed Light\n"; }
break;
} // end switch
} // end member function streetsA
// operations of streetB
void streetsB()
{
// variable declaration
int lane;
// driver has to stop before taking a route
cout << "\t\t\t\tRed Light\n\n";
// streets and lanes driver can take from position
cout << "1." << streetA[1][1] << "\n";
cout << "2." << laneA[1][1] << "\n";
cout << "3." << laneB[1][1] << "\n\n";
cout << "Choose route Desired\n\n";
cin >> lane;
// switch statement to show driver route options
switch (lane)
{
case 1:
// make lane clear from streetB lane1 to streetA lane2
streetB[0][1] = streetA[1][1];
// if lane is clear flash green light, if not flash red light
if(streetB[0][1] == streetA[1][1])
{ cout << "\t\t\t\tGreen Light\n"; }
else cout << "\t\t\t\tRed Light\n";
//stop all other traffic that can possibly go to streetA lane2
if(laneB[0][1] == streetA[1][1])
{ cout << "Red Light\n"; }
break;
case 2:
streetB[0][1] = laneA[1][1];
if (streetB[0][1] == laneA[1][1])
{ cout << "\t\t\t\tGreenLight\n"; }
else cout << "\t\t\t\tRed Light\n";
if(streetA[0][1] == laneA[1][1])
{ cout << "Red Light\n"; }
break;
case 3:
streetB[0][1] = laneB[1][1];
if (streetB[0][1] == laneB[1][1])
{ cout << "\t\t\t\tGreen Light\n"; }
else cout << "\t\t\t\tRed Light\n";
if(streetA[0][1] == laneB[1][1])
{ cout << "Red Light\n"; }
break;
} // end switch
} // end member funtion streetsB
// operations of laneA
void lanesA()
{
// driver has to stop before taking a route
cout << "\t\t\t\tRed Light\n\n";
// make lane from laneA lane1 to streetB lane2 clear
laneA[0][1] = streetB[1][1];
// if lane is clear flash Greenlight if not flash red light
if (laneA[0][1] == streetB[1][1])
{ cout << "\t\t\t\tGreen Light\n"; }
else cout << "\t\t\t\tRed Light\n";
// stop all other traffic leading to streetB lane2
if (streetA[0][1] == streetB[1][1] || laneB[0][1] == streetB[1][1])
{ cout << "Red Light\n"; }
} // end memberfuntion lanesA
// operations of laneB
void lanesB()
{
// variable declaration
int lane;
cout << "\t\t\t\tRed Light\n\n\n\n\n"; // driver is at intersection
cout << "1." << streetsA[1][1] << "\n";
cout << "2." << streetB[1][1] << "\n";
// driver chooses route desired
cout << "Choose Route Desired: ";
cin >> lane;
// switch statement to show driver route options
switch(lane)
{
case 1:
// make lane clear from laneB lane1 to streeA lane2
laneB[0][1] = streetA[1][1];
// if lane is clear flash Green Light, if not flash red light
if (laneB[0][1] == streetA[1][1])
{ cout << "Green Light\n"; }
else cout << "Red Light\n";
// stop all other traffic that could possibly take that lane
if(streetB[0][1] == streetA[1][1])
{ cout << "Red Light\n"; }
break;
case 2:
laneB[0][1] = streetB[0][1];
if (laneB[0][1] == streetB[1][1])
{ cout << "Green Light\n"; }
else cout << "Red Light\n";
if(streetA[0][1] == streetB[1][1])
{ cout << "Red Light\n"; }
break;
} // end switch
} // end member function lanesB
i've done a course on data structures last semester. got a b-.. i took your advice and and got it back down to a one dimensional and it wors pretty fine now.. thanks alot kbw..
i'd just love to use a few pointers in there to.. i try to make the array a string pointer but its an error.. seems i have a bit more research to do but thanks alot..