18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>SIMSCRIPT</strong> <strong>II.5</strong> <strong>Programming</strong> <strong>Language</strong><br />

Program 1-2.<br />

_______________________________________________________________________________<br />

'' Program To Compute The Roots of a Quadratic Equation<br />

'' of the Form AX**2 + BX + C = 0<br />

read A,B,C<br />

print 2 lines with A,B,C as follows<br />

ROOTS OF THE QUADRATIC EQUATION WITH COEFFICIENTS:<br />

A=***.** B=***.** C=***.**<br />

if A eq 0<br />

if B eq 0<br />

if C eq 0<br />

print 1 line as follows<br />

TRIVIAL CASE, COEFFICIENTS ALL ZERO<br />

else<br />

print 1 line with C as follows<br />

EQUATION STATES ***.** = 0<br />

always<br />

else<br />

print 1 line with -C/B as follows<br />

LINEAR, ONE ROOT ALPHA = ***.**<br />

always<br />

else<br />

let X = B**2 - 4*A*C<br />

if X ls 0<br />

let IMAG = ( (-X)**0.5 )/(2*A)<br />

let REAL = -B/(2*A)<br />

print 2 lines with REAL,IMAG as follows<br />

EQUATION HAS COMPLEX ROOTS<br />

REAL PART = ***.** IMAGINARY PART = ***.**<br />

else<br />

let X = X ** 0.5<br />

let ALPHA = (-B+X)/(2*A)<br />

let BETA = (-B-X)/(2*A)<br />

print 2 lines with ALPHA,BETA as follows<br />

EQUATION HAS REAL ROOTS<br />

ALPHA = ***.** BETA = ***.**<br />

always<br />

always<br />

stop<br />

end<br />

_______________________________________________________________________________<br />

1.22.2 Finding the Area of a Triangle<br />

This program demonstrates nested if statements, using more complex logical expressions. The<br />

program calculates the area and perimeter of a triangle with the lengths of the sides A, B, and C as<br />

input data. The first if statement verifies that none of the sides is of zero or negative length. The<br />

32

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!