|
LIMBAJUL DE PROGRAMARE PASCAL – program statistica
Folosind tipul de date înregistrare ?i considerând un e?antion social de maximum 200 persoane, s? se efectueze calculele statistice în vederea afi??rii la terminalul de ie?ire a urm?toarelor informa?ii :
- procentul de persoane având vârsta sub 18 ani;
- procentul de persoane având vârsta între 18 ?I 62 de ani;
- procentul de persoane având vârsta peste 62 de ani;
- în?l?imea medie a b?rba?ilor între 18 ?i 30 ani;
procentul persoanelor c?s?torite.
program statistica;
CONST
nr_max = 200;
nec?s?torit = 1;
c?s?torit = 2;
divor?at = 3;
vaduv = 4;
TYPE
persoana = record
vârst?:integer;
înal?ime:integer;
statut:integer;
sex:boolean;
end;
e?antion = array[1..nr_max] of persoana;
data_file = file of persoana;
VAR
es,esm:e?antion;
nr,nrm:integer;
i,nr_barbati:integer;
suma,m:real;
nume_fis:string;
p:real;
PROCEDURE read_data( from:string; var nr:integer;var buff:e?antion );
var
f:data_file;
c:char;
date:persoana;
i:integer;
begin
assign(f,from);
reset(f);
if IOresult<>0 then
begin
writeln('Eroare la deschiderea fi?ierului',from);
write ('Apasati o tasta pentru a opri programul: ');
halt;
end;
i:=1;
while not (eof(f)) do
begin
read(f,date);
buff[i]:=date;
inc(i);
end;
nr:=i-1;
close(f);
if nr=0 then
begin
writeln('Vectorul de date este vid. Program oprit. ');
halt;
end;
end;
FUNCTION c?s?toriti (n:integer;e:e?antion) : real;
var
i:integer;
nc:integer;
begin
nc:=0;
for i:=1 to n do
if e[i].statut=c?s?torit then
inc(nc);
c?s?toriti:=nc/n;
end;
FUNCTION selecteaz?_dup?_vârst?(n:integer; e:e?antion; lim_inf, lim_sup:integer;
var nsel:integer; var sel:e?antion) : real;
var
nv:integer;
i:integer;
begin
nv:=0;
for i:=1 to nr_max do
with sel[i] do
begin
vârst?:=0;
înal?ime:=0;
statut:=0;
end;
for i:=1 to n do
if (e[i].vârst? > lim_inf) and (e[i].vârst? < lim_sup) then
begin
inc(nv);
sel[nv]:=e[i];
end;
nsel:=nv;
selecteaz?_dup?_vârst?:=nv/n;
end; |