Solved

program for yearly update on salary file

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi TClientDataSet - override Refresh event 4 748
detect keyboard input monitoring 3 390
Delphi Skype API 2 1,727
find a node in VST 2 47
Moving applications to the cloud or switching services to cloud-based ones, is a stressful job.  Here's how you can make it easier.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now