### Create a StudySoup account

#### Be part of our community, it's free to join!

Already have a StudySoup account? Login here

# Intro Comp Prog Scientific Apl CS 1073

UTSA

GPA 3.55

### View Full Document

## 11

## 0

## Popular in Course

## Popular in ComputerScienence

This 19 page Class Notes was uploaded by Mireya Heidenreich on Thursday October 29, 2015. The Class Notes belongs to CS 1073 at University of Texas at San Antonio taught by Anthony Chronopoulos in Fall. Since its upload, it has received 11 views. For similar materials see /class/231373/cs-1073-university-of-texas-at-san-antonio in ComputerScienence at University of Texas at San Antonio.

## Reviews for Intro Comp Prog Scientific Apl

### What is Karma?

#### Karma is the currency of StudySoup.

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 10/29/15

Chapter 2 This is the modi ed version ofthe program given in Figure 21 pp 1819 The program is incomplete since it does contain any code for procedure calculateicircle PROGRAM circle IMPLICIT NONE This program calculates the equation of a circle passing through three points Variable declarations REAL X1 yl X2 y2 X3 y3 a b r Step 1 WRITE quotPlease type the coordinates ofthree pointsquot WRITE quotin the order XlylX2y2X3y3quot READ XlylX2y2X3y3 Read the three points Step 2 CALL calculateicircleXlylX2y2X3y3abr Step 3 WRITE quotThe center ofthe circle through these points is amp ampHa llllbllll WRITE quotIts radius is quot r STOP END PROGRAM circle Chapter 3 Modi ed Example 31 page 55 PROGRAM centigradeitoifahrenheit IMPLICIT NONE A program to convert a Centigrade temperature to Fahrenheit Variable declarations REAL tempic tempif Ask for Centigrade temperature WRITE quotWhat is the Centigrade temperature quot READ tempic Convert it to Fahrenheit tempif 90 tempic 50 320 Print both temperatures WRITE tempic quotC quot tempif quotFquot STOP END PROGRAM centigradeitoifahrenheit Modi ed Example 32 page 64 PROGRAM welcome IMPLICIT NONE This program manipulates character strings to produce a properly formatted welcome message Variable declarations CHARACTER LEN20 title rstiname lastiname CHARACTER LEN40 fulliname Ask for name etc WRITE quotPlease give your full name in the form requestedquot WRITE quotTitle MrMrsMsProfessoretc quot READ title WRITE quotFirst name quot READ rstiname WRITE quotLast name quot READ lastiname Create full name fulliname TRIMtitlequot quotTRIM rst7namequot quotlast7name Print messages WRITE quotWelcome quot fulliname WRITE quotMay I call you quot TRIM rst7name quotquot STOP END PROGRAM welcome Modi ed example 33 page 71 PROGRAM geometry IMPLICIT NONE A program to use derived types for twodimensional geometric calculations Type de nitions TYPE point REAL X y Cartesian coordinates of the point END TYPE point TYPE line REAL a b c coef cients of de ning equation END TYPE line Variable declarations TYPEpoint pl p2 TYPEline plitOJZ Read data WRITE quotPlease type coordinates of rst pointquot READ pl WRITE quotPlease type coordinates of second pointquot READ p2 Calculate coef cients of equation representing the line p17I04p2a p2y ply p17I04p2b plX p2X p17I04p2C plyp2X p2yplX Print result WRITE quotThe equation ofthe linejoining these two points is39 WRITE quotax by c 0quot WRITE quotwhere a quot p17I04p2a WRITE quot b quot p17I04p2b WRITE quot c quot p17I04p2C STOP END PROGRAM geometry Modi ed Example 34 page 73 PROGRAM complexiarithmetic IMPLICIT NONE A program to illustrate the use of a derived type to perform compleX arithmetic Type de nition TYPE complexinumber REAL real jart imaginary jart END TYPE complexinumber Variable de nitions TYPEcomplex7number cl c2 sum diff prod Read data WRITE quotPlease supply two complex numbersquot WRITE quotEach complex number should be typed as two numbers 39 WRITE quotrepresenting the real and imaginary parts amp ampof the numberquot READ cl c2 Calculate sum difference and product sumrealJart clrealJart c2realJart sumimaginaryJart climaginaryJart c2imaginaryJart di realJart clrealJart c2realJart di imaginaryJart climaginaryJart c2imaginaryJart prodrealJart clrealJart c2realJart amp climaginaryJart c2imaginaryJart prodimaginaryJart clrealJart c2imaginaryJart amp climaginaryJart c2realJart Print results WRITE quotThe sum ofthe two numbers is quot sum WRITE quotThe difference between the two numbers is quot diff WRITE quotThe product of the two numbers is quot prod STOP END PROGRAM complexiarithmetic Chapter 4 Example 41 page 86 code modi ed for elf90 compiler PROGRAM wheatisowing IMPLICIT NONE A program to calculate the quantity of wheat required to sow a triangular eld Variable declarations REAL a b c s area density quantity INTEGER numibags Read the lengths ofthe sides ofthe eld WRITE quotType the lengths ofthe three sides ofthe eld amp ampin meters quot READ a b c Calculate the area of the eld s05 abc areaSQRTs s a sb s c Read sowing density WRITE quotWhat is the sowing density gmsqm quot READ density Calculate quantity of wheat and the number of full 10 kg bags quantity density area numibags 00001 quantity 09 Round up more than 1kg Print results WRITE quotThe area ofthe eld is quot area quotsq metersquot WRITE quotand quot numibags quot 10 kilo bags will be requiredquot STOP END PROGRAM wheatisowing Example 42 from text page 103 A function that takes two chracter arguments as input arguments containing two names a rst name and a family name respectively and returns a string containing the two names exactly one space separating them FUNCTION fulliname rst7name lastiname IMPLICIT NONE CHARACTER LEN fulliname CHARACTER LEN INTENTIN rstiname lastiname Function to join two names to form a full name with a single space between the rst and last names Dummy argument declarations CHARACTER LEN LEN rst7name newi rstiname CHARACTER LEN LENlast7name newilastiname Use ADJUSTL to remove redundant leading blanks newi rstiname ADJUSTL rst7name newilastiname ADJUSTLlast7name Use TRIM to remove blanks at the end of newi rstiname fulliname TRIMnew7 rst7name quot quot newilastiname RETURN END Function fulliname Example 44 page 113 modi ed for elf90 MODULE complexidata IMPLICIT NONE This module de nes a complex data derived data type TYPE complexinumber REAL real jart imagjart END TYPE complexinumber END MODULE complexidata PROGRAM complexiexample USE complexidata IMPLICIT NONE Declare external functions TYPE complexinumber ciadd cisub cimult cidiv Declare two complex variables TYPE complexinumber 21 22 Read data WRITE quotPlease supply two complex numbers as two pairs amp ampof numbersquot WRITE quotEach pair represents the real and imaginary parts amp ampofa complex numberquot READ 21 22 Calculate and print sum difference product and quotient WRITE quotThe sum oftwo numbers is quot c7add21 22 WRITE quotThe difference between the two numbers is quot amp cisub 21 22 WRITE quotThe product of the two numbers is quot c7mult21 22 WRITE quotThe result of dividing the first number by the amp ampsecond is quot c7diV2122 STOP contains FUNCTION ciadd 21 22 USE complexidata IMPLICIT NONE Declare function type and dummy arguments TYPE complexinumber ciadd TYPE complexinumber INTENTIN 21 22 Calculate function result c7addrealJart 21realJ3art 22realJ3art c7addimagJart 21imagJart 21imagJ3art RETURN END FUNCTION ciadd FUNCTION c7sub2122 USE complexidata IMPLICIT NONE Declare function type and dummy arguments TYPE complexinumber cisub TYPE complexinumber INTENTIN 21 22 Calculate function result c7subrealJart 21realJ3art 22realJ3art c7subimagJart 21imagJart 22imagJ3art RETURN END FUNCTION cisub FUNCTION c7mult21 22 USE complexidata IMPLICIT NONE Declare function type and dummy arguments TYPE complexinumber cimult TYPE complexinumber INTENTIN 21 22 Calculate function result c7multrealJart 21realJ3art 22realJ3art amp 21imagJ3art 22imagJart c7multimagJart 21realJ3art 22imagJ3art amp 21imagJ3art 22realJ3art RETURN END FUNCTION cimult FUNCTION c7diV21 22 USE complexidata IMPLICIT NONE Declare function type and dummy arguments TYPE complexinumber 7le TYPE complexinumber INTENTIN 21 22 Local variable to save calculating denominator twice REAL denom Calculate function result denom 22realJ3art2 22imagJ3art2 c7diVrealJart 21realJ3art 22realJ3art amp 21imagJ3art 22imagJ3artdenom c7diVimagJart 22realJ3art 21imagJ3art amp 21realJ3art 22imagJ3artdenom RETURN END FUNCTION 7le END PROGRAM complexiexample Example 45 page 118119 modified for elf90 MODULE geometricidata IMPLICIT NONE Type definitions TYPE point REAL X y Cartesian coordinates of the point END TYPE point TYPE line REAL a b c coefficients of defining equations END TYPE line END MODULE geometricidata MODULE geometric jrocedures USE geometricidata IMPLICIT NONE CONTAINS SUBROUTINE lineitWOJoints lineil pointil point72 IMPLICIT NONE Dummy arguments TYPEline INTENTOUT lineil TYPEpoint INTENTIN pointil point72 Calculate coefficients of equation representing the line lineila point72y pointily lineilb pointilX point72X lineilc pointilypoint72x point72ypointilx RETURN END SUBROUTINE lineitWOJoints END MODULE geometric jrocedures PROGRAM geometry USE geometric Jrocedures IMPLICIT NONE A program to test the subroutine lineitWOJoints Variable declarations TYPE point pl p2 TYPE line plit0J32 Read data WRITE quotPlease type coordinates of rst pointquot READ pl WRITE quotPlease type coordinates of second pointquot READ p2 Call procedure to calculate theequation of the line CALL lineitWOJoints p17I04p2 pl p2 Print result WRITE quotThe equation ofthe linejoining these two points is39 WRITE quotax by c 0quot WRITE quotwhere a quot p17I04p2a WRITE quot b quot plitoJ2b WRITE quot c quot p17I04p2C STOP END PROGRAM Geometry Chapter 5 Example 51 page 139 code modi ed for elf90 compiler PROGRAM wheatisowing IMPLICIT NONE A program to calculate the quantity of wheat required to sow a triangular eld Variable declarations REAL a b c s area density quantity INTEGER numibags Read the lengths ofthe sides ofthe eld WRITE quotType the lengths ofthe three sides ofthe eld amp ampin meters quot READ a b c Calculate the area of the eld s05 abc areaSQRTs s a sb s c Read sowing density WRITE quotWhat is the sowing density gmsqm quot READ density Calculate quantity of wheat and the number of full 10 kg bags quantity density area numibags 00001 quantity Any partfull bag is excluded Check to see if another bag is required IF quantity gt 10000 numibags THEN numibags numibags 1 END IF Print results WRITE quotThe area ofthe eld is quot area quotsq metersquot WRITE quotand quot numibags quot 10 kilo bags will be requiredquot STOP END PROGRAM wheatisowing Example 52 Page 143 modi ed for elf90 An external function that returns the cube root of its argument FUNCTION cubeirootx IMPLICIT NONE REAL cubeiroot Function to calculate the cube root of a real number Dummy argument declaration REAL INTENT IN x Local constant REAL PARAMETER epsilon lE20 Eliminate nearly zero case IF ABSx lt epsilon THEN cubeiroot 00 Calculate cube root by using loops ELSE IF x lt 0 THEN First deal with negative argument cubeiroot EXPLOGx30 ELSE Positive argument cubeiroot EXPLOGx30 END IF RETURN END FUNCTION cubeiroot Example 53 pages 144145 modi ed for elf90 It has two warning errors MODULE geometricidata IMPLICIT NONE Type de nitions TYPE point REAL X y Cartesian coordinates of the point END TYPE point TYPE line REAL a b c coef cients of de ning equations END TYPE line END MODULE geometricidata MODULE geometric jrocedures USE geometricidata IMPLICIT NONE CONTAINS SUBROUTINE lineitwoimints lineil pointil point72 status IMPLICIT NONE Dummy arguments TYPE line INTENTOUT lineil TYPE point INTENTIN pointil point72 INTEGER INTENTOUT status Check to see whether points are coincident IF pointilX point72X AND pointily point72y THEN Points are coincident return error ag status l ELSE Points are distinct so calculate the coef cients of the equation representing the line lineila point72y pointily lineilb pointilX pOIIII72X lineilc pointily point72X point72y pointilX Set status to indicate success status 0 END IF RETURN END SUBROUTINE lineitWOJoints END MODULE geometric jrocedures Example 54 page 150 modi ed for elf90 FUNCTION changeicase char IMPLICIT NONE CHARACTER LENl changeicase This function changes the case of its argument if is is alphabetic Dummy argument CHARACTER LEN1 INTENTIN char Local constant INTEGER PARAMETER upperitoilower IACHARquotaquot IACHARquotAquot Check if argument is lower case alphabetic upper case alphabetic or nonalphabetic IF quotAquot lt char AND char lt quotZquot THEN Upper case convert to lower case changeicase ACHARIACHARcharupperitoilower ELSE IF quotaquot lt char AND char lt quot2quot THEN Lower case convert to upper case changeicase ACHARIACHARchar upperitoilower ELSE Not alphabetic changeicase char END IF RETURN END FUNCTION changeicase Example 55 page 155 modi ed for elf90 PROGRAM seasons IMPLICIT NONE A program to calculate in which season a speci ed data lies Variable declarations CHARACTERLEN10 date CHARACTERLEN2 month Read date WRITE quotPlease type a date in the form yyyymmddquot READ date Extract month number month date67 Print season SELECT CASE month CASE quot08quotquot10quot WRITE date quot is in the springquot CASE quotl1quotquot12quotquot01quotquot03quot WRITE date quot is in the summerquot CASE quot04quotquot05quot WRITE date quot is in the autumnquot CASE quot06quot quot07quot WRITE date quot is in the winterquot CASE DEFAULT WRITE date quot is not a valid datequot END SELECT STOP END PROGRAM seasons Example 56a page 159160 modi ed for elf90 A program to solve a quadratic equation using a CASE statement to distinguish between the three cases PROGRAM quadraticibinASE IMPLICIT NONE Constant declaration REAL PARAMETER epsilon lE6 Variable declarations REAL a b c d sqrtid X1 X2 INTEGER selector Read coefficients WRITE quotPlease type the three coefficients a b and cquot READ a b c Calculate b2 4ac and resulting case selector d b2 40ac selector depsilon Calculate and print roots if any SELECT CASE selector CASE 1 Print roots sqrtid SQRTd X1 b sqrtidaa X2 b sq1t7daa WRITE quotThe equation has two roots quotXlquot and quotX2 CASE 0 One root X1 baa WRITE quotThe equation has one root quot Xl CASE 1 No roots WRITE quotThe equation has no real rootsquot END SELECT STOP END PROGRAM quadraticibinASE Example 56b page 160161 modi ed for elf90 A program to solve a quadratic equation using a block IF statement to distinguish between the three cases PROGRAM quadraticibyiblockiIF IMPLICIT NONE Constant declaration REAL PARAMETER epsilon lE6 Variable declarations REAL a b c d sqrtid X1 X2 Read coefficients WRITE quotPlease type the three coefficients a b and cquot READ a b c Calculate b2 4ac d b2 40ac Calculate and print roots if any IF d gt epsilon THEN Print roots sqrtid SQRTd Xl b sqrtidaa X2 b sqrtidaa WRITE quotThe equation has two roots quotXlquot and quotX2 ELSE IF d gt epsilon THEN One root Xl baa WRITE quotThe equation has one root quot Xl ELSE No roots WRITE quotThe equation has no real rootsquot END IF STOP END PROGRAM quadraticibyiblockiIF Chapter 6 Example 61 page 175 modi ed for elf90 compiler This program prints statistics about a set of exam results PROGRAM examinationimarks IMPLICIT NONE Variable declarations INTEGER i number mark amp sum 0 maximum HUGEl minimum HUGEl REAL average Read number of marks and then the marks WRITE quotHow many marks are there quot READ number WRITE quotPlease type quot number quot marks quot Loop to read and process marks DO il number READ mark On each pass update sum maximum and minimum sum sum mark IF mark gt maximum maximum mark IF mark lt minimum minimum mark END DO Calculate average mark and output results average REAL sumnumber WRITE quotHighest mark is quot maximum WRITE quotLowest mark is quot minimum WRITE quotAverage mark is quot average STOP END PROGRAM examinationimarks Example 62 page 177 modi ed for elf90 PROGRAM multiplicationitables IMPLICIT NONE A program to print multiplication tables from 2 to 12 times Variable declarations INTEGER i j Outer loop de nes which times table39 DO i 2 12 WRITE quot quot WRITE i quot times tablequot DOj 1 12 WRITE i quot times quotj quot is quot ij END DO END DO STOP END PROGRAM multiplicationitables Example 63 page 178 modi ed for elf90 A program to print multiplication tables from 2 to 12 times PROGRAM multiplicationitables IMPLICIT NONE A program to print multiplication tables from 2 to 12 times Variable declarations INTEGER ij Outer loop de nes which 39times table39 DO i2 12 WRITE quot quot WRITE i quot times tablequot DO j1 i WRITE i quot times quotjquot is END DO END DO STOP END PROGRAM multiplicationitables 1J Example 64 pages 182183 modi ed for elf90 compiler This program calculates some simple examination statistics PROGRAM examinationistatistics IMPLICIT NONE Constant and variable declarations INTEGER PARAMETER manupils 100 INTEGER student mark numjupils numiboys 0 numigirls 0 amp totalimarks marksiboys 0 marksigirls 0 CHARACTERLEN1 code Read at most manupils sets of data WRITE quotType up to quot manupils quot exam resultsquot WRITE quotEach result must consist of the student number amp ampthe mark and a codequot WRITE quotThe code is F for a female student and M for a malequot WRITE quotData should be ended by a zero student number and amp ampmark followed by any code other than M or Fquot DO numjupils l manupils Read next mark and code READ student mark code IF student 0 EXIT Select appropriate action SELECT CASE code Female pupil CASE quotFquot numigirls numigirls l marksigirls marksigirls mark Male pupil CASE quotMquot numiboys numiboys l marksiboys marksiboys mark End of Data CASE DEFAULT EXIT END SELECT END DO Adjust numjupils to correct number numjupils numjupils l Calculate to tal marks totalimarks marksiboys marksigirls Calculate and print averages IF numjupils 0 THEN WRITE quotThere was no dataquot ELSE Deal with no terminator case IF numjupils max Jupils THEN WRITE max jupils quot sets of data read without a amp ampterminating recordquot WRITE quotResults are based on these pupils onlyquot END IF WRITE quotThere are quot numjupils quot pupils Their average amp ampmark is quot REALtotalimarksnumJupils IF numigirls gt 0 THEN WRITE quotThere are quot numigirls quot girls Their amp ampaverage mark isquot REALmarks7girlsnum7girls ELSE WRITE quotThere are no boys in the classquot END IF END IF STOP END PROGRAM examinationistatistics Chapter 8 Example 82 modi ed for elf90 It compiles but does not run io statements should be changed for le io PROGRAM Radioactiveidecay IMPLICIT NONE This program processes experimental data relating to radioactive decay Constant declarations maxireadings is maximum number of sets of data in and out are the unit numbers for reading and writing INTEGER PARAMETER maxireadings 1000 Variable declarations INTEGER alpha beta gamma i maxiinterval 0 REAL time lastitime 00 period amp avialpha avibeta avigamma maxiavigamma 00 Print headings

### BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.

### You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

#### "There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

#### "When you're taking detailed notes and trying to help everyone else out in the class, it really helps you learn and understand the material...plus I made $280 on my first study guide!"

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

#### "Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.