E0001 Computers in Engineering Built in Functions.

Slides:



Advertisements
Similar presentations
Computer Programming w/ Eng. Applications
Advertisements

CS 1400 Chapter 2 sections 1, 2, 4 – 6, 8,
Computer Science 1620 Variables and Memory. Review Examples: write a program that calculates and displays the average of the numbers 45, 69, and 106.
1 BIL106E Introduction to Scientific & Engineering Computing Organizational matters Fortran 90 ( subset F ): Basics Example programs in detail.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Chapter 1 Sections 1.3 & 1.4.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Signed Numbers, Powers, & Roots
Numeric precision in SAS. Two aspects of numeric data in SAS The first is how numeric data are stored (how a number is represented in the computer). –
Chapter 3 COMPLETING THE BASICS Programming Fundamentals with C++1.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
1 Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 2 Primitive Data Types and Operations.
1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
A First Book of ANSI C Fourth Edition Chapter 3 Processing and Interactive Input.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
E0001 Computers in Engineering Procedures: subprograms and functions.
Input, Output, and Processing
Formatting, Casts, Special Operators and Round Off Errors 09/18/13.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
C++ Programming: Basic Elements of C++.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
1 E0001 Computers in Engineering Built in Functions.
Fundamental Programming: Fundamental Programming Introduction to C++
Introduction to Programming with RAPTOR
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 3: Assignment, Formatting, and Interactive Input.
C++ for Engineers and Scientists Second Edition Chapter 3 Assignment, Formatting, and Interactive Input.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
Expressions and Interactivity. 3.1 The cin Object.
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Two: Fundamental Data Types Slides by Evan Gallagher.
Hungarian Notation A must in this course Every object used MUST be renamed including the form(s) using the following rules Form  frmFormName E.g. frmTemperature.
3. COMPUTING WITH NUMBERS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
Programming Fundamentals with C++1 Chapter 3 COMPLETING THE BASICS.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Chapter 3 Numerical Data. Objectives After you have read and studied this chapter, you should be able to Select proper types for numerical data. Write.
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
Assignments. Assignment 1 Write a program to calculate the current equation Where p is the period of pendulum in seconds, g=980 cm/sec 2 (acceleration),
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
1 float Data Type Data type that can hold numbers with decimal values – e.g. 3.14, 98.6 Floats can be used to represent many values: –Money (but see warning.
Chapter Topics The Basics of a C++ Program Data Types
Topics Designing a Program Input, Processing, and Output
Computing Fundamentals
Basic Elements of C++.
The Selection Structure
Basic Elements of C++ Chapter 2.
IDENTIFIERS CSC 111.
INPUT & OUTPUT scanf & printf.
Create an Excel worksheet that will convert inches to one of the following metric units: millimeters, centimeters, meters, or kilometers, depending on.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
C++ for Engineers and Scientists Second Edition
Presentation transcript:

E0001 Computers in Engineering Built in Functions

General Notes zError in Assignment A-E & M-R - TYPO Volume should be , 22.44, 5.77 zAssignment S-Z constant = 2.749*10 -8 zAssignment 2 due 9 April but …. submit until 12 April zAss1 and 2 handed back after holidays..

Readings and Exercises zSchneider Section 3.4 p zSchneider Practice Problems 3.4 p 78; programming problems #’s 57, 60, 62, 66, 68

Rem statements zRem short for REMARK zused for adding comments to code zuseful for the programmer, not the user znon executable line zTwo ways of adding comments yREM y‘

Examples REM this line is a comment REM This program will calculate…. REM This program was written by…. INPUT r,b,h‘radius, base, height READ n$, no$‘name, number

Numeric Functions zcovers common numeric and trigonometric terms ysquare root - SQR(x) ySIN(angle), COS(angle), TAN(angle) xBEWARE - (angle) must be in RADIANS yLOG (x) zsee handout for more examples

Examples of Numeric Functions zSQR (x) - square root of x where x is yvariable - given a value by the program or the user yarithmetic operation - (6-4)/360*12 zABS - absolute value yABS(-3) = 3; ABS(7) = 7 yABS(SQR(CINT(x)))

String Functions zallows examining strings or parts; combining strings zallows string comparisons using, = (relational operators)

Examples of String Functions zLEN(s) - s is known as the argument yreturns the length of the argument i.e. the number of characters contained in the argument yblanks are counted as characters yLEN(“John and Mary”) = 13 yZ$ = “John and Mary”: LEN(Z$) = 13 yIF LEN(Z$) = 20 THEN PRINT “HELLO”

zLEFT$(x$, n) - x$ is any string; n is an integer from 0 to LEN(x$) yx$ = “John and Mary” yPRINT LEFT$(x$,4) - gives the output John zsee also MID$(x$,n,m) and RIGHT$(x$,n) zLCASE$(X$); UCASE$(X$); INSTR(n,X$,Y$) zVAL(X$) - converts a string whose contents represent a number to its numerical form. yignores leading blanks yconverts a string up to its first nonnumerical character into its numerical value.

Built-in Functions zprewritten “subroutine” that does one operation zreturns ONE value only zimplimented by arithametic statement yvariable = equation zdesigned to manipulate both numerical and string data zcover common calculations

Computers in Engineering PRINT USING STATEMENT

Overview In a circuit three currents are represented by the variables cur1, cur2, cur3 Plan and write a program to input these values and calculate and display the average current

Plan zOutputs… zInputs…. zProcess… zflowchart/plan/pseudocode

INPUT statements Write input statements to enter these variables INPUT “current 1”, cur1 INPUT “current 2”, cur2 INPUT “current 3”, cur3

In Memory User enters 9.16, 12.4, 0.9 cur cur cur3 0.9

Calculate total and average currents and print totCur = cur1 + cur2 + cur3 AvgCur = totCur / 3 PRINT, cur1 PRINT, cur2 PRINT, cur3 PRINT, “________” PRINT, TotCur PRINT “Average”, AvgCur

Qbasic Screen

To add units to a variable PRINT “Current”; cur1; “amps” PRINT “prompt” ; variable list ; “prompt”

PRINT USING zPRINT USING statement can be used instead of PRINT to make decimal points line up zhas general form - PRINT USING “format string”;expression list e.g PRINT USING “##.##”; cur1

Format string zString of characters yletters, numbers, punctuation zsome have special meanings yif no special meaning qb will simply display it on the screen yif has special meaning qb uses it to determine the format for displaying one of the expressions in the list

Formatting numbers z# # #.# # ydisplays 3 digits preceding the decimal xfewer than 3 before qbasic leaves a space xmore than 3 - will be displayed correctly but in a different format, will also precede it with a % character ydisplays 2 digits after the decimal xfewer than 2 - displays zeros for the missing digits xmore than 2 - displays the rounded value

Format string Fmt$ = “current is ##.## at ###.# volts” PRINT USING Fmt$; cur; volts c.f. PRINT USING “format string”;expression list

Scientific notation - e.g. 2E-6 z^^^^ yrepresent positions for E, minus or plus sign, two digit exponent z^^^^^ yfor double precision numbers yrepresent positions for E, minus or plus sign, three digit exponent ze.g. FMT$ = “current is ##.###^^^^ at ##.#### ^^^^ volts”

Output? Current is 23.5, volts are FMT$ = “current is ##.###^^^^ at ##.####^^^^ volts” Current is 2.350E+01 at E+02 volts zadditional strings can be added yFMT$ = “current is & ##.###^^^^ at ##.####^^^^ volts” ycurType$ = “direct” yPRINT USING Fmt$; curType$; cur; volts Current is direct 2.350E+01 at 1.176E+02 volts

Take a break Return for assignments

zWrite a program to convert a US customary system length in miles, yards, feet and inches to a Metric System length in kilometres, meters and centimetres. After the number of miles, yards, feet and inches are requested as input, the length should be converted entirely to inches and then divided by to obtain the value in meters. The INT function should be used to break the total number of meters into a whole number of kilometres and meters. The number of centimetres should be displayed to one decimal place. Some of the needed formulas are: zTotal inches = * miles + 36 * yards + 12 * feet + inches zTotal meters = total inches / zKilometres = INT (meters/1000)

zKepler's Third Law states that for objects with an elliptical orbit (such as satellites orbiting Earth or planets orbiting the sun), the square of the Period is proportional to a 3, where a is half the length of the major axis of the ellipse. For nearly circular satellite orbit above Earth, a can be approximated by the radius of the earth plus the altitude of the satellite. Thus za ~ 6378 kilometers + altitude zIf the Period is expressed in minutes and the length of the major axis is expressed in kilometers, then zPeriod 2 = 2.749E-8*10 -4 *a 3 zWrite a program to produce the table shown below. The information in the first two columns should be stored in DATA statements and the period should be computed and displayed to an appropriate number of decimal places. Type of SatelliteAltitude (km)Period (minutes) Earth imaging400 Low-altitude communications1500 Geosynchronous communication35789

zThe general law of perfect gases states that PV / T = n R = constant zwhere P is the gas pressure (in atmospheres), V is the volume (in litres), T is the temperature (in degrees Kelvin), n is the number of moles, R is the constant of perfect gases (0.82 Liter- atm/Kelvin-mole).

zWrite a program to produce the table for the case n=1 thus giving V = RT/P. The user with an INPUT statement should enter a temperature (in Celsius) and pressure. Two new temperatures (in Celsius) should be calculated from the original, one increased by 50 0 and one decreased by A corresponding pressure for each new temperature should be entered by the use of an INPUT statement. The temperature in Kelvin and the Volume should be calculated for the three temperatures and displayed. A sample output is shown below:

 TemperaturePressureTemperature Volume  (Celsius)(atm)(Kelvin)(liter)   

 The period P of a pendulum of length L and maximum displacement angle  is given by the formula P = write a program that requests as input the length and maximum angle of displacement, and displays the period of the pendulum Problem

Tutorial 1. What will be the contents of x after the following statement is executed? LET x = SQR((9 + 7) / ( 4 * 2) + 2) 2. Suppose num = What is the output? LET num = INT(100 * num +.5) / 100 PRINT num

3. What output is generated by the following statements (show the output EXACTLY as it would appear on the screen)? PRINT SQR (3^2 + 4^2) PRINT MID$ ("Milkshake", 5, 5) PRINT UCASE$ ("123jump") 5 shake 123JUMP try this for yourself

4. The following statements are valid. (T/F) LET H$ = "Hello" LET a$ = INSTR(H$, 3) 5. Given the data in the variable y$ shown below, which of the following statements will assign the value ALL to x$? LET y$ = "WHEN ALL ELSE FAILS, READ THE DIRECTIONS" (a) LET x$ = MID$(y$, 6, 3) (b) LET x$ = INSTR(6, y$, "ALL") (c) LET x$ = LEFT$(y$, 3) (d) LET x$ = MIDDLE$(y$, 6, 3) (e) LET x$ = RIGHT$(y$, 8)

6. What will be displayed when the following program is executed? LET a$ = "THE WHOLE" LET b$ = "PART" LET c$ = MID$(a$, SQR(4), LEN(b$)) PRINT c$ END

The End