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...
By Anonymous on the 23rd of Jan 2010 12:51:34 AM
Download |
Raw |
Embed |
Report
with Ada.Text_IO;
with Ada.Strings.Unbounded;
use Ada.Text_IO;
use Ada.Strings.Unbounded;
procedure CalcPlus is
function isNumber(c : character) return boolean is
begin
if Character'Pos(c) in 48..57 then return true; else return false; end if;
end isNumber;
function get_First_Part(a : string) return string is
n : integer;
begin
n:=1;
while (isNumber(a(n))) loop
n := n+1;
end loop;
return a(a'First..n-1);
end get_First_Part;
function get_Last_Part(a : string) return string is
n : integer;
begin
n:=1;
while (isNumber(a(n))) loop
n := n+1;
end loop;
return a(n+1..a'Last);
end get_Last_Part;
function get_Symbol(a : string) return character is
n : integer;
begin
n:=1;
while (isNumber(a(n))) loop
n := n+1;
end loop;
return a(n);
end get_Symbol;
expression : String (1 .. 2000);
char : character;
a, b, c : integer;
Last : Natural;
begin
Put("Enter expression: ");
Get_Line(Item => expression, Last => Last);
a:=Integer'Value(get_First_Part(expression(1..expression'Last)));
b:=Integer'Value(get_Last_Part(expression(1..expression'Last)));
char:=get_Symbol(expression(expression'first..Last));
if char='+' then c:=a+b;
elsif char='-' then c:=a-b;
elsif char='/' then c:=a/b;
elsif char='*' then c:=a*b;
end if;
Put("Answer: "&c'img);
end CalcPlus;
Submit a correction or amendment below.
[ previous version ] | [ difference ] | Make A New Post