SETS.PAS 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. program sets;
  2. (* Program to test translation of sets *)
  3. type CharSet = SET OF CHAR;
  4. var Answer : CHAR;
  5. Line : STRING[80];
  6. Digits, UpperCase, LowerCase : CharSet;
  7. I, Digit_Count, Lower_Count, Upper_Count, Others : INTEGER;
  8. begin
  9. (* Initialize character sets *)
  10. Digits := ['0'..'9'];
  11. LowerCase := ['a'..'z'];
  12. UpperCase := ['A'..'Z'];
  13. repeat
  14. (* Initialize counters *)
  15. Digit_Count := 0;
  16. Upper_Count := 0;
  17. Lower_Count := 0;
  18. Others := 0;
  19. writeln('Type a line up to 80 characters ');
  20. readln(Line); writeln;
  21. for I := 1 TO Length(Line) do
  22. if Line[I] in Digits
  23. then
  24. Digit_Count := Digit_Count + 1
  25. else if Line[I] in LowerCase then
  26. Lower_Count := Lower_Count + 1
  27. else if Line[I] in UpperCase then
  28. Upper_Count := Upper_Count + 1
  29. else Others := Others + 1;
  30. writeln('You typed ',Length(Line),' characters with ');
  31. writeln(Digit_Count:2,' digits');
  32. writeln(Upper_Count:2,' upper case letters');
  33. writeln(Lower_Count:2,' lower case letters');
  34. writeln(Others:2,' other characters'); writeln;
  35. WRITE('Want to type another line? (Y/N) ');
  36. readln(Answer); writeln;
  37. until Answer <> 'Y';
  38. end.
  39.