Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R 2 nd Year C and R Workshop Part of module PA2930 – 2.5 credits Venue: Computer terminal.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 1 Engineering Problem Solving.
Advertisements

Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
COSC 120 Computer Programming
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
1 Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition by Tony Gaddis, Judy Walters,
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Chapter Introduction to Computers and Programming 1.
Python Mini-Course University of Oklahoma Department of Psychology Day 1 – Lesson 2 Fundamentals of Programming Languages 4/5/09 Python Mini-Course: Day.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
COMP1070/2002/lec3/H.Melikian COMP1070 Lecture #3 v Operating Systems v Describe briefly operating systems service v To describe character and graphical.
Overview of Linux CS3530 Spring 2014 Dr. José M. Garrido Department of Computer Science.
Introduction to Shell Script Programming
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Gator Engineering 1 Chapter 2 C Fundamentals Copyright © 2008 W. W. Norton & Company. All rights reserved.
Chapter 6: Shell Programming
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
UniMAP Sem1-08/09EKT120: Computer Programming1 Week 1 – Lecture 1.
Programming With C.
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
Computer Science 101 Introduction to Programming.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
EG280 Computer Science for Engineers Fundamental Concepts Chapter 1.
Getting started: Basics Outline: I.Connecting to cluster: ssh II.Connecting outside UCF firewall: VPN client III.Introduction to Linux IV.Intoduction to.
C Language: Introduction
I Power Higher Computing Software Development Development Languages and Environments.
Computing Systems & Programming ECE Fundamental Concepts Chapter 1 Engineering Problem Solving.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Introduction to programming Carl Smith National Certificate Year 2 – Unit 4.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Introduction to C – Part 1.
JavaScript 101 Introduction to Programming. Topics What is programming? The common elements found in most programming languages Introduction to JavaScript.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Chapter 1: Introduction to Computers and Programming.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
CHAPTER 1 OVERVIEW OF COMPUTER AND PROGRAMMING 1.1 Electronic Computer Then and Now 1.2 Computer Hardware 1.3 Computer Software 1.4 The Software Development.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
Chapter 1: Introduction to Computers and Programming
BASIC PROGRAMMING C SCP1103 (02)
CS1010: Intro Workshop.
Engineering Problem Solving With C An Object Based Approach
Chapter 1: Introduction to computers and C++ Programming
Introduction to Computer CC111
Key Ideas from day 1 slides
Chapter 1: An Overview of Computers and Programming Languages
BASIC PROGRAMMING C SCP1103 (02)
Week 1 – Session 1 Pn. Yasmin Yacob 04 – KUKUM Sem2-06/07
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Choice of Programming Language
11/10/2018.
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Programming Logic and Design Eighth Edition
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R 2 nd Year C and R Workshop Part of module PA2930 – 2.5 credits Venue: Computer terminal rooms G+H Duration: 4x3 hour workshop sessions Script on web: Re-read the script of the 1 st year workshop

Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R Purpose of the Workshop Programming in C on a Linux machine (SPECTRE) –Editing source files, compiling and running a C program –Variables and data types, arithmetic and mathematical functions –Printing output, reading data –Symbolic constants and preprocessor –Repetition –Logical and relational operators, conditional structures –Arrays and pointers –Defining and using functions Using R to plot data created by a C program Using R to call C functions directly

Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R What is LINUX (UNIX)? It is an operating system widely used by scientific programmers It is designed for software development rather than just software usage The simple interface between the user and the system is called a shell There is a core of commands/applications common to all flavours Now has a full Windows-like interface

Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R Why C? It is probably the best general purpose programming language It is ubiquitous It is easy to translate programs from C into other procedural languages, e.g. Fortran It is an excellent vehicle for teaching low- level procedural programming Programming using C is a useful skill for many careers

Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R Getting started with SPECTRE Logon to a UoL IT Windows machine Use the X-Terminal client NX to connect to SPECTRE (only need to install NX once) –Start  Program Installer  NX Client click –Start  All Programs  NX Client click SPECTRE click Logon to SPECTRE using you UoL IT username and password Start a terminal window on SPECTRE –Applications  Accessories  Terminal click

Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R Shell commands and files The default shell on SPECTRE is Bash (Bourne again shell) –prompt will look like Files are organised in a directory tree Commands are like R but no () required –pwd print working directory – cd to change directory – ls to list files in a directory There are 2 basic forms of file –Text files – contain just printable and simple control characters (carriage return, line feed, tab) – can be read or printed out –Binary files – contain binary codes, binary numbers… can only write or read using computer programs

Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R Creating a text file with an editor Use the command –$ nedit afile.txt & $ is the shell prompt nedit is the command which starts the text editor afile.txt is the name of the file & runs the editor as a background task Use the File tab (top left) to Save the file (but leave the editor running) Use the mouse to switch focus to terminal Use command –$ more afile.txt –This lists file at the terminal

Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R Creating/Compiling a C program Use the text editor to create a source text file $ nedit myprog.c & Use the compiler to translate (compile) the program into object code (in a binary file) $ cc myprog.c –o myprog Check your files – source file and executable file $ ls myprog myprog.c Run the program $./myprog

Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R Algorithms and procedural programming An algorithm is a specified sequence of steps which will solve a problem Procedural programming is used to implement algorithms In the 1 st and 2 nd Year workshops you learn the elements of procedural programming using R and C These same elements are common to all languages They enable you to solve many, many problems

Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R The structure of algorithm/program There are usually 3 phases: –Setting up – defining variables, getting data –Performing a sequence of manipulations, arithmetic, decisions and repetitions –Listing or saving the answers and clearing up In many languages the program is broken into lines or statements. There are 2 kinds of statement: –Instructions to the compiler to set up the problem – these do something during the compilation process –One step in the algorithm or procedure- these do something when the program is run

Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R The anatomy of a C program /* prog1 - a simple first program in C */ #include int main() { /* Declare variables */ float a, b, sum; /* Assign values to variables */ a = 10.0; b = 2.0; /* Calculate the sum, print it out */ sum = a + b; printf("The sum is %f\n", sum); }

Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R Elements of procedural programming Operators – arithmetic, logical In-built functions Scalar variables, arrays, structures Referencing components Listing – controlling precision Input/Output (IO) of data (from/to terminal, files…) User defined functions Conditional structures (If else…) Repetition (for, while…)