I often come to this site for a great deal of help for both Java and C++. I have been having a lot of trouble on my assignment for class, and I was hoping someone could nudge me in the right direction for implementing a pass-by-pointer into my program that is already using a pass-by-value. Basically, I have to use the pass-by-value mechanism to display accurate velocity calculations, then use pass-by-pointer to successfully use that result in a momentum equation. The program is suppose to display distance, time, velocity, and momentum. I am very much new to C++, and I am seriously struggling, so please do not be alarmed if my code is a bit "noob". I really only need a nudge in the right direction. Maybe an example or something? My textbook examples have me confused, and my instructor example confused me also. Here is what I have:
//Robin Yam
//IT/218
//Velocity and Momentum Program
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
//Function prototypes (declaring the functions).
double velocity (double distance, int time);
double momentum (double velocity);
//Main function.
int main ()
{
double PrimaryVelo (0);
double TotalMomentum (0);
int t (1);
for ( double d = 1; d <= 10; d++)
{
PrimaryVelo = velocity (d, t);
} //End for the primary for loop.
system ("pause"); //Prevents closing of debug automatically.
return 0;
} //End of the main function.
//Pass-by-value method for velocity.
double velocity (double distance, int time)
{
return (distance / time);
}
//Pass-by-pointers method for momentum.
double momentum (double velocity)
{
return (velocity * 205);
}

New Topic/Question
Reply



MultiQuote







|