A point mass consists of a 3-D location and an associated mass, such as
Location: (6, 0, 2) Mass: 3g
In a system of point masses, let p 1 , p 2 …….p n be the n 3-D points and m 1 , m 2 ……. m n be their associated masses. If m is the sum of the masses, the center of gravity C is calculated as
C=1/m(m1p1+m2p2+......+mnpn)
Write a program that repeatedly inputs point-mass system data sets from an input file until an input operation fails. For each data set, display the location matrix, the mass vector, n , and the center of gravity. Each data set includes a location matrix (a matrix in which each row is a point), a one-dimensional array of masses, and the number of point masses, n . Allow n to vary from 3 to 10.
Sample Data File
4
5 -4 3 2
4 3 -2 5
-4 -3 -1 2
-9 8 6 1
This sample should be stored as:
location 5 -4 3
4 3 -2
-4 -3 -1
-9 8 6
mass 2
5
2
1
n 4
Your main function should repeatedly input and process data sets from an input file until end of file is encountered. For each point-mass system data set, display the location matrix, the mass vector, n , and the center of gravity. Implement at least the following functions:
fget_point_mass : Takes an open input file and a maximum value for n as parameters and fills a two-dimensional array output parameter with a location matrix and a one-dimensional array output parameter with a mass vector from the data file. Returns as function value the actual value of n . center_grav : Takes a location matrix, mass vector, and n value as parameters, and calculates and returns as the function value the center of gravity of the system. fwrite_point_mass : Takes an open output file and the location matrix, mass vector, and n value of a point-mass system as parameters and writes the system to the file with meaningful labels.
Do you need help with this assignment or any other? We got you! Place your order and leave the rest to our experts.