Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project7;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses
- System.SysUtils ,
- {$IFDEF UNIX}{$IFDEF UseCThreads}
- cthreads,
- {$ENDIF}{$ENDIF}
- Classes
- { you can add units after this };
- Type TWeight = class (TObject)
- private
- kilograms, grams , Tonnes : integer;
- public
- Constructor Create( t : integer ; k : integer ; g : integer);
- Procedure SetKilograms(k : integer);
- procedure setGrams(g : integer);
- procedure setTonnes(t :integer);
- function getKilograms : integer;
- function getGrams : integer;
- function getTonnes : integer;
- procedure subtractGrams( g: integer);
- procedure addGrams(g:integer);
- procedure add(w1 : TWeight);
- procedure subtract(w1: Tweight);
- procedure displayStats ;
- end;
- Constructor TWeight.Create(t : integer ; k : integer ; g : integer);
- begin
- grams := g mod 1000 ;
- kilograms := k mod 1000 + g div 1000 ;
- tonnes := t + k div 1000 + kilograms div 1000;
- end;
- Procedure TWeight.SetKilograms(k: integer);
- begin
- kilograms := k mod 1000;
- tonnes := tonnes + k div 1000;
- end;
- procedure TWeight.setGrams(g: integer);
- begin
- grams:=g mod 1000;
- kilograms := kilograms + g mod 1000;
- tonnes := tonnes + kilograms div 1000;
- end;
- Procedure TWeight.setTonnes(t: integer);
- begin
- tonnes:= t;
- end;
- function TWeight.getKilograms;
- begin
- getKilograms := kilograms;
- end;
- function TWeight.getGrams;
- begin
- getGrams := grams;
- end;
- function TWeight.getTonnes;
- begin
- getTonnes := Tonnes;
- end;
- procedure TWeight.add(w1 : tWeight);
- begin
- kilograms := (kilograms + w1.kilograms + (grams + w1.grams) div 1000) mod 1000 ;
- grams := (grams + w1.grams) mod 1000 ;
- tonnes := tonnes + w1.tonnes + (kilograms + w1.kilograms + (grams + w1.grams) div 1000) div 1000;
- end;
- procedure TWeight.subtract(w1 : tWeight);
- var a , b , c : Longint;
- begin
- a := kilograms * 1000 + grams + tonnes* 1000000;
- b := w1.kilograms * 1000 + w1.grams + w1.tonnes* 1000000;
- c:= a - b;
- kilograms := ( c div 1000) mod 1000;
- grams := c mod 1000;
- tonnes := c div 1000000;
- end;
- procedure TWeight.subtractGrams(g: integer);
- var a , c : Longint;
- begin
- a := kilograms * 1000 + grams + tonnes* 1000000;
- c:= a - g;
- kilograms := ( c div 1000) mod 1000;
- grams := c mod 1000;
- tonnes := c div 1000000;
- end;
- procedure TWeight.addGrams(g: integer);
- var a , c : Longint;
- begin
- a := kilograms * 1000 + grams + tonnes* 1000000;
- c:= a + g;
- kilograms := ( c div 1000) mod 1000;
- grams := c mod 1000;
- tonnes := c div 1000000;
- end;
- procedure TWeight.displayStats;
- begin
- writeln(' grams = ',getgrams);
- writeln(' kilograms = ',getkilograms);
- writeln(' tonnes = ',gettonnes);
- end;
- Var
- ob1 : TWeight;
- ob2 : TWeight;
- ob3 : TWeight;
- begin
- ob1 := TWeight.Create(10 , 140 , 10);
- ob2 := TWeight.Create(1 , 100 , 5);
- ob3 := TWeight.Create(0 , 1 , 0);
- ob1.subtract(ob2);
- ob1.displayStats;
- ob1.SetKilograms(10000);
- ob1.displayStats;
- ob1.setTonnes(2);
- ob1.displayStats;
- ob1.addGrams(100);
- ob1.displayStats;
- // ob1.SetKilograms(10003);
- /// writeln(ob1.getKilograms);
- // writeln(ob1.getTonnes);
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement