A railroad track has a spur line that is a dead end. However at the end of the l
ID: 3688399 • Letter: A
Question
A railroad track has a spur line that is a dead end. However at the end of the line there is a railroad bumper that has been designed to stop a moving railroad car. At impact, the horizontal displacement in meters and the velocity in meters per second of the bumper as a function of time is given by: displacement = 4.219(e^-1.58 t - e^-6.32 t) velocity = 26.67e^-6.32t - 6.67e^-1.58 t Note: For the above equations, you must use C's built-in exponential function to compute e^x. EXAM PROGRAM: Using only one two-dimensional array and no other arrays, write a C program that will read from the input file called train the time; displacement, and velocity values into the array. The first row of numbers in the input file are the control numbers The remaining rows of numbers in the input file consist of time in seconds, displacement in meters, and velocity in meters/second respectively. The second and third columns of the input file are set to zero to initialize the array during the reading process. Using the two-dimensional array and the equations given above, compute the horizontal displacement and the velocity of the bumper at each time value after impact. Each computation of displacement and velocity will replace the zero values that were initially read into the array. After the computations are completed, the two-dimensional array will contain time, displacement, and velocity respectively. After completing the array computations, print a table as shown to the right. If the velocity turns negative, stop printing the table and print the message as shown to the right. Note: Your program must have three distinct for looping operations: one to read the array, one to compute the array, and one to print the array. The program must follow the same format that has been used for all programming assignments from the beginning of the semester. That is to say, it must have a title block, a program description, a list of variables, and within the program there must be indenting and comments relating to major sections of the program. Print the output to the computer screen and to an output file called train_report Your program must be named exam_3_firstname_lastname. Distance students will submit their exam to Blackboard and on-campus will submit their program to the O drive.Explanation / Answer
HI i have written a code for your reference,
#include <stdio.h>
#include <math.h>
#define inputfile "e:\personal\school\engr 200\Exams\Exam 3\train.txt"
#define outputfile "e:\personal\school\engr 200\Exams\Exam 3\train_report.txt"
/* Main function */
int main(void)
{
/* Declare variables */
double bumper[51][3];
int time,dis,velo,i,j,ndata;
FILE *train,*train_report;
/* Open input file */
train = fopen(inputfile,"r");
train_report = fopen(outputfile,"w");
/* Verify input file and read input data */
if(train == NULL)
{
printf(" ERROR OPENING INPUT FILE.");
printf(" PROGRAM TERMINATED. ");
return 0;
}
else
{
fscanf(train,"%i %i %i",&ndata);
for(i=0; i<=ndata-1; i++)
{
for(j=0; j<=ndata-1; j++)
fscanf(train,"%lf",&bumper[i][j]);
}
}
}
/* Compute displacement and velocity */
for(j=0; j<=ndata-1; j++)
{
for(i=0; i<-ndata-1; i++)
dis = 4.219 * (exp(-1.58*bumper[i][j]) - exp(-6.32*bumper[i][j]));
velo = (26.67 * exp(-6.32*bumper[i][j])) - (6.67 * exp(-1.58*bumper[i][j]));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.