Chapter 3 (Tutorial).

Slides:



Advertisements
Similar presentations
Chapter 3 IF & SELECT. Control Constructs: Branches Definitions: Code: statements or expressions in a program Block: a group of codes Branching: selecting.
Advertisements

Introduction to arrays
Exercise (1).
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.
Chapter 3 Program Design And Branching Structures.
You can select between blocks of statements by using the selection construct IF statement is used as a selection construct Four types of IF constructs.
Selection (decision) control structure Learning objective
Subject: Information Technology Grade: 10
Chapter 1.1 Sets of Real Numbers Real Life Situations.
Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
Chapter 4. Loops and Character Manipulation Loops in FORTRAN are constructs that permits us to execute a sequence of statements more than once. Type of.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Java Programming Practice.
1 Controlling Script Flow! David Lash Chapter 3 Conditional Statements.
Creating a “What-If” Spreadsheet Application GPA Prediction Calculator.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
FORTRAN PROGRAMMING BASICS MET 50. Programming Basics The basic layout of all programs is as follows (p.33) PROGRAM name = heading (i.e., title) Specifications.
Section 1.3 Prime numbers and fractions
1 CS 415: Programming Languages Fortran Aaron Bloomfield Fall 2005.
Additional Features – GPA Calculator GPA Calculator There are two options for the GPA Calculator: the Graduation Calculator and the Advice Calculator.
Ch Electricity IV. Measuring Electricity (p )  Electrical Power  Electrical Energy.
KENNARD-DALE HIGH SCHOOL COURSE SELECTION INFORMATION.
U SING V ARIABLES IN V ISUAL B ASIC Intermediate 2 Software Development.
 Senior timeline  Graduation Plans  College Information  Career Planning  College Selection & Admissions  SAT & ACT  Financial Aid.
DARSweb Beginning/Degree Program Training Beginning/Degree Program Training1.
CSEB114: Principle of programming
CS102 Introduction to Computer Programming Chapter 4 Making Decisions.
You can select between blocks of statements by using the selection construct IF statement is used as a selection construct Four types of IF constructs.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
A First C Program /* Print a Message */ #include main() { printf("This is a test!\n"); } The program is compiled and run as cc pg32.c  a.out  This is.
How to calculate your GPA
CSE 201 – Elementary Computer Programming 1 Extra Exercises Source: Suggested but not selected midterm questions.
Infinite Campus Student Portal. From any HVRSD webpage ( choose Students > Infinite Campus.
Function Problems. Write Functions Asks users whether the user wants to continue of not, then returns the answer. Takes two integers and returns 1 if.
Previously Repetition Structures While, Do-While, For.
How To Log On the Computer At School A Tutorial for Preschoolers and Kindergarteners.
Writing JavaScript Functions. Goals By the end of this unit, you should understand … How to breakdown applications into individual, re-usable modules.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X1 Chapter 3 Control Statements.
Getting Started with GradeQuick. Logging In to GradeQuick Shortcut on the Start Menu First time users enter first initial last name like this (ccornwell)
Chapter 6. else-if & switch Copyright © 2012 Pearson Education, Inc.
Changing Your Password General Lesson 3. Objectives Following completion of this lesson you will be able to:. Define how often a password must be changed.
Student Experience It’s your education Type the web site address into the browser given to you by your junior high or high school Select “I am a student”
How to Reset Your APICS Password Tutorial Also available at:
Credit-Grade based Performance and Assessment (CGPA) System.
Subroutines II. An Extended Example Subroutines are best used to simplify large and unwieldy programs. Here is one example of why and how they should.
Introduction to Computer Sciences References: [1] Fortran 95/2003 for Scientists and Engineers (3e) by Stephen J. Chapman. [2] Using Fortran 90 by Chester.
Calculating Your GPA By Tara L. Davis 2008 For use with the lesson and handout: “Calculating Your GPA” Images used for educational purposes only.
Algorithms, Part 3 of 3 Topics In-Class Project: The Box
CFISD GPA GRADING SCALE
Getting Started with GradeQuick. Logging In to GradeQuick Shortcut on the Start Menu First time users enter first initial last name like this (ccornwell)
CHAPTER 2:BASIC FORTRAN Data Types INTEGER REAL COMPLEX CHARACTER LOGICAL.
What is Canvas?. Log ins  Novell  Computer  Portal  Canvas  Gmail   Password is school ID  Apple.
Flow chart of the program Start Input a password Is it greater than 6 characters No Is it greater than 6 characters Is it greater than 12 characters yes.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
MATLAB – More Script Files
ECE Application Programming
Chapter 1 Introduction to Java
Chapter 1. Introduction to Computers and Programming
HOW TO CALCULATE YOUR GPA
Academic Probation Flow Chart
WebADVISOR HANDBOOK FOR FACULTY
IV. Measuring Electricity
Student Experience It’s your education.
How to Calculate your Grade Point Average
Data Types and Maths Programming Guides.
My Plan for Success Student Name.
Brian Tucker Debbie Novosad Carolyn Von Haefen
REPETITION Why Repetition?
Presentation transcript:

Chapter 3 (Tutorial)

IF & CASE flow chart

PROGRAM if IF (consumed <250) THEN cost = consumed * 5 PROGRAM POWER_CONSUMPTION IMPLICIT NONE INTEGER :: consumed REAL :: cost WRITE (*,*) 'Enter consumed power (kWh) = ' READ (*,*) consumed IF (consumed <250) THEN cost = consumed * 5 ELSEIF (consumed <500) THEN cost = consumed * 10 ELSE cost = consumed * 20 END IF WRITE (*,*) 'Payment = RO ', cost/1000 END PROGRAM PROGRAM if

PROGRAM case PROGRAM POWER_CONSUMPTION IMPLICIT NONE INTEGER :: consumed REAL :: cost WRITE (*,*) 'Enter consumed power (kWh) = ' READ (*,*) consumed SELECT CASE (consumed) CASE (:249) cost = consumed * 5 CASE (250:499) cost = consumed * 10 CASE DEFAULT cost = consumed * 20 END SELECT WRITE (*,*) 'Payment = RO ', cost/1000 END PROGRAM PROGRAM case

If (logical_expr) GO TO 333 No Yes Go To 333

If (logical_expr) GO TO PROGRAM Password_Check IMPLICIT NONE CHARACTER (len = 8) :: password 333 WRITE (*,*) ‘ENTER PASSWORD’ write (*,*) READ (*,*) password If (password /= ‘fortran’) GO TO 333 WRITE (*,*) “ OK, Password correct.” END PROGRAM

Integrate all in one

Integrate all in one PROGRAM Protected_Power IMPLICIT NONE CHARACTER (len = 8) :: password INTEGER :: consumed REAL :: cost 333 WRITE (*,*) 'ENTER PASSWORD' write (*,*) READ (*,*) password If (password /= 'fortran') GO TO 333 WRITE (*,*) 'Enter consumed power (kWh) = ' READ (*,*) consumed SELECT CASE (consumed) CASE (:249) cost = consumed * 5 CASE (250:499) cost = consumed * 10 CASE DEFAULT cost = consumed * 20 END SELECT WRITE (*,*) 'Payment = RO ', cost/1000 END PROGRAM

One more trick Make a non-terminated program that is always waiting for consumed power to calculate cost.

One more trick PROGRAM nonTerm_Power IMPLICIT NONE CHARACTER (len = 8) :: password INTEGER :: consumed REAL :: cost 333 WRITE (*,*) 'ENTER PASSWORD' write (*,*) READ (*,*) password If (password /= 'fortran') GO TO 333 444 WRITE (*,*) 'Enter consumed power (kWh) = ' READ (*,*) consumed SELECT CASE (consumed) CASE (:249) cost = consumed * 5 CASE (250:499) cost = consumed * 10 CASE DEFAULT cost = consumed * 20 END SELECT WRITE (*,*) 'Payment = RO ', cost/1000 GO TO 444 END PROGRAM

Practical Exercise Design a FORTRAN program for the following problem and run it on computer. A student need to calculate the GPA of a semester that consists of six courses. The user should enter course number, course credits and grade letter for each course. The ouput should be the overall semester GPA and total number of credits earned.