Assignment 09

Specifications:

Due: Monday, November 16, 2015 at noon 100 points

Instructions: Submit the files as usual.

Background: You've done swell this semester with the programs that you have written for Homer. Homer is so pleased that he is going for a ride in his new car. He bought one of those autonomously driving vehicles which always make driving fun, easy, and sometimes terrifying. Now you know that security is a big issue with autonomous cars; you wouldn't want to have your car hacked while driving down the highway. So, now that he has made lots-o-money from your hard work, he is itching to go for a long "road trip" vacation. But, he's worried. You see, he's a bit worried about the whole electric-car-autonomous-vehicle thing. You have to understand that early models of robotic vehicles were ... um ... didn't go so well. Another problem that Homer is concerned about is the car's range of travel - he will need battery power to get him to his destination.

He wants you to write a program to simulate his eventual car trip, highlighting all the ups and downs of automotometry1. This assignment, #9, will work eventually in conjunction with hw #10, the final project. BUT, for now in hw #9, you are only to develop 3 classes that will be used later in hw #10. You will also write a main function for this assignment whose sole purpose is to test the classes you've written. This kind of main is often referred to as a "driver" (no pun intended). More on it later.

  • ROAD CLASS

    • Member Variables

      • width: The number of road sections.

      • char sectors[MAX_WIDTH]: A road object will be seen as having "sectors" or "lanes", each of which will contain either nothing or part of a car unit. These are not lanes as you are used to thinking about lanes. Forget about north-bound vs. south-bound lanes. Just think about a single roadbed divided into strips. For example, suppose our road is 15 feet wide and there are 10 "sectors" or "lanes". Then each sector is 1.5 feet wide. So, a car might occupy 4 sectors (the wheels are in the outer-most of these four). Width will be an int representing the number of sectors for the road (each sector width is immaterial). A big road might have 15 sectors, a small road 10. Each sector will contain either a blank (nothing there) or a 'c' (part of the car). Make a constant MAX_WIDTH for this class and set it to 15.

    1. Member Functions

      1. a default constructor that initializes the sectors to be empty, and sets the width to 10.

      2. an accessor (get) function for the width of the road.

      3. a function to "add a car to the road". Call this function place_car(), and give it parameters for the width of the car, the left-most position on the road for the car, and a character to represent that the car is there. This simply "marks" appropriate sectors of the road to indicate a car is occupying those sectors.

      4. overloaded insertion operator. This should display the state of the road. The following output depicts a ten-lane/sector road with a car occupying 4 sectors/lanes:

        1. | |c|c|c|c| | | | | |

  • ANIMAL CLASS

    • Member Variables

      • weight: How much the animal weighs in kg.

      • species: A string ... for "cat", "deer", "possum", etc.

      • width: An int for the number of sectors (on a road) it occupies.

        • stupidity : This is to be a percentage value (0 -> 100) that will determine whether the animal will run onto the road.

    • Member Functions

      • A default constructor which will make type "possum", weight 10, width 2, stupidity 98 (yeah, no kidding).

      • A constructor to take species, weight, width, and stupidity as parameters.

      • Accessor functions for weight and width.

      • A private public choose_to_run() function that will depend on the animal's stupidity level. This should return a bool.

      • An overloaded insertion operator to output (on a single line) all of the animal's info.

  • CAR CLASS

    • Member Variables

      • width: The number of (road) sectors it occupies.

      • damage: An accumulated percentage of how damaged the car currently is.

      • battery: A percentage of battery power remaining.

      • symbol: A character to use to represent the car where ever it is (like, on a road).

    • Member Functions

      • appropriate constructor(s), including a default that will set:

        • width = 4

        • damage = 0

        • battery = some random value between 90 and 100

        • symbol = 'c'

      • an accessor for the width of the car.

      • an accessor for the damage to the car.

      • an accessor for the car's remaining battery power.

      • a function that takes a positive integer value (representing the weight of some road obstacle) and then increases the battery by half of the weight of the obstacle, battery not to exceed 100

      • a function that takes a positive integer value (representing the weight of some road obstacle) and then increases the damage by one tenth of the weight, damage not to exceed 100.

      • enter_a_road() function that is passed a road object and establishes the car on the road (changes the state of the road to reflect the existence of the car). This function will have the parameter (a road) call its place_car() function, passing it the width of the car, the left-most position (an index?) of where that car will be, and the char to represent that car.

      • an overloaded insertion to output the state of the car (on one line).

  • The driver

The driver, your main function, is supposed to be designed solely to test other units, your classes in this case. Make your driver so that it will create instances of each of the above described classes and test their functionality. Thus, your driver will declare objects of the above types using all the constructors you have made, and then will test the member functions of these objects. You should output the objects to show that the functions have indeed worked. For example, declare a road and declare a car, then have the car place itself on the road. Output the road showing that there is now a car on it.

When you submit: You will submit your classes and their respective implementation files, and the "driver".

1I just made up this word.