Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- TArray = array of Double;
- function GetArraySize(): Integer;
- begin
- Writeln('Введите количество точек');
- Readln(Result);
- end;
- function GetIntArray(Size: Integer; MainMsg, ElementName: String): TArray;
- var
- I: Integer;
- begin
- SetLength(Result, Size);
- Writeln(MainMsg);
- for I := 0 to High(Result) do
- begin
- Write(ElementName + '[' + IntToStr(I) + '] = ');
- Readln(Result[I]);
- end;
- end;
- function GetArraySum(Arr: TArray): Double;
- var
- I: Integer;
- begin
- Result := 0;
- for I := 0 to High(Arr) do
- Result := Result + Arr[I];
- end;
- function Get2ArrSum(Arr1, Arr2: TArray): Double;
- var
- I: Integer;
- begin
- Result := 0;
- for I := 0 to High(Arr1) do
- Result := Result + (Arr1[I] * Arr2[I]);
- end;
- var
- XArr, YArr, MArr: TArray;
- Mass, Xc, Yc: Double;
- Size: Integer;
- var
- OutputFile: TextFile;
- begin
- Size := GetArraySize();
- XArr := GetIntArray(Size, 'Введите массив координат X точек', 'x');
- YArr := GetIntArray(Size, 'Введите массив координат Y точек', 'y');
- MArr := GetIntArray(Size, 'Введите массив масс M', 'm');
- Mass := GetArraySum(MArr);
- Xc := Get2ArrSum(XArr, MArr) / Mass;
- Yc := Get2ArrSum(YArr, MArr) / Mass;
- AssignFile(OutputFile, 'output.txt');
- Rewrite(OutputFile);
- Writeln('Координаты центра масс (', Xc:0:3, ';', Yc:0:3, ')');
- Writeln(OutputFile, 'Координаты центра масс (', Xc:0:3, ';', Yc:0:3, ')');
- CloseFile(OutputFile);
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement