Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 11-09-2004, 10:36 AM   #1
Member (9 bit)
 
Join Date: Nov 2002
Posts: 502
Pascal S.O.S

I am having problems making these programs in turbo pascal 7.0

Problem 1.

An university knows the number of students joined in the 5 differents careers for the last 10 years. Make a program in pascal that gives the following information:

a: Total students joined per year.

b: Percent of students joined in the year "X" of the career "Y".

c: What year and career had the lower ingress of students.

d: In what year the career "T" had the higher ingress of students.


Problem 2.

An enterprise needs to know the mounts of sales of his offices across the country for the last 14 years. Make a program that calculate the following.

a: Office with higher sales in every year.

b: Prom of sales per year.

c: Year with higher prom of sales.

d: Total sales of the enterprise. (all the sales of the offices for the last 14 years).


Any help will be appreciate.
easg is offline   Reply With Quote
Old 11-10-2004, 07:05 AM   #2
aym
Registered User
 
aym's Avatar
 
Join Date: Nov 2001
Posts: 1,965
So why not show us what you have so far? It would be easier for us to help then.
aym is offline   Reply With Quote
Old 11-10-2004, 10:21 AM   #3
Member (9 bit)
 
Join Date: Nov 2002
Posts: 502
Ok I the part where I am confused is how to read the 10 years and in the ten years read the 5 carrers and the number of students joined for career, If it was only asking the carrer or only the year I wouldn`t have problem because I understand well the arrays, I would use a:


for i:=10 until 10 do

read (year [i]);

once there how do I read the 5 careers without affecting the other part of the questions? I even tried with a counter but it doesn`t work


I don`t have the program now, I will post it later.

The second one is similar n number of offices readed 14 times for the 14 year

I have this one that I did, it is part one the same homework

program defensa8;

{$m $400,0,0}
uses dos;

type

nombre = array [1..10] of string;
sexo = array [1..10] of string;
edad = array [1..10] of integer;
peso = array [1..10] of real;
altura = array [1..10] of real;

var
cma,cha,pm,ph:real;
cm,cf,i:integer;
n:nombre;
s:sexo;
e:edad;
peso;
a:altura;

begin

exec ('\command.com','/c cls');

for i:=1 to 10 do
begin

writeln ('Ingrese los datos del estudiante numero [',i,']:');
write ('Ingrese el nombre: ');
readln (n [i]);
write ('Ingrese el sexo: ');
readln (s [i]);

if (s [i] = 'm') then
begin
cm:=cm+1;
end
else
begin
cf:=cf+1;
end;
write ('Ingrese la edad: ');
readln (e [i]);
write ('Ingrese el peso: ');
readln (p [i]);
write ('Ingrese la altura: ');
readln (a [i]);
end;

for i:=1 to 10 do
begin
if (a [i] >= 1.73) and (p [i] >= 50) and (p [i] <= 83) and (s [i] = 'f') then
begin
writeln ('Mujeres con aptitudes fiscas');
writeln (n [i]);
cma:=cma+1;

end;

if (a [i] >= 1.83) and (p [i] >= 73) and (p [i] <= 105) and (s [i] = 'm') then
begin

writeln ('Hombre con aptitudes fisicas');
writeln (n [i]);
cha:=cha+1;

end
end;
pm:=cma/cf*100;
ph:=cha/cm*100;

writeln ('El porcentaje de mujeres es: ',pm);
writeln ('El porcentaje de hombres es: ',ph);

readln;

end.

It reads the sex name age and high of 10 student, but what if you want to read 10 students for every last 5 years, it would be similar to the others, read the students for the last 5 year n times, where n is the number of the students, this is where I am confused.

Last edited by easg; 11-10-2004 at 11:24 AM.
easg is offline   Reply With Quote
Old 11-11-2004, 08:07 AM   #4
aym
Registered User
 
aym's Avatar
 
Join Date: Nov 2001
Posts: 1,965
You need to use a multi-dimensional array:

Code:
var data : array[1..5][1..10] of integer; total : integer;

  begin

    { read student numbers }
    for carrier := 1 to 5 do
        for year := 1 to 10 do
            readln(data[carrier][year]);

    { total students joined per year }
    for year := 1 to 10 do
      begin
        total := 0;
        for carrier := 1 to 5 do
            total := total + data[carrier][year];
        writeln('total for year ', year, ' is ', total);
      end

  end.
Haven't tried to compile the program, but it looks OK to me, should give you an idea on how to use multi-dimensional arrays.
aym is offline   Reply With Quote
Old 11-11-2004, 08:51 AM   #5
Member (9 bit)
 
Join Date: Nov 2002
Posts: 502
multi-dimensional array? we haven`t seen this theme, that`s why I was lost. you used one single array to store two field the career and the year, but I think that the career must be string because I have to type the name, I will make it this way to see what happens.
easg is offline   Reply With Quote
Old 11-11-2004, 08:58 AM   #6
aym
Registered User
 
aym's Avatar
 
Join Date: Nov 2001
Posts: 1,965
You can use another array for carrier name, something like:
Code:
var carrier_name : array[1..5] of string;
Name of carrier #2 is carrier_name[2].

Last edited by aym; 11-11-2004 at 09:00 AM.
aym is offline   Reply With Quote
Old 11-11-2004, 11:00 AM   #7
Member (9 bit)
 
Join Date: Nov 2002
Posts: 502
Ok I have this, but I have to anwers question b,c and d, this is what I did, but it only displays the results for career 5, I don`t know hot to tell the program which of all data to select at the end to answer these questions, for example What year and career had the lower ingress of students specifically.


program defensa1;

var datos : array [1..5,1..10] of integer;
total, year,carrera,menor,mayor,grantotal:integer;
porcentaje:real;

begin
{Leer el numero de estudiantes}
for year :=1 to 10 do

for carrera:=1 to 5 do
begin
write ('Ingrese el numero de estudiantes ano' ,year,'carrera: ',carrera,': ');
readln (datos[carrera][year]);

{Acumulador general}
grantotal:=grantotal+datos[carrera][year];
end;

{Total de estudiantes matriculados por año}

for year :=1 to 10 do
begin
begin
menor:=menor+datos[carrera][year];
total:= 0;
porcentaje:=1
end;
for carrera:=1 to 5 do
total:=total+datos[carrera][year];
porcentaje:=total/grantotal*100;

{Carrera con menor ingreso de estudiantes}

if (menor > datos[carrera][year]) then
begin
menor:=datos[carrera][year];
end
else
mayor:=mayor+datos[carrera][year];

writeln ('Total por ano', year, 'es: ', total);
writeln ('El porcentaje por ano: ',year,'carrera: ',carrera,' Porcentaje: ',porcentaje:2:2);

end;
writeln ('menor ingreso de la carrera: ',carrera, 'es: ',menor);
writeln ('Mayor ingreso de la carrera: ',carrera, 'es: ',mayor);

readln;
end.
easg is offline   Reply With Quote
Old 11-13-2004, 05:54 AM   #8
aym
Registered User
 
aym's Avatar
 
Join Date: Nov 2001
Posts: 1,965
OK, here, I fixed the problems, I think this is what's required:
Code:
const
 YEAR_COUNT = 10;
 CARRIER_COUNT = 5;

var
 data : array[1..CARRIER_COUNT, 1..YEAR_COUNT] of integer;
 total : integer;
 grand_total : integer;
 year, carrier : integer;
 x, y : integer;
 min, min_year, min_carrier : integer;
 max_student,  max_year, carrier_number : integer;

  begin

    grand_total := 0;

    { read student numbers }
    for carrier := 1 to CARRIER_COUNT do
        for year := 1 to YEAR_COUNT do
          begin
	    writeln('enter student count for carrier ', carrier, ' and year ', year);
            readln(data[carrier][year]);
            grand_total := grand_total + data[carrier][year];
          end;

    { total students joined per year }
    for year := 1 to YEAR_COUNT do
      begin
        total := 0;
        for carrier := 1 to CARRIER_COUNT do
            total := total + data[carrier][year];
        writeln('total for year ', year, ' is ', total);
      end;

    { percent of students joined in the year "X" of the career "Y" }
    for year := 1 to YEAR_COUNT do
        for carrier := 1 to CARRIER_COUNT do
            writeln(
              'percent for year ', year,
              ' and carrier ', carrier,
              ' is ', data[carrier][year] / grand_total * 100
            );
    writeln('enter year');
    readln(x);
    writeln('enter carrier');
    readln(y);
    writeln(
      'percent for year ', x,
      ' and carrier ', y,
      ' is ', data[y][x] / grand_total * 100
    );

    min := data[1][1];
    min_year := 1;
    min_carrier := 1;
    { year and career had the lower ingress of students }
    for year := 1 to YEAR_COUNT do
        for carrier := 1 to CARRIER_COUNT do
            if (min > data[carrier][year]) then
              begin
                min := data[carrier][year];
                min_year := year;
                min_carrier := carrier;
              end;
    writeln('year/carrier with min ingress: ', min_year, '/', min_carrier);

    writeln('enter carrier T number:');
    readln(carrier_number);
    max_student := 0;
    for year := 1 to YEAR_COUNT do
        if (max_student < data[carrier_number][year]) then
	  begin
	    max_student := data[carrier_number][year];
	    max_year := year;
	  end;
    writeln('max year for carrier ', carrier_number, ' is ', max_year);
  end.
If you're going to post code, please use [ CODE ] [/ CODE ] tags
aym is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:11 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2