Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {https://cdn.discordapp.com/attachments/650768151264362519/831560843426529300/20210413_170333.jpg}
- Program ex2;
- Uses Wincrt;
- Var
- f1,f2: Text;
- Procedure creation (Var f1,f2:Text);
- Begin
- Assign (f1,'C:\bac\revision devoir 2\F_IPV4.txt');
- Assign (f2,'C:\bac\revision devoir 2\F_IPV6.txt');
- End;
- Function valide (ch:String): Boolean;
- Var
- test: Boolean;
- x,e: Integer;
- Begin
- ch:=ch+'.';
- Repeat
- Val (Copy(ch,1,Pos('.',ch)-1),x,e);
- test := (x<=255) and (x>=0);
- Delete (ch,1,Pos('.',ch));
- Until (test=False) Or (ch='');
- valide := test;
- End;
- Function convert_2 (ch:String): String;
- Var
- x,e: Integer;
- ch1: String;
- Begin
- Val (ch,x,e);
- ch := '';
- Repeat
- Str (x Mod 2,ch1);
- ch := ch1+ch;
- x := x Div 2;
- Until (x=0);
- convert_2 := ch;
- End;
- Function classe (ch:String): Char;
- Var
- c: Char;
- Begin
- ch := convert_2(Copy(ch,1,Pos('.',ch)-1));
- If (ch[1]='0') Then
- c := 'A'
- Else If (Pos('10',ch)=1) Then
- c := 'B'
- Else If ('110'=Copy(ch,1,3)) Then
- c := 'C'
- Else If (Pos('1110',ch)=1) Then
- c := 'D'
- Else If (Pos('1111',ch)=1) Then
- c := 'E';
- classe := c;
- End;
- Function convert_16 (ch:String): String;
- Var
- ch1: String;
- x,e: Integer;
- Begin
- Val (ch,x,e);
- ch1:='';
- Repeat
- Str (x Mod 16,ch);
- If (Length(ch)>1) Then
- ch1 := Chr(55+x Mod 16)+ch1
- Else
- ch1 := ch+ch1;
- x := x Div 16;
- Until (x=0);
- convert_16 := ch1;
- End;
- Function convert (ch:String): String;
- Var
- ch1: String;
- Begin
- ch1 := '';
- ch:=ch+'.';
- Repeat
- ch1 := ch1+convert_16(Copy(ch,1,Pos('.',ch)-1));
- Delete (ch,1,Pos('.',ch));
- Until (ch='');
- Insert (':',ch1,5);
- convert := ch1;
- End;
- Procedure traitement (Var f1,f2:Text);
- Var
- ch: String;
- Begin
- Reset (f1);
- Rewrite (f2);
- While Not (Eof(f1)) Do
- Begin
- Readln (f1,ch);
- If valide (ch) Then
- begin
- Writeln (f2,ch,'; Classe ',classe(ch),' ; ',convert(ch));
- end
- else writeln (ch,' est invalide');
- End;
- close (f1);
- close (f2);
- End;
- Procedure affiche (Var f2:Text);
- Var
- ch: String;
- Begin
- Reset (f2);
- While Not (Eof(f2)) Do
- Begin
- Readln (f2,ch);
- Writeln (ch);
- End;
- Close (f2);
- End;
- Begin
- creation (f1,f2);
- traitement (f1,f2);
- affiche (f2);
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement