[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

search a record and display result.

Posted on 2000-02-25
7
Medium Priority
?
238 Views
Last Modified: 2010-04-16
HERE IS THE PROCEDURE I NEED HELP WITH.

[1] I NEED TO ASK FOR A CUSTOMER NUMBER AND THEN SEARCH  THE FILE CUSFILE,CUSTOMER.DAT     WHERE THE INFO IS STORED THEn DISPLAY APPROPRIATE INFO i.e. name address. . then store it to orderfile.

[2] THE CUSFILE,CUSTOMER.DAT WERE MADE USING THE SAME FORMAT AS THIS, I CAN SCROLL THROUGH THE RECORDS BUT CAN'T PICK OUT INDIVIDUAL ONES IN A SEARCH.


        PROCEDURE Order;

        type
         ORDER    = record
                           GETDATE  ;
         CUST_NUM         :INTEGER;                    
         CUST_NAME        : string[20];
         CUST_address     : string[40];
         COSTUME_NUMBER   :INTEGER;
         COSTUME_DESC     :STRING;
         QUANTITY         :INTEGER;
         LOH              :STRING;
         RETURNDATE       :STRING;
         DELIVERY         :CHAR;

               end;

var
   ORDERFILE : file of ORDER;
   c : char;
   X : ORDER;

   n : integer;
begin




   assign(ORDERFILE,'ORDER.DAT');           { Associate it }
   {$I-}
      reset(ORDERFILE);           { First, open it }
   {$I+}

   n:=IOResult;
   if n<>0 then           { If it's doesn't exist then }
   begin
      {$I-}
         rewrite(ORDERFILE);      { Create it    }
      {$I+}
      n:=IOResult;
      if n<>0 then
      begin
         writeln('Error creating file !'); halt;
      end;
   end
   else
   begin                  { If it exists then }
      n:=filesize(ORDERFILE);     { Calculate total record }
      seek(ORDERFILE,N);          { Move file pointer PAST the last record }
   end;

   repeat

      writeln('File position : ',filepos(ORDERFILE));
      WRITELN;
      WRITELN;
      write('DATE IS              = '); readln(X.DATE);     { Input data }
      write('CUSTOMER NUMBER      = '); readln(number);
      ???

      write('CUSTOMER NAME IS     = '); readln(X.CUST_NAME);
      write('CUSTOMER ADRESS IS   = '); readln(x.cust_address);
      write('ENTER COSTUME NUMBER = '); READLN(x.COSTUME_NUMBER);
      WRITE('COSTME DESC IS       = '); READLN(X.COSTUME_DESC);
      WRITE('ENTER QUANTITY       = '); READLN (X.QUANTITY);
      WRITE('LOH                  = '); READLN(X.LOH);
      WRITE('RETURN DATE          = '); READLN(X.RETURNDATE);
      WRITE('DELIVERY Y OR N      = '); READLN(X.DELIVERY);



      write(ORDERFILE,X);                 { Write data to file }

      write('Input data again (Y/N) ?');
      repeat
         c:=upcase(readkey);      { Ask user : Input again or not }
      until c in ['Y','N'];
      writeln(c);
   until c='N';

   close(ORDERFILE);
end;

END.
0
Comment
Question by:elniniokev
[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
  • 5
7 Comments
 
LVL 1

Expert Comment

by:bakry99
ID: 2562378
Hi try this

function Search(Index: integer; var Result: Order): boolean;
{Search a record by Index(Cust_Num) if found then function return true and info in the "Result" , if not found then return False}
var
  Temp: Order;
  Found: Boolean;
begin
  reset(orderfile);
  Found := False;
  while (not eof(OrderFile))and(not Found) do
    begin
       read(orderfile,Temp);
       if index = Temp.Cust_Num then
       begin            
          Found := True;
          Result := Temp;      
       end;  
    end;
   Search := Found;
   Close(OrderFile);
end;{Of function}


{and you may call it like this}
var
 x: Order;
 n: integer;
begin
Write('Input Customer Number to Search for: ');
readln(n);
if Search(n, x) then
 Begin
   {Write the field of x}
 end
else
  Writeln('search record not found');
end.
0
 
LVL 1

Expert Comment

by:bakry99
ID: 2562386
Hi try this

function Search(Index: integer; var Result: Order): boolean;
{Search a record by Index(Cust_Num) if found then function return true and info in the "Result" , if not found then return False}
var
  Temp: Order;
  Found: Boolean;
begin
  reset(orderfile);
  Found := False;
  while (not eof(OrderFile))and(not Found) do
    begin
       read(orderfile,Temp);
       if index = Temp.Cust_Num then
       begin            
          Found := True;
          Result := Temp;      
       end;  
    end;
   Search := Found;
   Close(OrderFile);
end;{Of function}


{and you may call it like this}
var
 x: Order;
 n: integer;
begin
Write('Input Customer Number to Search for: ');
readln(n);
if Search(n, x) then
 Begin
   {Write the field of x}
 end
else
  Writeln('search record not found');
end.
0
 
LVL 1

Expert Comment

by:bakry99
ID: 2562394
Hi try this

function Search(Index: integer; var Result: Order): boolean;
{Search a record by Index(Cust_Num) if found then function return true and info in the "Result" , if not found then return False}
var
  Temp: Order;
  Found: Boolean;
begin
  reset(orderfile);
  Found := False;
  while (not eof(OrderFile))and(not Found) do
    begin
       read(orderfile,Temp);
       if index = Temp.Cust_Num then
       begin            
          Found := True;
          Result := Temp;      
       end;  
    end;
   Search := Found;
   Close(OrderFile);
end;{Of function}


{and you may call it like this}
var
 x: Order;
 n: integer;
begin
Write('Input Customer Number to Search for: ');
readln(n);
if Search(n, x) then
 Begin
   {Write the field of x}
 end
else
  Writeln('search record not found');
end.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:bakry99
ID: 2562398
Hi try this

function Search(Index: integer; var Result: Order): boolean;
{Search a record by Index(Cust_Num) if found then function return true and info in the "Result" , if not found then return False}
var
  Temp: Order;
  Found: Boolean;
begin
  reset(orderfile);
  Found := False;
  while (not eof(OrderFile))and(not Found) do
    begin
       read(orderfile,Temp);
       if index = Temp.Cust_Num then
       begin            
          Found := True;
          Result := Temp;      
       end;  
    end;
   Search := Found;
   Close(OrderFile);
end;{Of function}


{and you may call it like this}
var
 x: Order;
 n: integer;
begin
Write('Input Customer Number to Search for: ');
readln(n);
if Search(n, x) then
 Begin
   {Write the field of x}
 end
else
  Writeln('search record not found');
end.
0
 
LVL 1

Expert Comment

by:bakry99
ID: 2562401
Sorry i submited it more than one time but the internet here is not work better
:).
0
 
LVL 3

Accepted Solution

by:
sumant032199 earned 150 total points
ID: 2562905
Have a look at this code.
program customer100;
uses crt;

type customer = record
         name : string[15];
         number : integer;
         { as many more you want}
     end;
     custfile = file of customer;

var custrecord : custfile;
    cust1 : customer;
    n : integer;

procedure lastwait;
begin
     writeln;
     write('Press any key to continue....');
     readkey;
end;

procedure  create_customer_database;
var   A_file : file of customer;
      cust : customer;
      c : char;
begin
      assign(A_file,'CUSTOMER.DAT');
      reset(A_file);
      seek(A_file,filesize(A_file));
      writeln;
      write('Enter Customers'' database: ');
      repeat
            writeln;
            write('Enter name: ');
            read(cust.name);
            write('Enter number: ');
            readln(cust.number);
            write(A_file,cust);

            writeln;
            write('Enter more (y/n)? ');
            c:=readkey;
      until c in ['n','N'];
      close(A_file);
end;
procedure search_and_store(n : integer);
var storefile,searchfile : file of customer;
    cust2 : customer;
begin
    writeln;
    assign(searchfile,'CUSTOMER.DAT');
    reset(searchfile);

    write('Searching information...');
    while not eof(searchfile) do
    begin
        read(searchfile,cust2);
        if cust2.number = n then
        begin
           writeln('Search complete and successful.');
           break;
        end
        else
        begin
             write('.');
        end;
    end;
    close(searchfile);
    writeln;
    if cust2.number <> n then writeln('Search complete but no match found.')
    else
    begin
         writeln('Search Results: ');
         writeln('Name of customer: ',cust2.name);
         writeln('Number of customer: ',cust2.number);

         assign(storefile,'ORDER.DAT');
         reset(storefile);
         seek(storefile,filesize(storefile));

         write(storefile,cust2);
    end;
end;

begin
    create_customer_database; { in CUSTOMER.DAT file }
    writeln;
    write('Enter customer number: ');
    read(n);
    search_and_store(n);      { in ORDER.DAT file }






    lastwait;
end.
0
 
LVL 49

Expert Comment

by:dbrunton
ID: 2564049
{

ERE IS THE PROCEDURE I NEED HELP WITH.

[1] I NEED TO ASK FOR A CUSTOMER NUMBER AND THEN SEARCH  THE FILE
CUSFILE, CUSTOMER.DAT     WHERE THE INFO IS STORED THE DISPLAY APPROPRIATE INFO i.e.
name address. . then store it to orderfile.

[2] THE CUSFILE,CUSTOMER.DAT WERE MADE USING THE SAME FORMAT AS THIS, I CAN
SCROLL THROUGH THE RECORDS BUT CAN'T PICK OUT INDIVIDUAL ONES IN A SEARCH.


The coding here needs tidying up.  Run it and try it.  
}

program doit;
uses crt;

type
  ORDERTYPE    = record
    DATE : string[20];
    CUST_NUM         :INTEGER;
    CUST_NAME        : string[20];
    CUST_address     : string[40];
    COSTUME_NUMBER   :INTEGER;
    COSTUME_DESC     :STRING;
    QUANTITY         :INTEGER;
    LOH              :STRING;
    RETURNDATE       :STRING;
    DELIVERY         :CHAR;
end;

var
  ORDERFILE : file of ORDERTYPE;
  c : char;
  X : ORDERTYPE;
  n : integer;
  cusno : integer;
  recordfound : integer;

PROCEDURE Order;
begin
  assign(ORDERFILE, 'ORDER.DAT');           { Associate it }
  {$I-}
  reset(ORDERFILE);           { First, open it }
  {$I+}
  n := IOResult;
  if n <> 0 then           { If it's doesn't exist then }
    begin
    {$I-}
      rewrite(ORDERFILE);      { Create it    }
     {$I+}
      n := IOResult;
      if n <> 0 then
        begin
          writeln('Error creating file !'); halt;
        end;
    end
  else
    begin                  { If it exists then }
      n := filesize(ORDERFILE);     { Calculate total record }
      seek(ORDERFILE,N);          { Move file pointer PAST the last record }
    end;
  repeat
    writeln('File position : ',filepos(ORDERFILE));
    WRITELN;
    WRITELN;
    write('DATE IS              = '); readln(X.DATE);     { Input data }
    write('CUSTOMER NUMBER      = '); readln(X.CUST_num);
    write('CUSTOMER NAME IS     = '); readln(X.CUST_NAME);
    write('CUSTOMER ADRESS IS   = '); readln(x.cust_address);
    write('ENTER COSTUME NUMBER = '); READLN(x.COSTUME_NUMBER);
    WRITE('COSTME DESC IS       = '); READLN(X.COSTUME_DESC);
    WRITE('ENTER QUANTITY       = '); READLN (X.QUANTITY);
    WRITE('LOH                  = '); READLN(X.LOH);
    WRITE('RETURN DATE          = '); READLN(X.RETURNDATE);
    WRITE('DELIVERY Y OR N      = '); READLN(X.DELIVERY);
    write(ORDERFILE, X);                 { Write data to file }
    write('Input data again (Y/N) ?');
    repeat
      c:=upcase(readkey);      { Ask user : Input again or not }
    until c in ['Y','N'];
    writeln(c);
  until c='N';
  close(ORDERFILE);
end;

procedure show;
begin
  reset(orderfile);
  while not eof(orderfile) do
  begin
    read(orderfile, x);
    writeln(x.date);
    writeln(x.cust_num);
    writeln(x.cust_name);
    writeln(x.cust_address);
  end;
end;

procedure searchforcusno(no : integer);
var
  whichrecord : integer;
begin
  reset(orderfile);
  recordfound := 0;
  whichrecord := 0;
  while not eof(orderfile) do
  begin
    read(orderfile, x);
    if x.cust_num = no then
      recordfound := whichrecord;
    inc(whichrecord);
  end;
end;

procedure findandshowrecord(no : integer);
var
  recordno : integer;
begin
  reset(orderfile);
  recordno := 0;
  while not eof(orderfile) do
  begin
    read(orderfile, x);
    if recordno = no then
      writeln(x.cust_num);
    inc(recordno);
  end;
end;

begin
  Order;
  show;
  writeln('What customer number do you want?');
  readln(cusno);
  searchforcusno(cusno);
  if recordfound <> 0 then
    findandshowrecord(recordfound);
END.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Ransomware, the malware that locks down its victim’s files until they pay up, has always been a frustrating issue to deal with. However, a recent mobile ransomware will make the issue a little more personal… by sharing the victim’s mobile browsing h…
While there are many new features for iOS 11, these are the five that can improve your digital lifestyle.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

649 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