Subdomain Posts
None | 11 hours ago
None | 11 hours ago
None | 4 days ago
None | 4 days ago
Ada | 4 days ago
Ada | 4 days ago
None | 6 days ago
Ada | 6 days ago
None | 7 days ago
None | 14 days ago
Recent Posts
C++ | 1 sec ago
Java | 2 sec ago
None | 8 sec ago
None | 56 sec ago
JavaScript | 1 min ago
None | 1 min ago
None | 1 min ago
C# | 1 min ago
PHP | 1 min ago
Python | 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Anonymous on the 23rd of Jan 2010 12:51:34 AM Download | Raw | Embed | Report
  1. with Ada.Text_IO;
  2. with Ada.Strings.Unbounded;
  3. use Ada.Text_IO;
  4. use Ada.Strings.Unbounded;
  5.  
  6. procedure CalcPlus is
  7.  
  8. function isNumber(c : character) return boolean is
  9. begin
  10. if Character'Pos(c) in 48..57 then return true; else return false; end if;
  11. end isNumber;
  12.  
  13. function get_First_Part(a : string) return string is
  14. n : integer;
  15. begin
  16. n:=1;
  17. while (isNumber(a(n))) loop
  18. n := n+1;
  19. end loop;
  20. return a(a'First..n-1);
  21. end get_First_Part;
  22.  
  23. function get_Last_Part(a : string) return string is
  24. n : integer;
  25. begin
  26. n:=1;
  27. while (isNumber(a(n))) loop
  28. n := n+1;
  29. end loop;
  30. return a(n+1..a'Last);
  31. end get_Last_Part;
  32.  
  33. function get_Symbol(a : string) return character is
  34. n : integer;
  35. begin
  36. n:=1;
  37. while (isNumber(a(n))) loop
  38. n := n+1;
  39. end loop;
  40. return a(n);
  41. end get_Symbol;
  42.  
  43. expression : String (1 .. 2000);
  44. char : character;
  45. a, b, c : integer;
  46. Last : Natural;
  47. begin
  48. Put("Enter expression: ");
  49. Get_Line(Item => expression, Last => Last);
  50. a:=Integer'Value(get_First_Part(expression(1..expression'Last)));
  51. b:=Integer'Value(get_Last_Part(expression(1..expression'Last)));
  52. char:=get_Symbol(expression(expression'first..Last));
  53. if char='+' then c:=a+b;
  54. elsif char='-' then c:=a-b;
  55. elsif char='/' then c:=a/b;
  56. elsif char='*' then c:=a*b;
  57. end if;
  58. Put("Answer: "&c'img);
  59. end CalcPlus;
Submit a correction or amendment below. [ previous version ] | [ difference ] | Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: