? Fwd: EGR 106 Exam Rev × -webwork-MTH 201 02-C Desmos l Graphing Calculat + v K
ID: 3710628 • Letter: #
Question
? Fwd: EGR 106 Exam Rev × -webwork-MTH 201 02-C Desmos l Graphing Calculat + v K n https://mail.google.com/mail/u/2/#inbax/162d125da9af3ce8?projector 1messagePartld-0.1 67 34 32 89 67 54 23 90 20 50 23 2. Reading in a ile of data points using multidimensional array Read the coordinate values of the location of the mass and the value of the mass from Calculate the center of mass Formula e Center of mass in x direction Center of mass in y direction = Center of mass in z direction %1(mi) 2i1(m) File would be formatted in a similar fashion (x,y,z) mass (2,4,8) 20 (12,7,16) 30 (23,40,12) 12Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<ctype.h>
#include<stdlib.h>
void main()
{
ifstream file1("data.txt");
char a[100][4]; char ch; int i=0,j=0;
clrscr();
while(!file1.eof())
{
file1>>ch;
if(isdigit(ch))
a[i][j++]=ch;
if(j>3)
{ i++; j=0;}
}//while
int n1=0,n2=0,x=0,y=0,z=0,mass=0;
for(n1=0;n1<=i;n1++)
{
x+=a[n1][0];
y+=a[n1][1];
z+=a[n1][2];
mass+=a[n1][3];
}
double massx=x/mass;
double massy=y/mass;
double massz=z/mass;
cout<<" center of mass in X Direction ="<<massx;
cout<<" center of mass in Y Direction ="<<massy;
cout<<" center of mass in Z Direction ="<<massz;
getch();
}
data.txt
(1,2,3),10
(2,2,4),5
(3,1,2),6
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.