Solved

Pascal Problem

Posted on 2006-11-22
8
336 Views
Last Modified: 2010-04-16
People from the contest are identified by an id and they get points in diferent chanlenges. Write a pascal problem that reads the result from the contest in pairs (id, points) the end of the pairs will terminate when it meets (0, 0), and print the competitors in decreasing order in function the points they get

0
Comment
Question by:rares_dumitrescu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 17999886
This looks suspiciously like a homework problem.  EE experts can help you with specific questions but will not write the program for you.

Please post the code you have thus far and ask a specific question.

mlmcc
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 18000542
If you don't have any code post a word algorithm and what you think the data and functions will be.

mlmcc
0
 
LVL 10

Expert Comment

by:For-Soft
ID: 18001363
The first decision would be, how to store the (ID,Score) pairs before sorting and printing them.

I see 2 choices, in a table, or in a list of records or objects.

The table has a maximum size limit, while the list of records is limited by available memory (but pointer operations skill is needed).

Table is a simpler solution, of course.
0
[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

 

Author Comment

by:rares_dumitrescu
ID: 18002330
type concurent=record
     id,proba,punctaj:integer;
     end;

type concurenti=array[1..100] of concurent;
var records:concurenti;
    n,i:integer;


procedure writerecord(records:concurenti;n:integer);
          var i:integer;
          begin
          for i:=1 to n do
              writeln('Numar concurs: ', records[i].id, '; Proba: ', records[i].proba, '; Nota: ', records[i].punctaj, ';');
          end;

procedure readrecord(var records:concurenti;var n:integer);
          var id,proba,punctaj:integer;
          begin
          read(id,proba,punctaj);
          n:=0;
          while (id<>0) or (proba<>0) or (punctaj<>0) do
                begin
                n:=n+1;
                records[n].id := id;
                records[n].proba := proba;
                records[n].punctaj := punctaj;
                read(id,proba,punctaj);

                end;
          end;


procedure sortrecordpunctaj(var records:concurenti;n:integer);
          var i,j:integer;
              tmp:concurent;
          begin
          for i:=1 to n do
              for j:=1 to n-1 do
                  if records[j].punctaj < records[j+1].punctaj then
                     begin
                     tmp:= records[j];
                     records[j] := records[j + 1];
                     records[j + 1] := tmp;
                     end;
          end;





begin
readrecord(records,n);
sortrecordpunctaj(records,n);
writerecord(records,n);
end.
0
 
LVL 6

Expert Comment

by:My name is Mud
ID: 18002748
I have tested your code and seems to be working... what seems to be the problem???
0
 
LVL 10

Accepted Solution

by:
For-Soft earned 500 total points
ID: 18003999
After a first look, I see no reason to pass variables "records" and "n" to every procedure.

All procedures are declared below the variables declaration:
var records:concurenti;
    n,i:integer;

So, the variables "records" and "n" are declared as global variables, and there is no need to pass them to the procedures.

If you declare a variable in some point, all code and procedures declared after that point will be in scope of the declaration of the variable. Means: variable declared globaly is available in all procedures declared after the global declaration.

So, a program like this will work, as well.

type concurent=record
     id,proba,punctaj:integer;
     end;

type concurenti=array[1..100] of concurent;
var records:concurenti;
    n,i:integer;


procedure writerecord;
          var i:integer;
          begin
          for i:=1 to n do
              writeln('Numar concurs: ', records[i].id, '; Proba: ', records[i].proba, '; Nota: ', records[i].punctaj, ';');
          end;

procedure readrecord;
          var id,proba,punctaj:integer;
          begin
          read(id,proba,punctaj);
          n:=0;
          while (id<>0) or (proba<>0) or (punctaj<>0) do
                begin
                n:=n+1;
                records[n].id := id;
                records[n].proba := proba;
                records[n].punctaj := punctaj;
                read(id,proba,punctaj);

                end;
          end;


procedure sortrecordpunctaj;
          var i,j:integer;
              tmp:concurent;
          begin
          for i:=1 to n do
              for j:=1 to n-1 do
                  if records[j].punctaj < records[j+1].punctaj then
                     begin
                     tmp:= records[j];
                     records[j] := records[j + 1];
                     records[j + 1] := tmp;
                     end;
          end;





begin
readrecord;
sortrecordpunctaj;
writerecord;
end.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 18004153
Remember his is probably a school assignment so he has to follow the rules set down by the instructor.

The reason to pass the data to the procedures and functions is because they are being taught to do it that way.  It would be better to pass pointers but they haven't gotten to them yet.

Also a function or procedure should stand on its own rather than relying on the using program to provide the data and properly named.  In that way a procedure can be reused in another program.

mlmcc
0
 
LVL 10

Expert Comment

by:For-Soft
ID: 18004222
Perhaps you are right.

But, I learned to preserve as much of the processor stack, as possible. It is a very useful habit when programming in Pascal.

Other cleaning proposition is to remove the global declaration of the variable "i". As, it is declared in every proper procedure.

So,:

var records:concurenti;
    n:integer;

instead of:

var records:concurenti;
    n,i:integer;
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Let’s face it: one of the reasons your organization chose a SaaS solution (whether Microsoft Dynamics 365, Netsuite or SAP) is that it is subscription-based. The upkeep is done. Or so you think.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question