MECH 415 Assignment #5: part II

Question #1

Develop a class called subsystem with the following public member variables:

X – a dynamic 1D array used to represent the state vector of the system Xd – a dynamic 1D array used to represent the state vector derivative of the system N – the number of state variables U – a dynamic 1D array used to represent the input vector of the system M – the number of input variables t – time Name – a dynamic string variable used to represent the name of the subsystem

The class has the following public member functions:

A constructor with the arguments N and M which correspond to the values of the member variables indicated above.

A destructor.

Question #2

Develop a class called vehicle which is derived from the subsystem class from the previous question (the subsystem class is private). Furthermore, the vehicle class has the following public member variables:

P – a dynamic 1D array representing a 3D vector that stores the position of the vehicle V – a dynamic 1D array representing a 3D vector that stores the velocity of the vehicle a – a dynamic 1D array representing a 3D vector that stores the acceleration of the vehicle F – a dynamic 1D array representing a 3D vector that stores the external force on the vehicle (this can be considered the input to the system). R – a dynamic dmatrix object (from Assignment #4) that represents a 3x3 rotational matrix for the vehicle m – the mass of the vehicle Radius – the approximate size of vehicle as represented by a spherical radius from the center of the vehicle X_file – a string variable that represents the x-file used to draw the vehicle (drawing will be done in a future assignment)

You can assume that the state vector is composed of the position and the velocity components.

The class has the following public member functions:

A constructor with the argument init_file (a string variable used to store the file name) which consistently initializes all the member variables of the vehicle class. The file format sequentially stores the member variables in the order they are listed above in the problem statement. This function can be tested with the output from the save function described below (make sure the member variables are first initialized before calling save). save – a function with the argument save_name (a string variable used to store the file name) that writes all the member variables sequentially into a file (in the order the member variables are listed above). load – a function with the argument load_name (a string variable used to store the file name) that reads all the member variables from the file (assuming the file format indicated in the save function). calculate_input – a function that calculates the input (ie F) of the system according to the formula:

F = [sin(t),sin(2*t),sin(3*t)] calculate_Xd – a function that calculates the state vector derivative of the system from the formula: a = F/m sim_step – a function that calculates the change in the state and member variables for one time step of dt using the Euler simulation method. The argument to the function is dt.

A destructor.

Question #3

Write a program (in the main function) that simulates a 1D array of vehicle classes (from question #2) with a dimension of 3. Assume each vehicle has a different constructor initialization file. Hint: you need to use a 1D array of vehicle pointers, ie. vehicle *v_p[3]; // declare an array of 3 vehicle pointers