Solved

program for yearly update on salary file

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 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