Solved

program for yearly update on salary file

Posted on 2000-02-28
3
304 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to resolve an IP Address to a host name 6 1,687
VB.Net code to pascal 1 396
Delphi TClientDataSet - override Refresh event 4 765
Kind of encoding 3 425
How do we balance the user experience (UX) with reasonable security measures? It can be done, if you keep these fundamentals in mind.
When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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