(Solved) : Vehicletxt Copy Paste Notepad 17 99 03577 108778 21764 06881 32 1396 210232 40071 24055 40 Q42750213 . . .

C++Homework 5 In this assignment you will write code involving text files, structs, and operator overloading Consider reviewi

The findFarthestitem) function takes the parts array and its length N as input, and also the computed center-of-gravity (vect

VEHICLE.txt (copy and paste this into notepad)

17
99   0.3577   -10.8778  2.1764   -0.6881
32   1.396   -21.0232  -4.0071   2.4055
40   6.8664   10.8634  1.7559   1.5829
22   0.8992   -4.1864  -6.4992   -1.4902
34   2.7101   4.2737  -0.57   5.5512
92   8.171   3.3406  -11.0228   1.9537
91   4.1261   1.2147  -3.4654   3.6087
35   1.1538   -9.0394  1.3102   -0.1493
6   3.3582   -8.4715  -2.605   0.0333
55   2.5404   -2.7443  5.1828   2.9431
3   4.2818   -10.8589  -4.1564   2.3204
96   1.3425   -9.559  -12.6261   7.5446
68   3.1249   15.7248  -7.1582   1.1747
16   5.2367   1.5574  4.2782   8.6377
69   7.6784   -11.1732  -1.5661   6.5256
11   2.1721   0.5877  0.8961   -3.8352
54   9.5857   -10.2834  3.721   -3.0416

C++Homework 5 In this assignment you will write code involving text files, structs, and operator overloading Consider reviewing the lecture material on these topics before beginning. 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. In this problem, we are primarily interested in the mass and center-of-gravity of a particular product. The file vehicle.but contains a list of part data for a particular product (a vehicle of some sort). The first (A) 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 of the part (float, in kg), and the x, y and coordinates of where the part is located (3 floats, in meters). You will store the information for each part in a C++ structure defined as: struct Part int id float mass float coord[3] You will then store the information for the full vehicle in an array of Part structures called parts. Using this structure, you will write a program that opens the vehicle.txt 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, ie, the main program should have the following exact lines of code float xcgl3) 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 meotal -1 xu where m is the mass of each part, x is the three-element vector specifying the location of each part, and mtal is the total mass of the vehicle. The function prototype is therefore float findCG(Part, int, float”) where the integer input is the length of the Part array (we know that the length of the float array is 3, since it’s a spatial coordinate). The findFarthestitem) function 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- Xcall is the largest. Note that the function should output the identifier id, not the index of the part in the parts array! Once your code is able to determine the total mass, CG location, and most distant part, write the results to a data file called results.bxt. With the above parts of the code working, running the program with the provided parts file should generate the following texts in the new file: Total mass: 65.001 CG location: 2.29989-1.65699 2.26985 Most distant part: 68 The numbers above are for the reference vehicle.txt file provided; we will test your code with a different file, which will have a different number of parts With part (A) working, extend your code using operator overloading to do the following First, overload (B) the “” operator such that streaming a Part to standard output will display the part data. For example, cout < parts 01 should produce the following on your screen: ID 99 Mass 0.3577; xyz-10.8778.2.1764-06881 Next, overload the +” operator to “combine” two Parts together, such than adding two Part variables together will ( ask the user to enter a part number for the new Part, (2) assign the entered value to the id of the new Part, (3) assign the new Part mass to be the sum of the input Part masses, and (4) assign the new part coordinates (coord values) to be the sum of the individual part coordinates. Modify your code with the following lines at the end of your main) function (copy these lines exactly into your code) cout parts0< parts(1 endl cout partslo] parts[1 With the overloading working correctly, these lines will yield the following output on your screen ID 99, Mass 0.3577, x,yz-10.8778,2.17640.6881 ID 32; Mass 1.396 x,yz -21.0232,4.0071,2.4055 Enter new ID: 123 ID 123; Mass 1.7537; xyz -31.901-1.8307,1.7174 Call your final code parts.cpp. and submit through ELMS. You only need to submit a single source code file for this entire assignment Show transcribed image text C++Homework 5 In this assignment you will write code involving text files, structs, and operator overloading Consider reviewing the lecture material on these topics before beginning. 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. In this problem, we are primarily interested in the mass and center-of-gravity of a particular product. The file vehicle.but contains a list of part data for a particular product (a vehicle of some sort). The first (A) 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 of the part (float, in kg), and the x, y and coordinates of where the part is located (3 floats, in meters). You will store the information for each part in a C++ structure defined as: struct Part int id float mass float coord[3] You will then store the information for the full vehicle in an array of Part structures called parts. Using this structure, you will write a program that opens the vehicle.txt 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, ie, the main program should have the following exact lines of code float xcgl3) 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 meotal -1 xu where m is the mass of each part, x is the three-element vector specifying the location of each part, and mtal is the total mass of the vehicle. The function prototype is therefore float findCG(Part, int, float”) where the integer input is the length of the Part array (we know that the length of the float array is 3, since it’s a spatial coordinate).
The findFarthestitem) function 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- Xcall is the largest. Note that the function should output the identifier id, not the index of the part in the parts array! Once your code is able to determine the total mass, CG location, and most distant part, write the results to a data file called results.bxt. With the above parts of the code working, running the program with the provided parts file should generate the following texts in the new file: Total mass: 65.001 CG location: 2.29989-1.65699 2.26985 Most distant part: 68 The numbers above are for the reference vehicle.txt file provided; we will test your code with a different file, which will have a different number of parts With part (A) working, extend your code using operator overloading to do the following First, overload (B) the “” operator such that streaming a Part to standard output will display the part data. For example, cout

Expert Answer


Answer to VEHICLE.txt (copy and paste this into notepad) 17 99 0.3577 -10.8778 2.1764 -0.6881 32 1.396 -21.0232 -4.0071 2.4055 40…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?