Write a program to determine the average momentum

Assignment Help Computer Engineering
Reference no: EM132209689

Write a program to determine the average momentum of a collection of items with random velocities and masses. Do this using the following outline:

1. Construct a function named randVec that will take no arguments and return a dynamically allocated 3-element array of doubles. Each element in the array should be a randomly generated value in the range -100.0 through +100.0.

2. Using randVec and your momentum function from the previous part, generate momentum vectors for 1000 items, each of which has a random velocity (as described above) and a randomly generated mass in the range 1.0 through 10.0. Save the momentum vectors using a suitable array of pointers.

3. Determine and display the average momentum vector of the items using a for loop. [Hint: the average should be done component by component.]

This is what the code look like. The only thing cannot do is No.3, determining the average momentum vector. You can modify this code or start a new one!

#include <iostream>
#include <bits/stdc++.h>
#include <string.h>
#include <ctime>

using namespace std;


double *momentum(double velocity[3], double mass)

{
double *arymntm = new double[3];
for (int i=0; i<3; i++)

{
arymntm[i] = velocity[i] * mass;
}
return arymntm;

}


double *randVec()

{
double *velVec = new double[3];
for (int i=0; i<3; i++)
{
velVec[i] = rand() %200+(-100);
}
return velVec;
}


int main()

{

double mass[1000];
double *velocity[1000][3];
double *res[1000],sum[1000];
for (int it=0;it<1000;it++)
{
mass[it]=(rand() % 10)+1;
*velocity[it]=randVec();
res[it]=momentum(*velocity[it],mass[it]);
cout<<"Momentum values:";
sum[it]=0;
for(int i=0; i<3; i++)
{
cout<<res[it][i]<<" ";
sum[it]=sum[it]+res[it][i];
}
cout<<"Average of Momentum "<<it+1<<" value is :"<<sum[it]/3<<endl;
}
// system("pause");
return 0;
}

Reference no: EM132209689

Questions Cloud

Write a program that displays the sheep number that you are : Write a program that displays the sheep number that you are on (i.e. 1 sheep, 2 sheep). You have decided to count down from 100.
Write a program in which you create a hen class : Write a program in which you create a Hen class. Inside this class, nest a Nest class. Inside Nest, place an Egg class.
Determine whether or not an entered password is valid : Write a program to determine whether or not an entered password is valid.
Write a program to determine the time and date corresponding : Write a program to determine the time and date corresponding to a elapsed number of seconds since 00: 00: 00 on 1 January 2016.
Write a program to determine the average momentum : Write a program to determine the average momentum of a collection of items with random velocities and masses.
Display a centimeters- to- inches conversion table : Write a program to display a centimeters- to- inches conversion table. The smallest and largest number of centimeters in the table are input values.
Write a program to determine the class of an earthquake : Write a program to determine, and output to the screen, the class of an earthquake, given its magnitude.
Write a program that declares and initializes 2 integer : Write a program that declares and initializes 2 integer variables a and b with the values 35 and 14 and displays and calculates their sum.
Create and print a random phone number of the form : Write a program that creates and prints a random phone number of the form XXX-XXX-XXXX. Include the dashes in the output.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Write a subroutine that reads every symbol of the string

Declare a string using DCB directive. Write a subroutine that reads every symbol of the string and compares if it is a letter (A-Z, a-z).

  Describe the impact of access control methods

Describe the impact of access control methods and models in obtaining evidence of sufficient quality to be accepted by a court.

  What is your opinion about sqa plan

More project teams are having software quality assurance plan done when they develop projects.

  Which component would provide the best return on

When selecting a new computer, identify the key components that drive the performance of the machine.

  How could the shortcoming have been prevented

Using a web browser and a search engine, search the terms "CitiBank backup tapes lost." You will find many results. Select one article and identity what.

  Write a program that prompts for and reads the user city

Write a program that prompts for and reads the user's city and country (separately). Then print a string composed of the first two letters of the user's.

  How should manley make the case for soa to ensure

What new internal IT capabilities will have to be developed in order to create an IT department to support AgCredits future business architecture?

  What is requirements definition

An aspect of the preferred process for almost all formal software development approaches is to do some design before coding. One of the plan artifacts you are asked to use in this course is a flow chart.

  Differentiate between the vmebus and the nubus

What are the similarities between the IEEE 488 bus and the NuBus?

  What is the bandwidth efficiency for a 64-psk system

What is the bandwidth efficiency for a 64-PSK system - Can you find the bandwidth efficiency for a 64-PSK system?

  Write down a java gui application called indexjava which

write a java gui application called index.java that inputs several lines of text and a search character and uses string

  Write down a c program which accepts by keyboard input 8

write a c program that accepts by keyboard input 8 user-ratings of the galaxy s5. the ratings use a scale of 1 to 10

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd