Character (String) Data

Slides:



Advertisements
Similar presentations
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Advertisements

Functions Most useful programs are much larger than the programs that we have considered so far. To make large programs manageable, programmers modularize.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
6 April, 2000 CS1001 Lecture 15 EXAM1 - results SUBPROGRAM - - revisit FUNCTION.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
27 March, 2000 CS1001 Lecture 16 FUNCTIONS SUBROUTINES SCOPE MODULES EXTERNAL SUBPROGRAMS.
Chapter 9 Modules and Programming with Functions.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
6 April, 2000 CS1001 Lecture 13 PRACTICE EXAM - revisit SUBPROGRAM FUNCTION.
Abstract Data Types and Encapsulation Concepts
1 CS101 Introduction to Computing Lecture 29 Functions & Variable Scope (Web Development Lecture 10)
Functions. Program complexity the more complicated our programs get, the more difficult they are to develop and debug. It is easier to write short algorithms.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Chapter 7 Designing Classes. Class Design When we are developing a piece of software, we want to design the software We don’t want to just sit down and.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
Functions. Type of Subprograms Fortran 90/95 allows for two types of subprograms: –Functions, and –Subroutines. In general, there are two forms of subprograms:
1 CS Programming Languages Class 15 October 17, 2000.
CPS120: Introduction to Computer Science Decision Making in Programs.
CPS120: Introduction to Computer Science Lecture 14 Functions.
I Power Higher Computing Software Development High Level Language Constructs.
Beginning Fortran Fortran (77) Advanced 29 October 2009 *Black text on white background provided for easy printing.
Scripting Languages Diana Trandab ă ț Master in Computational Linguistics - 1 st year
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
A FIRST BOOK OF C++ CHAPTER 6 MODULARITY USING FUNCTIONS.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
Python Let’s get started!.
Beginning Fortran Introduction 13 October 2009 *Black text on white background provided for easy printing.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Module 9: Operator overloading #1 2000/01Scientific Computing in OOCourse code 3C59 Module 9: Operator Overloading In this module we will cover Overloading.
CSCE Do Loops Simplest form DO j = 1,100 PRINT *,j END DO Variable j runs from 1 to 100 counting by ones.
Information and Computer Sciences University of Hawaii, Manoa
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
Friend functions, operator overloading
Functions and Subroutines
Content Programming Overview The JVM A brief look at Structure
CS 326 Programming Languages, Concepts and Implementation
Java Applet Programming Barry Sosinsky Valda Hilley
A basic tutorial for fundamental concepts
Python Let’s get started!.
Formatting Output.
CMSC201 Computer Science I for Majors Lecture 12 – Lists (cont)
CS 326 Programming Languages, Concepts and Implementation
Programming Mehdi Bukhari.
Miscellaneous Items Loop control, block labels, unless/until, backwards syntax for “if” statements, split, join, substring, length, logical operators,
CS/COE 0449 (term 2174) Jarrett Billingsley
Week 4 - Monday CS222.
Data Structures Recursion CIS265/506: Chapter 06 - Recursion.
User-Defined Functions
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Strings, Line-by-line I/O, Functions, Call-by-Reference, Call-by-Value
Computational Methods of Scientific Programming
Functions BIS1523 – Lecture 17.
File Handling Programming Guides.
Exceptions with Functions
Number and String Operations
Functions In Matlab.
Variables Title slide variables.
Testing and Repetition
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Chapter 8 - Functions and Functionality
Class code for pythonroom.com cchsp2cs
Lecture 3 More on Flow Control, More on Functions,
Presentation transcript:

Character (String) Data Character data in an programming language is always a little tricky. CHARACTER name (for single character variables) CHARACTER name(n) for strings of characters The tricky part always comes down to: CHARACTER name(100) = ‘Duncan Buell’ The first 12 characters of this string are obviously ‘Duncan Buell’, but what gets stored in the rest of the string? CSCE 206

Character (String) Data Character strings in scientific computing are usually labels on other data. There are functions that handle character strings. There is a collating sequence or sort order for character strings. Usually character data will be sorted lexicographically (in dictionary order), with the strings left justified. (We may or may not get to the issue of the collating sequence.) CSCE 206

The End CSCE 206

Subprograms The power of a computer comes from conditional execution (IF-THEN-ELSE) and from iteration (DO loops). Programs would be much less useful if done as straight line code. Subprograms in Fortran are either subroutines or functions. Functions work like mathematical functions—arguments are passed in to the function, and a function value is returned. Subroutines allow for returning more than one value. CSCE 206

Builtin Functions See pages 324-325 for some builtin functions. CSCE 206

Functions DO n = 1, 10 PRINT *,a*n**2 + b*n + c END DO can be replaced by f = f_of_n(a,b,c,n) PRINT *,a,b,c,n,f then later on INTEGER FUNCTION f_of_n(a,b,c,n) INTEGER :: a,b,c,n f_of_n = a*n**2 + b*n + c RETURN END CSCE 206

Functions -- Rules Variables in the calling program are completely independent of variables in the subprogram, so you can have an x in each and they are different. The region of code over which a variable is defined is called its scope. Variables must be declared in the subprogram. If the value of variable that is an argument to a subprogram is changed inside the subprogram, then that change is propagated to the calling program as well. Unless the INTENT(IN) spec is used. CSCE 206

The End CSCE 206

Functions—Internal, External, Modules Four ways to do functions—this is too many, IMO I cover this only to explain what you’ll find in the book. Essentially, the only differences are in the scope of the function names and the variables. And everything I say about functions is also true for subroutines CSCE 206

First: A Word about Compilation When the compiler has finished, virtually all of the symbols in your program have disappeared This sort of includes the function names themselves, which is the point of this whole section of the lecture. If your calling program wants to call a function, there has to be a way for the function’s symbol (i.e., name) to be recognizable by the compiler. CSCE 206

ONE: EXTERNALLY Defined Functions PROGRAM version_one IMPLICIT none INTEGER my_function f = my_function(arguments) END PROGRAM version_one INTEGER FUNCTION my_function(arguments) my_function = whatever RETURN END my_function The function code lies OUTSIDE the calling program. CSCE 206

TWO: INTERNALLY Defined Functions PROGRAM version_one IMPLICIT none ! INTEGER my_function (NO LONGER NECESSARY) f = my_function(arguments) STOP CONTAINS INTEGER FUNCTION my_function(arguments) my_function = whatever RETURN END my_function END PROGRAM version_one The function code lies INSIDE the calling program. CSCE 206

Functions—Internal, External, Modules External: The function name must be declared and typed in the calling program, because the function “isn’t visible” outside the calling program. Internal: The function name must NOT be declared, because the INTEGER FUNCTION (or similar) declaration does the declaration. But you need the CONTAINS statement—in essence, this tells the compiler that what follows are functions/subroutines and not CSCE 206

Functions—Internal, External, Modules External: The functions are compiled as independent units. All the variables have local scope. This has advantages we won’t go into now. Internal: Everything about the functions can be hidden, which facilitates the current fashionable mode of object-oriented programming. Variables in the main program have global scope unless they are overridden in subprograms. Not everyone is a fan of OO. I personally find the internal method to be harder to keep straight in my head, but I’ll deny this if you report me to others. CSCE 206

THREE: Functions As Modules It is possible to define a function in one file and its calling program in another file, and then to compile the two files in a multistep process. In this case, there needs to be a way to link the symbols together, because the compilation processes are independent and wash away all the symbols. This is the way a lot of packages are written. (This makes your own functions look like the builtin functions.) CSCE 206

Functions—Internal, External, Modules External: The functions are compiled as independent units. This has advantages we won’t go into now. Internal: Everything about the functions can be hidden, which facilitates the current fashionable mode of object-oriented programming. Not everyone is a fan of OO. But don’t say I told you so. CSCE 206

Functions—Bottom Line With external functions, or with separately compiled files, the ONLY symbols that still exist after the compile step are the names of the subprograms. All other symbols are local to the functions and have disappeared by the time the compilation finishes. This isn’t all that difficult to deal with. If you forget to declare something, then the compiler messages will indicate that by saying that the variables aren’t defined. CSCE 206

The End CSCE 206

Subroutines Functions take arguments and return a single value, just as does a mathematical function. Sometimes you want to use a subprogram because you’re going to use the same piece of code over and over again, and you want to encapsulate that code (and be able to guarantee that you can use variable names that won’t conflict with names used elsewhere in the program). CSCE 206

Subroutines SUBROUTINE my_sub_name(arguments) instead of REAL FUNCTION my_func_name(arguments) Called with CALL my_sub_name(arguments) instead of by invoking with variable_name = my_func_name(arguments) CSCE 206

Subroutines Since subroutine names are not symbols with data types, they do NOT need to be declared. And the name is NOT given a value inside the subroutine before executing the RETURN. Otherwise, all the same rules apply, with regard to local or global scoping, internal or external, etc…. CSCE 206

The End CSCE 206