Solved

program for yearly update on salary file

Posted on 2000-02-28
3
310 Views
Last Modified: 2010-04-16
I need a program that will perform a yearly update on a salary file.  Each data group in the file contains an employee's name, wage, and years worked. At the end of each year, the year must first be incremented by 1 and then given a raise. If the employee has been with the firm for at least 10 years, the employee receives a weekly salary increase of $30; otherwise, raise is only $15.

Here is my code:

program salary;
uses printer;
var name: string;
   SalaryFile1, SalaryFile2:text;
   years, wage, raise: integer;

begin
  assign (SalaryFile1, 'salary.dat');
  assign (SalaryFile2, 'salary2.dat');
  reset (SalaryFile2);
    while not seekeof (SalaryFile1) do
       begin {while}
          readln (SalaryFile1, name);
          readln (SalaryFile1, wage);
          readln (SalaryFile1, years);
       years := years + 1;
          if years >= 10 then
              raise := $30 + years
          else raise := $15 + years
        writeln (SalaryFile2, name);
        writeln (SalaryFile2, wage);
        writeln (SalaryFile2, years);
      end;{while}
   close (SalaryFile1);
   close (SalaryFile2);
end.




0
Comment
Question by:kazooie21
3 Comments
 
LVL 1

Expert Comment

by:Binder
ID: 2568355
  Actually you must use records to do this.

  For example:

   employee: record
       name: string[40];
       wage: real;
       years: integer;
   end;

   and then you must read and write with the commands read and
write. Readln and Writeln are just for text files. Also you are not
opening your first file. Since you are readind from it you should use
reset. The second file is being used for write, so you must use
rewrite to open it. Rewrite destroy previous contents of the file and
opens the file for writing. If you need more info just ask.
0
 
LVL 1

Expert Comment

by:nrico
ID: 2568926
If you use the record way (which is better, by the way), you should declare your file as:

Var
  F: File Of Employee;

(Assuming your record name is "Employee")
0
 
LVL 3

Accepted Solution

by:
sumant032199 earned 30 total points
ID: 2569613
{I am extending his idea and giving you a complete working program.}

program salary;
uses crt;

type employee = record
       name : string[40];
       wage : real;
       years : integer;
     end;
     employee_database = file of employee;
var emp1 : employee;
    emp_file_read,emp_file_write : employee_database;
procedure generate_database;
var    c : char;
begin
    repeat
       writeln;
       write('Enter name: ');
       readln(emp1.name);
       write('Enter wages: ');
       readln(emp1.wage);
       write('Enter years: ');
       readln(emp1.years);

       write(emp_file_read,emp1);

       write('Do you want to enter more (Y/N)? ');
       c := readkey;
       c := upcase(c);
    until c = 'N';

end;
procedure update_database;
begin
     while not eof(emp_file_read) do
     begin
          read(emp_file_read,emp1);
          emp1.years := emp1.years + 1;
          if emp1.years >= 10 then  emp1.wage := emp1.wage + 30
                              else  emp1.wage := emp1.wage + 15;

          write(emp_file_write,emp1);
     end;
end;
begin
     clrscr;

     assign(emp_file_read,'READDATA.DAT');
     assign(emp_file_write,'WRITDATA.DAT');
     reset(emp_file_read);
     rewrite(emp_file_write);

     {If you are running for the first time then }
     {generate_database;}
     update_database;
     { Now you have to rename WRITDATA.DAT to READDATA.DAT }
     close(emp_file_read);
     close(emp_file_write);

     Erase(emp_file_read);
     rename(emp_file_write,'READDATA.DAT');

     if IOResult <> 0 then
     begin
           writeln;
           write('Some error occured.');
     end;
end.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi ADO query as a string 4 2,690
SetWindowsHookEx capturing unicode (universal) characters ? 1 1,813
USB Flash Drive Serial Numbers 9 4,031
Utf8 encode 2 591
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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