Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Colombo
Red Hat Certified System Administrator (RHCSA) - RHEL 10
Sanjeewani95
Updated:
Friday at 7:43 PM
NURSING , CAREGIVER , HOTEL & BEAUTY COURSES
IVA Para Medical Campus
Updated:
Thursday at 9:24 AM
Handmade Character Soft Toys Peppa Pig Family
anil1961
Updated:
Wednesday at 9:58 PM
Ad icon
Video Content Creator
pramukag
Updated:
Jun 28, 2026
Ad icon
QA Engineer Intern
pramukag
Updated:
Jun 28, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
Education
Thread for Programming and Realeted Topics
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="madurax86" data-source="post: 5582209" data-attributes="member: 1293"><p>ඕන්න කට්ටියට ඕන නම් ගන්න මේක Scientific Cal එකක් Delphi වලින් ලිව්වෙ </p><p>මට VB6 වල string functions පුරුදුවෙලා නිසා මේකෙ ඒවත් අලුතෙන් හදලා තමා පටන් ගත්තෙ.</p><p>සම්පූර්ණ project එක(exe සමඟ)</p><p><a href="http://madurax86.2kmegs.com/Calc.zip" target="_blank">http://madurax86.2kmegs.com/Calc.zip</a></p><p></p><p>[code]</p><p>//--Info</p><p>// * Originally written by Madura Anushanga Shelton</p><p>// * Last updated: 16/09/09</p><p>// * Please give credit where credit is due, if you are planning to use this code</p><p>// or its ideas :D</p><p>//--</p><p>program Project1;</p><p>{$APPTYPE CONSOLE}</p><p>uses SysUtils;</p><p>var s:string; iWidth:integer; sTmp:string;</p><p>//--main cal functions</p><p>function add(sVal1,sVal2:string):string;</p><p>var r1,r2:real;</p><p>begin</p><p> val(sval1,r1,iWidth);</p><p> val(sval2,r2,iWidth);</p><p> result:=formatfloat('',r2+r1) ;</p><p>end;</p><p>function subtract(sVal1,sVal2:string):string;</p><p>var r1,r2:real;</p><p>begin</p><p> val(sval1,r1,iWidth);</p><p> val(sval2,r2,iWidth);</p><p> result:=formatfloat('',r1-r2) ;</p><p>end;</p><p>function divide(sVal1,sVal2:string):string;</p><p>var r1,r2:real;</p><p>begin</p><p> val(sval1,r1,iWidth);</p><p> val(sval2,r2,iWidth);</p><p> result:=formatfloat('',r1/r2) ;</p><p>end;</p><p>function multiply(sVal1,sVal2:string):string;</p><p>var r1,r2:real;</p><p>begin</p><p> val(sval1,r1,iWidth);</p><p> val(sval2,r2,iWidth);</p><p> result:=formatfloat('',r1*r2) ;</p><p>end;</p><p>//--</p><p>//--string manipulation and convertion</p><p>function Rev(sMain:string):string;</p><p>var s:string;i:integer;</p><p>begin</p><p> s:=smain;</p><p> for i := 1 to length(sMain) do</p><p> begin</p><p> s[length(sMain)-i+1]:=sMain[i];</p><p> end;</p><p> rev:= s;</p><p>end;</p><p>function Mid(const strMain:string;const iStart,iLen:Integer):string;</p><p>var i,j:integer;var strOut:string;</p><p>begin</p><p> j:=iLen;</p><p> if iLen = 0 then</p><p> begin</p><p> j:=length(strMain)-iStart;</p><p> end;</p><p></p><p> for i := 1 to j do</p><p> begin</p><p> strOut := strOut + strMain[i+iStart];</p><p> end;</p><p> result:=strout;</p><p>end;</p><p>function Replace(const strMain,strSearch,strReplace:string):string;</p><p>var i:integer;strOut:string;t:integer;</p><p>begin</p><p> //go through the string</p><p> i:=-1;</p><p> t:=1;</p><p> while (t=1) do</p><p> begin</p><p> i:=i+1;</p><p> if strSearch = mid(strMain,i,length(strSearch)) then</p><p> begin</p><p> strOut:=strOut+strReplace; //replace if found</p><p> i:= i+length(strSearch)-1;</p><p> end</p><p> else</p><p> begin</p><p> strOut:=strOut+mid(strMain,i,1); //if not found amend</p><p> end;</p><p> if i= length(strMain) then t:=0;</p><p></p><p> end;</p><p> result:=strOut;</p><p>end;</p><p>function InStr(const strMain,strSearch:string; iStart:integer=0):integer;</p><p>var i,j:integer;</p><p>begin</p><p> j:=-1;</p><p> for i := iStart to length(strMain) - length(strSearch) do</p><p> begin</p><p> if strSearch=mid(strMain,i,length(strSearch)) then</p><p> begin</p><p> j:=i;</p><p> break;</p><p> end;</p><p> end;</p><p> InStr:=j;</p><p>end;</p><p>function c_sr(sNum:string):real;</p><p>var r1:real;</p><p>begin</p><p> val(snum,r1,iWidth);</p><p> c_sr:=r1;</p><p>end;</p><p>function c_rs(rNum:real):string;</p><p>begin</p><p> c_rs:=formatfloat('',rNum);</p><p>end;</p><p>procedure GetNumbers(const strMain,strChk:string;var iL,iR:real;var strRep:string);</p><p>var i,j:integer;k,l:string; label 2;</p><p>begin</p><p> j:=instr(strmain,strChk,1);</p><p></p><p> for i := j+2 to length(strmain) do</p><p> begin</p><p> if ((strmain[i]='/') or (strmain[i]='*') or (strmain[i]='+') or (strmain[i]='-') )And not (j+2=i )then</p><p> begin</p><p> //if (strmain[i]='+') or (strmain[i]='-') then k:=k+strmain[i];</p><p> break;</p><p> end</p><p> else</p><p> begin</p><p> k:=k+strmain[i];</p><p> end;</p><p> end;</p><p> for i := j downto 1 do</p><p> begin</p><p> if (strmain[i]='/') or (strmain[i]='*') or (strmain[i]='+') or (strmain[i]='-') then</p><p> begin</p><p> if (strmain[i]='+') or (strmain[i]='-') then l:=l+strmain[i];</p><p> break;</p><p> end</p><p> else</p><p> begin</p><p> l:=l+strmain[i];</p><p> end;</p><p> end;</p><p> l:=rev(l);</p><p> iL:=c_sr(l);</p><p> iR:=c_sr(k);</p><p> strRep:=l+strchk+k;</p><p>end;</p><p>//--</p><p>//--recursive</p><p>function Division(const strMain:string;var strRes:string):string;</p><p>var sOut,sRep:string;r1,r2:real;</p><p>begin</p><p> if not (instr(strmain,'/') = -1) then</p><p> begin</p><p> getnumbers(strmain,'/',r1,r2,sRep);</p><p> sout:=replace(strmain,srep,c_rs(r1/r2));</p><p> if instr(sout,'/') = -1 then</p><p> strRes := sout</p><p> else</p><p> Division(sout,strRes);</p><p> end</p><p> else strres:=strmain;</p><p>end;</p><p>function Multiplication(const strMain:string;var strRes:string):string;</p><p>var sOut,sRep:string;r1,r2:real;</p><p>begin</p><p> if not (instr(strmain,'*') = -1) then</p><p> begin</p><p> getnumbers(strmain,'*',r1,r2,sRep);</p><p> sout:=replace(strmain,srep,c_rs(r1*r2));</p><p> if instr(sout,'*') = -1 then</p><p> strRes := sout</p><p> else</p><p> Multiplication(sout,strRes);</p><p> end</p><p> else strres:=strmain;</p><p>end;</p><p>function Addition(const strMain:string;var strRes:string):string;</p><p>var sOut,sRep:string;r1,r2:real;</p><p>begin</p><p> if not (instr(strmain,'+',1) = -1) then</p><p> begin</p><p> getnumbers(strmain,'+',r1,r2,sRep);</p><p> sout:=replace(strmain,srep,c_rs(r1+r2));</p><p> if instr(sout,'+') = -1 then</p><p> strRes := sout</p><p> else</p><p> Addition(sout,strRes);</p><p> end</p><p> else strres:=strmain;</p><p>end;</p><p>function Subtraction(const strMain:string;var strRes:string):string;</p><p>var sOut,sRep:string;r1,r2:real;</p><p>begin</p><p> if not (instr(strmain,'-',1) = -1) then</p><p> begin</p><p> getnumbers(strmain,'-',r1,r2,sRep);</p><p> sout:=replace(strmain,srep,c_rs(r1-r2));</p><p> if (instr(sout,'-') = -1) then</p><p> strRes := sout</p><p> else</p><p> Subtraction(sout,strRes);</p><p> end</p><p> else strres:=strmain;</p><p>end;</p><p>//--</p><p>//--Execution--no parenthesis level</p><p>function Execute(const str:string):string;</p><p>var i:integer; label 1;</p><p>begin</p><p> //BODMAS</p><p> if (trim(str)='') then begin stmp:=str; goto 1; end;</p><p></p><p> division(str,stmp);</p><p> multiplication(stmp,stmp);</p><p> addition(stmp,stmp);</p><p> subtraction(stmp,stmp);</p><p> 1: Execute:=stmp;</p><p>end;</p><p>//--</p><p>//--Calculator-main</p><p>procedure CutParenthesis(strIn:string);</p><p>var i,j,k:integer; a:string;</p><p>begin</p><p> k:=0;</p><p> for i := 0 to length(strIn) do if strIn[i] = '(' then j:=i; //get last '('</p><p> for i := j to length(strIn) do if (strIn[i] = ')') and (k=0) then k:=i ; //first ')'</p><p> a:=mid(strIn,j,k-j-1); //execute a, a will not include '(',')'</p><p> strIn:=replace(strIn,'('+a+')',trim(Execute(a)));</p><p> if instr(strIn,'(')=-1 then</p><p> begin</p><p> strIn:=Execute(strIn);</p><p> writeln(' = '+strIn);</p><p> writeln('');</p><p> end</p><p> else</p><p> cutparenthesis(strIn);</p><p>end;</p><p>procedure Calc(); //main loop of the whole calculator</p><p>var s:string;</p><p>begin</p><p> stmp:='';</p><p> iWidth:=3;</p><p> s:='';</p><p> readln(s);</p><p> if not (instr(s,'{') = -1) then s:=replace(s,'{','(');</p><p> if not (instr(s,'[') = -1) then s:=replace(s,'[','(');</p><p> if not (instr(s,']') = -1) then s:=replace(s,']',')');</p><p> if not (instr(s,'}') = -1) then s:=replace(s,'}',')');</p><p></p><p> CutParenthesis(s);</p><p>end;</p><p>//--</p><p>//--Some DOS graphics :P</p><p>procedure PrintHeader();</p><p>var j:integer;</p><p>begin</p><p> for j := 1 to 80 do write('=');</p><p> writeln('');</p><p> writeln(' A Simple Scientific Calculator - Written by Madura Anushanga Shelton in Delphi');</p><p> writeln(' * Do NOT enter wrong expressions, it''ll not throw an error for wrong input.');</p><p> writeln('');</p><p> for j := 1 to 80 do write('=');</p><p> writeln('');</p><p>end;</p><p>//--</p><p>var i:integer;</p><p>begin</p><p> PrintHeader;</p><p> i:=0;</p><p> while i=0 do calc;</p><p>end.</p><p></p><p>[/code]</p></blockquote><p></p>
[QUOTE="madurax86, post: 5582209, member: 1293"] ඕන්න කට්ටියට ඕන නම් ගන්න මේක Scientific Cal එකක් Delphi වලින් ලිව්වෙ මට VB6 වල string functions පුරුදුවෙලා නිසා මේකෙ ඒවත් අලුතෙන් හදලා තමා පටන් ගත්තෙ. සම්පූර්ණ project එක(exe සමඟ) [url]http://madurax86.2kmegs.com/Calc.zip[/url] [code] //--Info // * Originally written by Madura Anushanga Shelton // * Last updated: 16/09/09 // * Please give credit where credit is due, if you are planning to use this code // or its ideas :D //-- program Project1; {$APPTYPE CONSOLE} uses SysUtils; var s:string; iWidth:integer; sTmp:string; //--main cal functions function add(sVal1,sVal2:string):string; var r1,r2:real; begin val(sval1,r1,iWidth); val(sval2,r2,iWidth); result:=formatfloat('',r2+r1) ; end; function subtract(sVal1,sVal2:string):string; var r1,r2:real; begin val(sval1,r1,iWidth); val(sval2,r2,iWidth); result:=formatfloat('',r1-r2) ; end; function divide(sVal1,sVal2:string):string; var r1,r2:real; begin val(sval1,r1,iWidth); val(sval2,r2,iWidth); result:=formatfloat('',r1/r2) ; end; function multiply(sVal1,sVal2:string):string; var r1,r2:real; begin val(sval1,r1,iWidth); val(sval2,r2,iWidth); result:=formatfloat('',r1*r2) ; end; //-- //--string manipulation and convertion function Rev(sMain:string):string; var s:string;i:integer; begin s:=smain; for i := 1 to length(sMain) do begin s[length(sMain)-i+1]:=sMain[i]; end; rev:= s; end; function Mid(const strMain:string;const iStart,iLen:Integer):string; var i,j:integer;var strOut:string; begin j:=iLen; if iLen = 0 then begin j:=length(strMain)-iStart; end; for i := 1 to j do begin strOut := strOut + strMain[i+iStart]; end; result:=strout; end; function Replace(const strMain,strSearch,strReplace:string):string; var i:integer;strOut:string;t:integer; begin //go through the string i:=-1; t:=1; while (t=1) do begin i:=i+1; if strSearch = mid(strMain,i,length(strSearch)) then begin strOut:=strOut+strReplace; //replace if found i:= i+length(strSearch)-1; end else begin strOut:=strOut+mid(strMain,i,1); //if not found amend end; if i= length(strMain) then t:=0; end; result:=strOut; end; function InStr(const strMain,strSearch:string; iStart:integer=0):integer; var i,j:integer; begin j:=-1; for i := iStart to length(strMain) - length(strSearch) do begin if strSearch=mid(strMain,i,length(strSearch)) then begin j:=i; break; end; end; InStr:=j; end; function c_sr(sNum:string):real; var r1:real; begin val(snum,r1,iWidth); c_sr:=r1; end; function c_rs(rNum:real):string; begin c_rs:=formatfloat('',rNum); end; procedure GetNumbers(const strMain,strChk:string;var iL,iR:real;var strRep:string); var i,j:integer;k,l:string; label 2; begin j:=instr(strmain,strChk,1); for i := j+2 to length(strmain) do begin if ((strmain[i]='/') or (strmain[i]='*') or (strmain[i]='+') or (strmain[i]='-') )And not (j+2=i )then begin //if (strmain[i]='+') or (strmain[i]='-') then k:=k+strmain[i]; break; end else begin k:=k+strmain[i]; end; end; for i := j downto 1 do begin if (strmain[i]='/') or (strmain[i]='*') or (strmain[i]='+') or (strmain[i]='-') then begin if (strmain[i]='+') or (strmain[i]='-') then l:=l+strmain[i]; break; end else begin l:=l+strmain[i]; end; end; l:=rev(l); iL:=c_sr(l); iR:=c_sr(k); strRep:=l+strchk+k; end; //-- //--recursive function Division(const strMain:string;var strRes:string):string; var sOut,sRep:string;r1,r2:real; begin if not (instr(strmain,'/') = -1) then begin getnumbers(strmain,'/',r1,r2,sRep); sout:=replace(strmain,srep,c_rs(r1/r2)); if instr(sout,'/') = -1 then strRes := sout else Division(sout,strRes); end else strres:=strmain; end; function Multiplication(const strMain:string;var strRes:string):string; var sOut,sRep:string;r1,r2:real; begin if not (instr(strmain,'*') = -1) then begin getnumbers(strmain,'*',r1,r2,sRep); sout:=replace(strmain,srep,c_rs(r1*r2)); if instr(sout,'*') = -1 then strRes := sout else Multiplication(sout,strRes); end else strres:=strmain; end; function Addition(const strMain:string;var strRes:string):string; var sOut,sRep:string;r1,r2:real; begin if not (instr(strmain,'+',1) = -1) then begin getnumbers(strmain,'+',r1,r2,sRep); sout:=replace(strmain,srep,c_rs(r1+r2)); if instr(sout,'+') = -1 then strRes := sout else Addition(sout,strRes); end else strres:=strmain; end; function Subtraction(const strMain:string;var strRes:string):string; var sOut,sRep:string;r1,r2:real; begin if not (instr(strmain,'-',1) = -1) then begin getnumbers(strmain,'-',r1,r2,sRep); sout:=replace(strmain,srep,c_rs(r1-r2)); if (instr(sout,'-') = -1) then strRes := sout else Subtraction(sout,strRes); end else strres:=strmain; end; //-- //--Execution--no parenthesis level function Execute(const str:string):string; var i:integer; label 1; begin //BODMAS if (trim(str)='') then begin stmp:=str; goto 1; end; division(str,stmp); multiplication(stmp,stmp); addition(stmp,stmp); subtraction(stmp,stmp); 1: Execute:=stmp; end; //-- //--Calculator-main procedure CutParenthesis(strIn:string); var i,j,k:integer; a:string; begin k:=0; for i := 0 to length(strIn) do if strIn[i] = '(' then j:=i; //get last '(' for i := j to length(strIn) do if (strIn[i] = ')') and (k=0) then k:=i ; //first ')' a:=mid(strIn,j,k-j-1); //execute a, a will not include '(',')' strIn:=replace(strIn,'('+a+')',trim(Execute(a))); if instr(strIn,'(')=-1 then begin strIn:=Execute(strIn); writeln(' = '+strIn); writeln(''); end else cutparenthesis(strIn); end; procedure Calc(); //main loop of the whole calculator var s:string; begin stmp:=''; iWidth:=3; s:=''; readln(s); if not (instr(s,'{') = -1) then s:=replace(s,'{','('); if not (instr(s,'[') = -1) then s:=replace(s,'[','('); if not (instr(s,']') = -1) then s:=replace(s,']',')'); if not (instr(s,'}') = -1) then s:=replace(s,'}',')'); CutParenthesis(s); end; //-- //--Some DOS graphics :P procedure PrintHeader(); var j:integer; begin for j := 1 to 80 do write('='); writeln(''); writeln(' A Simple Scientific Calculator - Written by Madura Anushanga Shelton in Delphi'); writeln(' * Do NOT enter wrong expressions, it''ll not throw an error for wrong input.'); writeln(''); for j := 1 to 80 do write('='); writeln(''); end; //-- var i:integer; begin PrintHeader; i:=0; while i=0 do calc; end. [/code] [/QUOTE]
Insert quotes…
Verification
Hathara warak wissa keeyada? (Hathara wadi karanna 20)
Post reply
Top
Bottom