From 207befebb4932a4cb6a6497d744ce24b10bdabec Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 23 Apr 2019 12:15:34 -0500 Subject: More lab --- ee1301/wk6/lab5/momentum.cpp | 21 +++++++++++++-------- ee1301/wk6/lab5/vectorArray.cpp | 7 +++++++ 2 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 ee1301/wk6/lab5/vectorArray.cpp (limited to 'ee1301') diff --git a/ee1301/wk6/lab5/momentum.cpp b/ee1301/wk6/lab5/momentum.cpp index ef7a7e7..0a19e04 100644 --- a/ee1301/wk6/lab5/momentum.cpp +++ b/ee1301/wk6/lab5/momentum.cpp @@ -1,6 +1,6 @@ #include -double* momentum (double velocity[3], double mass); +double momentum (double velocity, double mass); int main() { double velocity[3]; @@ -9,14 +9,19 @@ int main() { std::cin >> velocity[0] >> velocity[1] >> velocity [2]; std::cout << "Please enter mass [kg]: "; std::cin >> mass; - momentum(&velocity[3], mass); -} - -double* momentum(double velocity[3], double mass) { double* vector; vector = new double[3]; - for (int i=0; i<2; i++) { - vector[i]=velocity[i]*mass; + std::cout << "Momentum: <"; + for (int i=0; i<=2; i++) { + vector[i]=momentum(velocity[i], mass); + std::cout << vector[i]; + if ((i<2)) + std::cout << ","; } - return vector; + delete[] vector; + std::cout << ">" << std::endl; +} + +double momentum(double velocity, double mass) { + return velocity * mass; } \ No newline at end of file diff --git a/ee1301/wk6/lab5/vectorArray.cpp b/ee1301/wk6/lab5/vectorArray.cpp new file mode 100644 index 0000000..069ef6a --- /dev/null +++ b/ee1301/wk6/lab5/vectorArray.cpp @@ -0,0 +1,7 @@ + + + + +double randVec() { + +} \ No newline at end of file -- cgit v1.2.3