- #1
asz304
- 108
- 0
Hi. I need help with in running my program, when I tried it in the computer lab, my program didn't run..And I'm sure it couldn't run because of my workings..which I assume are incorrect. I appreciate it if you could tell me where did I go wrong with my calculations and if it matched the "Input/Output" example in the Assignment Problem Source.
Assignment Problem Source: http://www.engr.mun.ca/~markevans/engr1020/Eng1020Labs/Assignments/Entries/2010/10/7_Assignment_3__Mark_the_lazy_cyclist.html"
My Workings:
#include <iostream>
#include <cmath>
using namespace std;
void outResults1(float deceleration,float v_final, float v_initial, int time);
int time ( float deceleration, float v_average, float v_inital, float v_final);
void outResults2(int time, int seconds);
float calculatedistance ( int time, float distance, float v_average);
void outResults3(float distance, float v_average, float time );
/********************************************************************
* main --
*
* @params: argc -
* argv - the value of the command line arguments as array of character pointers
* @descript: main entry point for program, handle inputs and outputs.
*
* @returns: 0 for execution success.
********************************************************************/
int main( int argc, char *argv[] )
{
float deceleration; //Deceleration Of Mark
int time; //Time spent for coasting
float distance; //Distance coasted
float v_final;
float v_initial;
float v_average;
outResults1(deceleration, v_final, v_initial,time);
deceleration = (v_final - v_initial)/time;
outResults2(int time, int seconds);
time = distance/v_average;
outResults3(distance,v_average, time );
distance = v_average*time;
}
/********************************************************************
deceleration - the acceleration rate of Mark
@params: none
@modifies: cin
cout
-Prompts the user and inputs the following:
Initial speed of in kph
Speed after 1 minute in kph
@pre: none
@returns: acceleration rate of Mark
******************************************************************/
float deceleration()
{
float deceleration = 0.f;
float v_initial = 34.7;
float v_final = 24.3;
float v_average = 0.f;
float distance = 0.f;
int time;
cout << "Please enter the initial speed in kph with decimal:" << endl;
cin >> v_initial;
cout << "Please enter the speed after 1 minute in kph with a decimal" << endl;
cin >> v_final;
time = distance/v_average;
deceleration = ( v_final - v_initial )/ time;
return deceleration;
}
/********************************************************************
* outResults1 - outputs the computed deceleration
*
* @params: deceleration--deceleration of Mark.
* @modifies: cout -- Outputs the results.
*
* @pre: none
*
* @returns: nothing
* ********************************************************************/
void outResults1(float deceleration, float v_final, float v_initial, int time )
{
cout << "\n Mark's deceleration rate is: " << ( v_final - v_initial ) / time;
}
/********************************************************************
@params: time - time spent coasting
v_average - average speed of Mark
deceleration - acceleration rate of Mark
@modifies: nothing
@pre: none
@returns: time
********************************************************************/
int time ( float deceleration, float v_average, float v_inital, float v_final)
{
int time = 0.f;
v_average = (v_inital + v_final)/ 2;
time = (v_final - v_inital)/ deceleration;
return time;
}
/********************************************************************
* outResults2 - outputs the time spent for coasting
*
* @params: time- time spent for coasting
* @modifies: cout -- Outputs the results
*
* @pre: none
* @returns: nothing
********************************************************************/
void outResults2 ( int time, int seconds )
{
cout << time / 60 << "minutes and " << time % 60 << seconds;
}
/******************************************************************** distance - distance reached after coasting
v_average - average speed
time - time spent coasting
@modifies: nothing
@returns: distance
********************************************************************/
float calculatedistance ( int time, float v_average)
{
float distance = 0.f;
distance = v_average*time;
return distance;
}
/******************************************************************** *
outResults3 - outputs the distance reached after coasting
*
* @params: distance- distance reached after coasting
* @modifies: cout - Outputs the results
*
* @returns: nothing
* ********************************************************************/
void outResults3 ( float distance, float v_average, float time )
{
cout << "\nThe distance that Mark reached after coasting is : " << v_average*time;
}
Homework Statement
Assignment Problem Source: http://www.engr.mun.ca/~markevans/engr1020/Eng1020Labs/Assignments/Entries/2010/10/7_Assignment_3__Mark_the_lazy_cyclist.html"
The Attempt at a Solution
My Workings:
#include <iostream>
#include <cmath>
using namespace std;
void outResults1(float deceleration,float v_final, float v_initial, int time);
int time ( float deceleration, float v_average, float v_inital, float v_final);
void outResults2(int time, int seconds);
float calculatedistance ( int time, float distance, float v_average);
void outResults3(float distance, float v_average, float time );
/********************************************************************
* main --
*
* @params: argc -
* argv - the value of the command line arguments as array of character pointers
* @descript: main entry point for program, handle inputs and outputs.
*
* @returns: 0 for execution success.
********************************************************************/
int main( int argc, char *argv[] )
{
float deceleration; //Deceleration Of Mark
int time; //Time spent for coasting
float distance; //Distance coasted
float v_final;
float v_initial;
float v_average;
outResults1(deceleration, v_final, v_initial,time);
deceleration = (v_final - v_initial)/time;
outResults2(int time, int seconds);
time = distance/v_average;
outResults3(distance,v_average, time );
distance = v_average*time;
}
/********************************************************************
deceleration - the acceleration rate of Mark
@params: none
@modifies: cin
cout
-Prompts the user and inputs the following:
Initial speed of in kph
Speed after 1 minute in kph
@pre: none
@returns: acceleration rate of Mark
******************************************************************/
float deceleration()
{
float deceleration = 0.f;
float v_initial = 34.7;
float v_final = 24.3;
float v_average = 0.f;
float distance = 0.f;
int time;
cout << "Please enter the initial speed in kph with decimal:" << endl;
cin >> v_initial;
cout << "Please enter the speed after 1 minute in kph with a decimal" << endl;
cin >> v_final;
time = distance/v_average;
deceleration = ( v_final - v_initial )/ time;
return deceleration;
}
/********************************************************************
* outResults1 - outputs the computed deceleration
*
* @params: deceleration--deceleration of Mark.
* @modifies: cout -- Outputs the results.
*
* @pre: none
*
* @returns: nothing
* ********************************************************************/
void outResults1(float deceleration, float v_final, float v_initial, int time )
{
cout << "\n Mark's deceleration rate is: " << ( v_final - v_initial ) / time;
}
/********************************************************************
@params: time - time spent coasting
v_average - average speed of Mark
deceleration - acceleration rate of Mark
@modifies: nothing
@pre: none
@returns: time
********************************************************************/
int time ( float deceleration, float v_average, float v_inital, float v_final)
{
int time = 0.f;
v_average = (v_inital + v_final)/ 2;
time = (v_final - v_inital)/ deceleration;
return time;
}
/********************************************************************
* outResults2 - outputs the time spent for coasting
*
* @params: time- time spent for coasting
* @modifies: cout -- Outputs the results
*
* @pre: none
* @returns: nothing
********************************************************************/
void outResults2 ( int time, int seconds )
{
cout << time / 60 << "minutes and " << time % 60 << seconds;
}
/******************************************************************** distance - distance reached after coasting
v_average - average speed
time - time spent coasting
@modifies: nothing
@returns: distance
********************************************************************/
float calculatedistance ( int time, float v_average)
{
float distance = 0.f;
distance = v_average*time;
return distance;
}
/******************************************************************** *
outResults3 - outputs the distance reached after coasting
*
* @params: distance- distance reached after coasting
* @modifies: cout - Outputs the results
*
* @returns: nothing
* ********************************************************************/
void outResults3 ( float distance, float v_average, float time )
{
cout << "\nThe distance that Mark reached after coasting is : " << v_average*time;
}
Last edited by a moderator: