Lab4: The Highway

If we are going to model a chunk of the Interstate through Austin, we need a way to visualize the action we expect to see.

To get started on our simulation, we need to set up a screen where we can see all the vehicles traveling along the highway. There is a problem with this. The highway is long, and our computer screen is short. The solution I came up with is to break the highway up into short strips, and show traffic moving along each strip.

Vehicles will enter at the left edge of the top strip, move along that first strip, and leave at the right edge. Then, they will appear on the left edge of the next strip below, and move along that one. They repeat this process until they reach the final strip exit point. At that point, we remove them from the simulation.

Highway Construction

Gather up a bunch of orange cones. We need to build a highway!.

To build this part of the simulation, we need a class that will represent the highway. Here is the start of a class specification you can use to build this part of the simulation.

Highway.h
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#ifndef HIGHWAY_H
#define HIGHWAY_H

#include <string>

class Highway {
    public:
	std::string name;	// name of this highway
        int lanes;		// number of lanes 
        int width;		// width of each lane in pixels
        int length;		// length of each lane segment

	Highway();		// default constructor
	void draw();		// display the highway
};

#endif

All you need to do for this lab is make your application draw the highway system we will use for the rest of the project. You will see an example of this system in class.