Most engineering products are composed of many different components or parts. It is, of course, essential to maintain a list of all parts in a product; depending on the nature of the product, one would want to include different types of information in such a list. Let's imagine that we are primarily interested in the mass and center-of-gravity of a particular product (the obvious examples are airplanes and boats, but could also include things like hand-held devices). The file vehicle.prt contains a list of part data for a particular product (a vehicle of sorts in this case). The first line contains an integer of how many different parts are in the file (i.e., the number of lines that follow). The following lines contain, in order: the part identifier number (integer); the mass m of the part (float, in kg); and the æ, y and z coordinates of where the part is located (3 floats, in m). We are going to store the information for each part in a C++ structure defined as struct Part { int id; float mass; float coord [3] ; }; We are then going to store the information for the full vehicle in an array of Part structures called parts. Using this structure, you should write a program that opens the vehicle.prt file, finds the number of parts, and allocates an array parts of the correct length. It should then read all the parts information in the file and store this in the parts array. The program should then compute the total mass and the center-of-gravity ("CG"), and also find which part is farthest from the CG. These tasks should be performed in functions, i.e., the main program should have the following exact lines of code: float xcg[3]; float totalMass - findcG (parts, N, xcg); int part_id - findFarthestItem(parts, N, xcg); The findCG function should take the parts array loaded from the file and compute both the total vehicle mass and the location of the center-of-gravity. The latter is a thrce-element vector XCG = mrotal where m, is the mass of each part, x, is the three-element vector specifying the location of each part, and motal = EN, m, is the total mass of the vehicle. The function prototype is therefore

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I want to know how to write this  C++ code with comments to help me understand better.

Most engineering products are composed of many different components or parts. It is, of course,
essential to maintain a list of all parts in a product; depending on the nature of the product, one
would want to include different types of information in such a list. Let's imagine that we are
primarily interested in the mass and center-of-gravity of a particular product (the obvious examples
are airplanes and boats, but could also include things like hand-held devices).
The file vehicle.prt contains a list of part data for a particular product (a vehicle of sorts
in this case). The first line contains an integer of how many different parts are in the file (i.e.,
the number of lines that follow). The following lines contain, in order: the part identifier number
(integer); the mass m of the part (float, in kg); and the a, y and z coordinates of where the part is
located (3 floats, in m).
We are going to store the information for each part in a C++ structure defined as
struct Part {
int id;
float mass;
float coord[3];
};
We are then going to store the information for the full vehicle in an array of Part structures called
parts.
Using this structure, you should write a program that opens the vehicle.prt file, finds the
number of parts, and allocates an array parts of the correct length. It should then read all the
parts information in the file and store this in the parts array.
The program should then compute the total mass and the center-of-gravity ("CG"), and also
find which part is farthest from the CG. These tasks should be performed in functions, i.e., the
main program should have the following exact lines of code:
float xcg[3];
float totalMass = findCG (parts, N, xcg);
int part_id = findFarthestItem (parts, N, xcg);
The findCG function should take the parts array loaded from the file and compute both the
total vehicle mass and the location of the center-of-gravity. The latter is a three-element vector
N
1
XCG
mtotal
i=1
where m; is the mass of each part, x; is the three-element vector specifying the location of each
part, and mrotal = E, m; is the total mass of the vehicle. The function prototype is therefore
float findCG (Part, int, float+);
Transcribed Image Text:Most engineering products are composed of many different components or parts. It is, of course, essential to maintain a list of all parts in a product; depending on the nature of the product, one would want to include different types of information in such a list. Let's imagine that we are primarily interested in the mass and center-of-gravity of a particular product (the obvious examples are airplanes and boats, but could also include things like hand-held devices). The file vehicle.prt contains a list of part data for a particular product (a vehicle of sorts in this case). The first line contains an integer of how many different parts are in the file (i.e., the number of lines that follow). The following lines contain, in order: the part identifier number (integer); the mass m of the part (float, in kg); and the a, y and z coordinates of where the part is located (3 floats, in m). We are going to store the information for each part in a C++ structure defined as struct Part { int id; float mass; float coord[3]; }; We are then going to store the information for the full vehicle in an array of Part structures called parts. Using this structure, you should write a program that opens the vehicle.prt file, finds the number of parts, and allocates an array parts of the correct length. It should then read all the parts information in the file and store this in the parts array. The program should then compute the total mass and the center-of-gravity ("CG"), and also find which part is farthest from the CG. These tasks should be performed in functions, i.e., the main program should have the following exact lines of code: float xcg[3]; float totalMass = findCG (parts, N, xcg); int part_id = findFarthestItem (parts, N, xcg); The findCG function should take the parts array loaded from the file and compute both the total vehicle mass and the location of the center-of-gravity. The latter is a three-element vector N 1 XCG mtotal i=1 where m; is the mass of each part, x; is the three-element vector specifying the location of each part, and mrotal = E, m; is the total mass of the vehicle. The function prototype is therefore float findCG (Part, int, float+);
float findCG (Part*, int, float*);
where the integer input is the length of the Part+ array (but we know that the length of the float*
array is 3, since it's a coordinate!).
The findFarthestItem function also takes the parts array and its length N as input, and also
the computed center-of-gravity (vector) xcg. The output of the function should then be the id of
the part that is farthest from the CG, i.e., the part for which |x; – XcG|| is the largest. Note that
the function should output the identifier id, not the index of the part in the parts array!
Finally, the code should ask the user to enter the vector to shift all of your part positions,
perform the shift using the += operator, and write the results to a data file called results.dat.
The format of the output in this file should be:
Total mass: 65.001
Initial CG location: -2.29989 -1.65699 2.26985
Most distant part: 68
Transcribed Image Text:float findCG (Part*, int, float*); where the integer input is the length of the Part+ array (but we know that the length of the float* array is 3, since it's a coordinate!). The findFarthestItem function also takes the parts array and its length N as input, and also the computed center-of-gravity (vector) xcg. The output of the function should then be the id of the part that is farthest from the CG, i.e., the part for which |x; – XcG|| is the largest. Note that the function should output the identifier id, not the index of the part in the parts array! Finally, the code should ask the user to enter the vector to shift all of your part positions, perform the shift using the += operator, and write the results to a data file called results.dat. The format of the output in this file should be: Total mass: 65.001 Initial CG location: -2.29989 -1.65699 2.26985 Most distant part: 68
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY