How can I complete this? VERY STUCK :(

program cw2;

{$APPTYPE CONSOLE}

uses
SysUtils;

type
// You have to create your own data types.
// This template uses a data type called Tstaff which is the employees DB
// This program does not compile because the data tyoe Tstaff has not been declared

{PRE: true}
{POST: fill the DB with the data of 10 employees}
procedure create_DB(var staff:Tstaff);
begin
end;

{PRE: staff non empty }
{POST if employee name found his/her address, telephone, position
is displayed
else error message}
procedure find_employee(staff:Tstaff;name:string);
begin
end;

{PRE: staff non empt}
{POST: displays all the imformation stored in the DB}
procedure display(staff:Tstaff);
begin
end;

{PRE: staff non empty }
{POST if employee name found user is asked for new salary and modified in DB
else error message}
procedure change_salary(var staff:Tstaff; name:string);
begin
end;

{PRE: staff non empty }
{POST all the employees names with this position are displayed}
procedure post_emp(staff:Tstaff;post:string);
begin
end;


var
staff:Tstaff;
option:integer;
name,post:string;
begin

create_DB(staff);
option:=1;
writeln('Welcome to XXX Company');
while option <> 0 do
begin
writeln('You have the following options');
writeln('1: Find data about an employee');
writeln ('2: Change an employee salary');
writeln('3: Display all the employees');
writeln('4: The names of the employees doing a specific job');
writeln ('0 to quit');
readln(option);
case option of
1: begin
write('Introduce name of employee: ');
readln(name);
find_employee(staff,name);
end;
2: begin
write('Introduce name of employee: ');
readln(name);
change_salary(staff,name);
end;
3: display(staff);
4: begin
write('Introduce a post in your company: ');
readln(post);
post_emp(staff,post);
end;
0: writeln ('Thank your for using our software');
else
writeln('Wrong option please try again');
end;
end;
readln;

end.

Comments

  • : program cw2;
    :
    : {$APPTYPE CONSOLE}
    :
    : uses
    : SysUtils;
    :
    : type
    : // You have to create your own data types.
    : // This template uses a data type called Tstaff which is the employees DB
    : // This program does not compile because the data tyoe Tstaff has not been declared
    :
    : {PRE: true}
    : {POST: fill the DB with the data of 10 employees}
    : procedure create_DB(var staff:Tstaff);
    : begin
    : end;
    :
    : {PRE: staff non empty }
    : {POST if employee name found his/her address, telephone, position
    : is displayed
    : else error message}
    : procedure find_employee(staff:Tstaff;name:string);
    : begin
    : end;
    :
    : {PRE: staff non empt}
    : {POST: displays all the imformation stored in the DB}
    : procedure display(staff:Tstaff);
    : begin
    : end;
    :
    : {PRE: staff non empty }
    : {POST if employee name found user is asked for new salary and modified in DB
    : else error message}
    : procedure change_salary(var staff:Tstaff; name:string);
    : begin
    : end;
    :
    : {PRE: staff non empty }
    : {POST all the employees names with this position are displayed}
    : procedure post_emp(staff:Tstaff;post:string);
    : begin
    : end;
    :
    :
    : var
    : staff:Tstaff;
    : option:integer;
    : name,post:string;
    : begin
    :
    : create_DB(staff);
    : option:=1;
    : writeln('Welcome to XXX Company');
    : while option <> 0 do
    : begin
    : writeln('You have the following options');
    : writeln('1: Find data about an employee');
    : writeln ('2: Change an employee salary');
    : writeln('3: Display all the employees');
    : writeln('4: The names of the employees doing a specific job');
    : writeln ('0 to quit');
    : readln(option);
    : case option of
    : 1: begin
    : write('Introduce name of employee: ');
    : readln(name);
    : find_employee(staff,name);
    : end;
    : 2: begin
    : write('Introduce name of employee: ');
    : readln(name);
    : change_salary(staff,name);
    : end;
    : 3: display(staff);
    : 4: begin
    : write('Introduce a post in your company: ');
    : readln(post);
    : post_emp(staff,post);
    : end;
    : 0: writeln ('Thank your for using our software');
    : else
    : writeln('Wrong option please try again');
    : end;
    : end;
    : readln;
    :
    : end.
    :
    :
    Create an array of records called TStaff. In each record you need to declare the necessary fields.
    In CreateDB() fill each record in that array with the necessary info.
    In find_employee() loop through the array and if you find the matching name, then show that record.
    In display() loop though the array and write the data of each record.
    In change_salary() loop though the array, and if you find the correct staff record, then ask the user for the new salary and change the correct field.
    In post_emp() loop through the array and write each record with the matching post.

    As you can see from my comments here, nearly everything is a loop with an if-then statement inside it. An array of records is the easiest data structure. More complex structures include array of objects, linked lists (record-based or object-based), binary trees (record-based or object-based), hash table, etc.
  • If anyone minds doing this for me i don't mind paypalling them some cash :)

    Thanks for help dude.

    : : program cw2;
    : :
    : : {$APPTYPE CONSOLE}
    : :
    : : uses
    : : SysUtils;
    : :
    : : type
    : : // You have to create your own data types.
    : : // This template uses a data type called Tstaff which is the employees DB
    : : // This program does not compile because the data tyoe Tstaff has not been declared
    : :
    : : {PRE: true}
    : : {POST: fill the DB with the data of 10 employees}
    : : procedure create_DB(var staff:Tstaff);
    : : begin
    : : end;
    : :
    : : {PRE: staff non empty }
    : : {POST if employee name found his/her address, telephone, position
    : : is displayed
    : : else error message}
    : : procedure find_employee(staff:Tstaff;name:string);
    : : begin
    : : end;
    : :
    : : {PRE: staff non empt}
    : : {POST: displays all the imformation stored in the DB}
    : : procedure display(staff:Tstaff);
    : : begin
    : : end;
    : :
    : : {PRE: staff non empty }
    : : {POST if employee name found user is asked for new salary and modified in DB
    : : else error message}
    : : procedure change_salary(var staff:Tstaff; name:string);
    : : begin
    : : end;
    : :
    : : {PRE: staff non empty }
    : : {POST all the employees names with this position are displayed}
    : : procedure post_emp(staff:Tstaff;post:string);
    : : begin
    : : end;
    : :
    : :
    : : var
    : : staff:Tstaff;
    : : option:integer;
    : : name,post:string;
    : : begin
    : :
    : : create_DB(staff);
    : : option:=1;
    : : writeln('Welcome to XXX Company');
    : : while option <> 0 do
    : : begin
    : : writeln('You have the following options');
    : : writeln('1: Find data about an employee');
    : : writeln ('2: Change an employee salary');
    : : writeln('3: Display all the employees');
    : : writeln('4: The names of the employees doing a specific job');
    : : writeln ('0 to quit');
    : : readln(option);
    : : case option of
    : : 1: begin
    : : write('Introduce name of employee: ');
    : : readln(name);
    : : find_employee(staff,name);
    : : end;
    : : 2: begin
    : : write('Introduce name of employee: ');
    : : readln(name);
    : : change_salary(staff,name);
    : : end;
    : : 3: display(staff);
    : : 4: begin
    : : write('Introduce a post in your company: ');
    : : readln(post);
    : : post_emp(staff,post);
    : : end;
    : : 0: writeln ('Thank your for using our software');
    : : else
    : : writeln('Wrong option please try again');
    : : end;
    : : end;
    : : readln;
    : :
    : : end.
    : :
    : :
    : Create an array of records called TStaff. In each record you need to declare the necessary fields.
    : In CreateDB() fill each record in that array with the necessary info.
    : In find_employee() loop through the array and if you find the matching name, then show that record.
    : In display() loop though the array and write the data of each record.
    : In change_salary() loop though the array, and if you find the correct staff record, then ask the user for the new salary and change the correct field.
    : In post_emp() loop through the array and write each record with the matching post.
    :
    : As you can see from my comments here, nearly everything is a loop with an if-then statement inside it. An array of records is the easiest data structure. More complex structures include array of objects, linked lists (record-based or object-based), binary trees (record-based or object-based), hash table, etc.
    :

  • : If anyone minds doing this for me i don't mind paypalling them some cash :)
    :
    : Thanks for help dude.
    :
    : : : program cw2;
    : : :
    : : : {$APPTYPE CONSOLE}
    : : :
    : : : uses
    : : : SysUtils;
    : : :
    : : : type
    : : : // You have to create your own data types.
    : : : // This template uses a data type called Tstaff which is the employees DB
    : : : // This program does not compile because the data tyoe Tstaff has not been declared
    : : :
    : : : {PRE: true}
    : : : {POST: fill the DB with the data of 10 employees}
    : : : procedure create_DB(var staff:Tstaff);
    : : : begin
    : : : end;
    : : :
    : : : {PRE: staff non empty }
    : : : {POST if employee name found his/her address, telephone, position
    : : : is displayed
    : : : else error message}
    : : : procedure find_employee(staff:Tstaff;name:string);
    : : : begin
    : : : end;
    : : :
    : : : {PRE: staff non empt}
    : : : {POST: displays all the imformation stored in the DB}
    : : : procedure display(staff:Tstaff);
    : : : begin
    : : : end;
    : : :
    : : : {PRE: staff non empty }
    : : : {POST if employee name found user is asked for new salary and modified in DB
    : : : else error message}
    : : : procedure change_salary(var staff:Tstaff; name:string);
    : : : begin
    : : : end;
    : : :
    : : : {PRE: staff non empty }
    : : : {POST all the employees names with this position are displayed}
    : : : procedure post_emp(staff:Tstaff;post:string);
    : : : begin
    : : : end;
    : : :
    : : :
    : : : var
    : : : staff:Tstaff;
    : : : option:integer;
    : : : name,post:string;
    : : : begin
    : : :
    : : : create_DB(staff);
    : : : option:=1;
    : : : writeln('Welcome to XXX Company');
    : : : while option <> 0 do
    : : : begin
    : : : writeln('You have the following options');
    : : : writeln('1: Find data about an employee');
    : : : writeln ('2: Change an employee salary');
    : : : writeln('3: Display all the employees');
    : : : writeln('4: The names of the employees doing a specific job');
    : : : writeln ('0 to quit');
    : : : readln(option);
    : : : case option of
    : : : 1: begin
    : : : write('Introduce name of employee: ');
    : : : readln(name);
    : : : find_employee(staff,name);
    : : : end;
    : : : 2: begin
    : : : write('Introduce name of employee: ');
    : : : readln(name);
    : : : change_salary(staff,name);
    : : : end;
    : : : 3: display(staff);
    : : : 4: begin
    : : : write('Introduce a post in your company: ');
    : : : readln(post);
    : : : post_emp(staff,post);
    : : : end;
    : : : 0: writeln ('Thank your for using our software');
    : : : else
    : : : writeln('Wrong option please try again');
    : : : end;
    : : : end;
    : : : readln;
    : : :
    : : : end.
    : : :
    : : :
    : : Create an array of records called TStaff. In each record you need to declare the necessary fields.
    : : In CreateDB() fill each record in that array with the necessary info.
    : : In find_employee() loop through the array and if you find the matching name, then show that record.
    : : In display() loop though the array and write the data of each record.
    : : In change_salary() loop though the array, and if you find the correct staff record, then ask the user for the new salary and change the correct field.
    : : In post_emp() loop through the array and write each record with the matching post.
    : :
    : : As you can see from my comments here, nearly everything is a loop with an if-then statement inside it. An array of records is the easiest data structure. More complex structures include array of objects, linked lists (record-based or object-based), binary trees (record-based or object-based), hash table, etc.
    : :
    :
    :
    Here are the declarations and the Find_Employee() procedure. I leave the rest up to you.
    [code]
    const
    StaffCount = 20;
    type
    TStaffMember = record
    Name: string;
    Salary: real;
    Post: string;
    end;

    TStaff = array[0..StaffCount] of TStaffMember;

    procedure find_employee(staff:Tstaff;name:string);
    var
    i: integer;
    begin
    for i := 0 to StaffCount do
    if Staff[i].Name = name then
    with Staff[i] do
    writeln(Format('%s'#9'%d'#9'%s', [Name, Salary, Post]);
    end;

    [/code]
  • Very very helpful, thanks so much, i'll try to do the rest.. hehe
  • I just need to know how to modify the employees salary and display all the staff in the DB???

    Anyone can help me by providing the code?
    Then i'm finally done!

    Kind regards friends
  • : I just need to know how to modify the employees salary and display all the staff in the DB???
    :
    : Anyone can help me by providing the code?
    : Then i'm finally done!
    :
    : Kind regards friends
    :
    You can acces and assign fields within records and objects using a dot between them (See the if-then statement I gave you). Thus:
    [code]
    Staff[0].Name := 'John Doe';
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion