Solved

program for yearly update on salary file

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

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

The world seems to conceive of a curious bubble separating IT from “the business.”  More so than just about any other pursuit in the commercial world, people think of IT as some kind of an island.
Read the original post on Monitis Blog. Believe it or not, the most important thing about the website of your business is not what’s on it but how fast it loads. Yes, that’s right!    As you can see on this infographic (an oldie but goodie!), …
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…

726 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