LOVEGUN

Exercice 7

Oct 27th, 2020 (edited)
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.93 KB | None | 0 0
  1. Program ex7;
  2. Uses Wincrt;
  3. Type
  4.   tab = Array ['A'..'Z'] Of Integer;
  5. Var
  6.   f1,f2: Text;
  7.   compt: tab;
  8.  
  9. Procedure creation (Var f1,f2:Text);
  10. Begin
  11.   Assign (f1,'c:\bac\ex7\ftxt.txt');
  12.   Assign (f2,'c:\bac\ex7\modified.txt');
  13. End;
  14.  
  15. Procedure espace (Var ch:String);
  16. Begin
  17.   While Pos('  ',ch)<>0 Do
  18.     Delete (ch,Pos('  ',ch),1);
  19.   If ch[1]=' ' Then
  20.     Delete(ch,1,1);
  21.   If ch[Length(ch)]=' ' Then
  22.     Delete (ch,Length(ch),1);
  23. End;
  24.  
  25. Procedure supp_esp (Var f1,f2:Text);
  26. Var
  27.   ch: String;
  28. Begin
  29.   Reset (f1);
  30.   Rewrite (f2);
  31.   While Not (Eof(f1)) Do
  32.     Begin
  33.       Readln (f1,ch);
  34.       espace (ch);
  35.       Writeln (f2,ch);
  36.     End;
  37.   Close (f1);
  38.   Close (f2);
  39. End;
  40. Procedure majchaine (Var ch:String);
  41. Var
  42.   i: Integer;
  43. Begin
  44.   For i:=1 To Length(ch) Do
  45.     ch[i] := Upcase(ch[i]);
  46. End;
  47. Procedure convmaj (Var f1,f2:Text);
  48. Var
  49.   ch: String;
  50. Begin
  51.   Reset (f2);
  52.   Rewrite (f1);
  53.   While Not (Eof(f2)) Do
  54.     Begin
  55.       Readln (f2,ch);
  56.       majchaine (ch);
  57.       Writeln (f1,ch);
  58.     End;
  59.   Close (f1);
  60.   Close (f2);
  61.   Erase (f2);
  62. End;
  63. Procedure comptable (Var t:tab;Var ch:String);
  64. Var
  65.   i,l: Char;
  66.   j: Integer;
  67. Begin
  68.   For i:='A' To 'Z' Do
  69.     t[i] := 0;
  70.   For j:=1 To Length(ch) Do
  71.     Begin
  72.       l := ch[j];
  73.       If l In ['A'..'Z'] Then
  74.         t[l] := t[l]+1;
  75.     End;
  76. End;
  77. Procedure comptage (Var f1,f2:Text;Var compt:tab);
  78. Var
  79.   ch: String;
  80.   i: Char;
  81.   t: tab;
  82. Begin
  83.   Reset (f1);
  84.   For i:='A' To 'Z' Do
  85.     compt[i] := 0;
  86.   While Not (Eof(f1)) Do
  87.     Begin
  88.       Readln (f1,ch);
  89.       comptable (t,ch);
  90.       For i:='A' To 'Z' Do
  91.         compt[i] := compt[i]+t[i];
  92.     End;
  93.   Close (f1);
  94. End;
  95. Procedure affiche (Var compt:tab);
  96. Var
  97.   i: Char;
  98. Begin
  99.   For i:='A' To 'Z' Do
  100.     If compt[i] <> 0 Then
  101.       Writeln(i, ' : ', compt[i] ,' fois');
  102. End;
  103. Begin
  104.   creation (f1,f2);
  105.   supp_esp (f1,f2);
  106.   convmaj (f1,f2);
  107.   comptage (f1,f2,compt);
  108.   affiche (compt);
  109. End.
Add Comment
Please, Sign In to add comment