Reference no: EM132309686
Programming Fundamentals Assignment - A mini-programming project
Tasks: Design and implement the following tasks to manage the simulation of an Automated Crash Test System.
Your program should first load the names of up to 10 vehicles from a file named "Vehicle.txt" and load the names of up to 10 obstacles from a file named "Obstacle.txt" and store them in two arrays of structures, one for vehicles and the other for obstacles. The minimum requirement for the data structures representing a vehicle and an obstacle can be found from Section (1).
Next, the program should display a Menu that allows the user to navigate through and execute the following options:
- Search a vehicle
- Search an obstacle
- Input/update vehicle information
- Input/update obstacle information
- Simulate a vehicle crash against an obstacle
- Display simulation results
- Display all results
- Save all results
- Save vehicle/obstacle information
- Exit
The "Search a vehicle" feature should allow the user to search for information of a vehicle by its Vehicle_Name. Information stored in the related entry/entries in the vehicle array will be displayed. If the vehicle is not found, an error message should be displayed. The "Search an obstacle" feature is similar, but it searches information of an obstacle instead.
The "Input/update vehicle information" feature allows the user to input information of a vehicle. If the input Vehicle_Number matches an existing vehicle, the information entered is used to update the information of the vehicle stored in the array of vehicles. Otherwise a new entry is created in the array of vehicles and information is stored there. The "Input/update obstacle information" feature is similar, but it inputs/updates information of an obstacle instead.
The "Simulate a vehicle crash against an obstacle" feature should allow the user to select a vehicle and an obstacle (from the respective arrays), and then simulate a vehicle crash scenario. Detailed simulation task is described in "Vehicle crash test simulation" section.
The "Display simulation results" feature should allow the user to choose a vehicle (e.g., by its vehicle name) and display all test simulation results against some or all obstacles. If the vehicle has not yet been tested (i.e., no simulation was recorded), the program should inform the user that they must test that vehicle before displaying any results of the vehicle/s. If multiple vehicles have the same name, all vehicles' test results with that name should be displayed.
The "Display all results" feature should display an error message if no vehicle has been tested. Otherwise it displays the results of all vehicles that have been tested.
The "Save vehicle/obstacle information" feature should extract all vehicle names from the vehicle array and save them back to "Vehicle.txt" file. It also extracts all obstacle names from the obstacle array and saves them back to "Obstacle.txt" file for possible future use/test. For simplicity, only up to 10 (vehicle/obstacles) names are required to save.
The "Save all results" feature should display an error message if no vehicle has been tested. Otherwise it creates a file, named "results.txt", and save the names and test results for all vehicles that have been tested, to the file.
Menu design/implementation requirement: Create one function for each menu item (i.e., to implement its feature/s). If any of these functions was not completed as required in the final submission, use a dummy function that prints the following statement only: "<menu item name> feature has not been completed yet."
For example, if the "Display all results" feature was not completed at submission, the function should print the following statement only: "Display all results feature has not been completed yet."
(1) Data structures for Vehicles and Obstacles
Referencing the Vehicle structure defined in your Workshop 3, define a new structure to represent a vehicle for the crash simulation purpose. Your Vehicle structure should include at least 6 fields, including Vehicle_number, Vehicle_name, Manufactur_date, Top_speed, Mass, Number_of_seats. You may add any extra field/s as you need.
The Obstacle structure should include at least 3 fields, Obstacle_number, Obstacle_Name, Stopping_distance. You may add any extra field/s as you need.
(2) Vehicle crash test simulation
This task simulates a vehicle crash scenario, completing calculations on various data items, and displaying test simulation result.
Vehicle crash test simulation can be done under random conditions (i.e., conditions are randomly generated automatically within a reasonable value range) or by manually entering a set of test conditions. - Due to time and workload constraints, we only perform the latter case in this assignment (that is, all test conditions are to be entered manually under prompt).
At the start, the function/program prompts the user to choose one vehicle from the available vehicles and one obstacle from the available obstacles. It then prompts user to enter a variety of test conditions (including the velocity, or alternatively named impact_velocity, of the vehicle) for the crash test simulation.
The test conditions are set as follows and must comply with the listed restrictions:
Vehicle_age
- Measured in years.
- Must not be greater than the current date minus the Vehicle manufacture date or less than zero.
Impact_velocity
- Display/entered in kmph.
- Use m/s in calculations.
- Must not be greater than the Vehicle's top speed or less than zero.
Number_of_passengers
- Must not be greater than the number of seats of the Vehicle or less than zero.
Number_of_seatbelt_wearing_passengers
- Must not be greater than the number of passengers or less than zero.
If the user enters an invalid value for any test condition, the program should print an error message, together with the data entered, and continue to prompt user again until a valid value is entered.
Based on the above information, the simulation calculates various data items, including Safety_rate and Damage to the vehicle participating the simulation, and Survival_rate of passengers involved in the crash. It then displays (and optionally saves) these data items as the simulation results.
Calculation of Safety-rate
Each test condition confers a bonus or penalty to the overall percentage Safety_rate of the test.
The Safety_rate is calculated using the following steps/algorithm:
a) Safety_rate = 1; // initialized as a percentage value of 100%
b) Decrease Safety_rate by a percentage factor of the vehicle's age using: ¼ * (Vehicle_rge - 2)2
c) Decrease Safety_rate by F /10000.0, which is the approximate impact force F on the vehicle, where F = ½mv2/s, m is the vehicle's mass, v the impact_velocity (in m/s) of the vehicle, and s the stopping distance of the obstacle.
d) If Safety_rate is below zero, set Safety_rate to 0; if Safety_rate is above 100% (or Safety_rate = 1), set Safety_rate to 100%.
Once the details of the test have been finalized, the user should be shown all condition information and the Safety_rate. The user will have an opportunity to accept the information and start the test or discard (and regenerate) all conditions.
Calculation of Damage-rate
In a crash, the damage to a vehicle depends on its Safety_rate of the vehicle in that crash. This is set as a random value within 25% * (1- Safety_rate).
Calculation of Passenger's Survival-rate
In a crash, the Survival-rate of a passenger involved in the crash depends on two factors, the Safety_rate of the vehicle, and whether or not he/she is wearing a seatbelt.
Each passenger will have, initially, a Safety_rate (percent) chance of survival. However, if any passengers are not wearing a seatbelt, all passengers are 4 times less likely to survive. Furthermore, those who are not wearing a seatbelt are 9 times less likely to survive.
Finally, display simulation result (together with test conditions) in a properly designed table.
Attachment:- Assignment File.rar