Здравствуйте. Очень нужна ваша помощь- перевести этот код из паскаля на с++. uses CRT;const n=10;type Vector=array [1..n] of integer;var mas:Vector; m,q:Byte; procedure vivod(var A:Vector);var i:integer;begin writeln('Initial array:'); for i:=1 to n do write(A:5); writeln;end; procedure vvod_ruchnoi(var A:Vector);var i:integer;begin for i:=1 to n do begin write('A[', i, ']= '); readln(a); end; writeln; vivod(A);end; procedure vvod_random(var A:Vector);var i:integer;begin Randomize; for i:=1 to n do A:=-10+Random(21); vivod(A);end; procedure zadacha1(var A:Vector);var i,k: integer; sum: real;begin vivod(A); i:=0; k:=0; Sum:=0; repeat i:=i+1; if A<0 then begin Sum:=Sum+A; k:=k+1; end; until (A>0) or (i=n); if k>0 then Writeln('Arithmetic mean is ',Sum/k:0:3) else Writeln('No such elements!');end; procedure zadacha2(var A:Vector);var B,C: Vector; i,Imin,Imax,Min,Max,n1,n2: integer;begin vivod(A); B:=A; Max:=B[1]; for i:=2 to n do if B>Max then Max:=B; i:=0; repeat i:=i+1; until B=Max; Imax:=i; If Imax=n then begin Writeln('First maximal element is the last one!'); n1:=n; end else If Imax=n-1 then n1:=n-1 else begin for i:=Imax+2 to n do B[i-1]:=B; n1:=n-1; end; C:=B; Min:=C[1]; for i:=2 to n1 do if C<Min then Min:=C; i:=0; repeat i:=i+1; until C=Min; Imin:=i; If Imin=n1 then begin Writeln('First minimal element is the last one!'); n2:=n1; end else If Imin=n1-1 then n2:=n1-1 else begin for i:=Imin+2 to n1 do C[i-1]:=C; n2:=n1-1; end; Writeln('New array:'); For i:=1 to n2 do write(C:5); writeln;end; procedure zadacha3(var A:Vector);var i,Izero:integer; B:Array[1..n+2] of integer;begin vivod(A); for i:=1 to n do B:=A; i:=n+1; repeat i:=i-1; until (A=0) or (i=1); if (i=1) and (A<>0) then writeln('No zero elements!') else begin Izero:=i; if Izero=n then begin B[n+1]:=0; B[n+2]:=0; end else begin for i:=n downto Izero+1 do B[i+2]:=A; B[Izero+1]:=0; B[Izero+2]:=0; end; Writeln('New array:'); for i:=1 to n+2 do write(B:5); end; writeln;end; procedure zadacha4(var A:Vector);var i: integer; p: boolean;begin vivod(a); p:=true; for i:=1 to n-1 do if a>a[i+1] then p:=false; Writeln(p);end; Begin ClrScr; Repeat WriteLn; repeat WriteLn('Elements entering metod:'); WriteLn(' 1 - console'); WriteLn(' 2 - random'); WriteLn(' 3 - exit'); Readln(m); until (m>0) and (m<4); if m<3 then begin if m=1 then vvod_ruchnoi(mas); if m=2 then vvod_random(mas); repeat Writeln; WriteLn('Chooze the task:'); WriteLn(' 1 - Arithmetic mean'); WriteLn(' 2 - Excluding of elements'); WriteLn(' 3 - Inserting zeroes'); WriteLn(' 4 - Test of ordering'); WriteLn(' 5 - Exit'); Readln(q); if (q=0) or (q>5) then q:=5; Case q of 1: zadacha1(mas); 2: zadacha2(mas); 3: zadacha3(mas); 4: zadacha4(mas); End; until q=5; end; Until m=3;End. с уважением.
будь на моей стороне.
|
|
|