CMPUT 201: Practical Programming Methodology. Guohui Lin Department of Computing Science University of Alberta September 2018

Similar documents
COP 3275: Chapter 02. Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA

CMSC 246 Systems Programming

Problem Set 1: Unix Commands 1

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

Mills HPC Tutorial Series. Linux Basics I

Practical Programming Methodology

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

Getting started with Hugs on Linux

Getting started with Hugs on Linux

Intermediate Programming, Spring Misha Kazhdan

Introduction. Overview of 201 Lab and Linux Tutorials. Stef Nychka. September 10, Department of Computing Science University of Alberta

Introduction: The Unix shell and C programming

Lecture 1. A. Sahu and S. V. Rao. Indian Institute of Technology Guwahati

Unix and C Program Development SEEM

EL2310 Scientific Programming

Programming in C First meeting Tiina Niklander

Beyond this course. Machine code. Readings: CP:AMA 2.1, 15.4

Perl and R Scripting for Biologists

Using the Unix system. UNIX Introduction

EL2310 Scientific Programming

Systems Programming and Computer Architecture ( ) Exercise Session 01 Data Lab

Programming for Engineers C Preprocessor

Laboratory 1 Semester 1 11/12

CpSc 1011 Lab 4 Formatting and Flow Control Windchill Temps

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Programming and Data Structure Laboratory (CS13002)

Exercise 1: Basic Tools

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

First steps on Linux and programming

CS Fundamentals of Programming II Fall Very Basic UNIX

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

A Brief Introduction to Unix

Operating System Labs. Yuanbin Wu

CISC 220 fall 2011, set 1: Linux basics

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Saint Louis University. Intro to Linux and C. CSCI 2400/ ECE 3217: Computer Architecture. Instructors: David Ferry

CSE 390a Lecture 2. Exploring Shell Commands, Streams, and Redirection

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi and Cyrill Stachniss

Week 2 C Fundamentals; Formatted Input/Output; int and float Types

Lab 1 Introduction to UNIX and C

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Warm-up sheet: Programming in C

CS101 Linux Shell Handout

Practical Session 0 Introduction to Linux

SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar)

Introduction: What is Unix?

CSE 351. Introduction & Course Tools

PDS Lab Section 16 Autumn Tutorial 1. Unix Commands pwd The pwd command displays the full pathname of the current directory.

Programming in C First meeting

EECS2301. Lab 1 Winter 2016

Lab 1 Introduction to UNIX and C

CS19001/CS19002 Programming and Data Structures Lab Autumn/Spring Semester. Introduction. Abhijit Das. January 4, 2015

CS 253: Intro to Systems Programming 1/21

1. The Mac Environment in Sierra Hall 1242

last time in cs recitations. computer commands. today s topics.

CENG 334 Computer Networks. Laboratory I Linux Tutorial

CS11001/CS11002 Programming and Data Structures Autumn/Spring Semesters. Introduction

Scripting Languages Course 1. Diana Trandabăț

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

CSE 15L Winter Midterm :) Review

CpSc 1111 Lab 1 Introduction to Unix Systems, Editors, and C

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Linux/Cygwin Practice Computer Architecture

Introduction to Linux

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

CSCI 4152/6509 Natural Language Processing Lecture 6: Regular Expressions; Text Processing in Perl

Part I. UNIX Workshop Series: Quick-Start

Basic UNIX commands. HORT Lab 2 Instructor: Kranthi Varala

CS11002 Programming and Data Structures Spring Introduction

CSCI 2132 Software Development. Lecture 8: Introduction to C

CSCI 2132 Software Development. Lecture 4: Files and Directories

UNIX Essentials Featuring Solaris 10 Op System

CSE 391 Lecture 1. introduction to Linux/Unix environment

Introduction in Unix. Linus Torvalds Ken Thompson & Dennis Ritchie

EKT332 COMPUTER NETWORK

Lecture 10: Potpourri: Enum / struct / union Advanced Unix #include function pointers

Fundamental of Programming (C)

CMPT 300. Operating Systems. Brief Intro to UNIX and C

Introduc)on to Unix and Perl programming

Unix Shells and Other Basic Concepts

COSC UNIX. Textbook. Grading Scheme

Sprint 2017, Sul Ross State University

Parallel Programming Pre-Assignment. Setting up the Software Environment

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

EE516: Embedded Software Project 1. Setting Up Environment for Projects

1. The Mac Environment in SIE 1222

CSC111 Computer Science II

Helpful Tips for Labs. CS140, Spring 2015

INTRODUCTION TO BIOINFORMATICS

BIOINFORMATICS POST-DIPLOMA PROGRAM SUBJECT OUTLINE Subject Title: OPERATING SYSTEMS AND PROJECT MANAGEMENT Subject Code: BIF713 Subject Description:

CSC209. Software Tools and Systems Programming.

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

The UNIX Operating System. HORT Lecture 2 Instructor: Kranthi Varala

COURSE PLAN COMPUTER INFORMATION TECHNOLOGY

Lecture 03 Bits, Bytes and Data Types

Summary of Last Class. Processes. C vs. Java. C vs. Java (cont.) C vs. Java (cont.) Tevfik Ko!ar. CSC Systems Programming Fall 2008

Answers to AWK problems. Shell-Programming. Future: Using loops to automate tasks. Download and Install: Python (Windows only.) R

Transcription:

CMPUT 201: Practical Programming Methodology Guohui Lin guohui@ualberta.ca Department of Computing Science University of Alberta September 2018

Lecture 1: Course Outline Agenda: Course calendar description Course objectives Student responsibilities Course official information introducing the team my office hours weekly plan mark distribution course policies final grade Introducing C Reading: eclass: https://eclass.srv.ualberta.ca/course/view.php?id=46976 Public webpage: https://www.cs.ualberta.ca/~ghlin/cmput201.php Textbook: Chapter 1 1

Lecture 1: Course Outline Major take-home messages: Computing science is not programming, but program design C language provides a set of tools Lectures on good practices of an intermediate programmer clear and simple preferred over clever and complex Students use C to program under the Linux environment reading (textbook, sample codes, sample solutions, etc.) work on lab exercises (30%, starting Monday September 10, 2018) work on assignments (15%) be prepared for quizzes (10%) and exams (15% + 30%) How to succeed: try it out search out: man, Google, discuss use debugger (gdb, valgrind) start your work AEAP! 2

Lecture 1: Course Outline Introducing C: History of C a byproduct of UNIX operating system a higher-level language than assembly mostly done in 1960s and 1970s standard C99 C influences many modern programming languages C++, Java, C#, Perl Strengths: efficiency, portability, power, flexibility, standard libraries low-level, access to machine-level concepts small, limited features permissive, you know what you are doing good for writing a paper Weaknesses: error-prone, difficult to understand, difficult to modify not good for writing a book Effective use of C stick to standard! 3

Lecture 1: Course Outline Explanation on Assignment #1: All three assignments together as a project Assignment #2 is built on Assignment #1 Continuingly, Assignment #3 is built on Assignments #1 & #2 Specifications for Assignment #1: 1. command-line options parsing 2. read in an instance, redirect, and validate 3. print out an instance, redirect 4. generate random instances Purchase a solution program? each costs you 1% (no matter you use the purchased program or not) [e.g., if your program is marked with x, then you get x 1, which can be negative] cannot be re-distributed (cheating penalty applies) need an email or written paper to confirm you understand all these 4

Agenda: CSC 159: ugxx.cs.ualberta.ca The Linux environment, shell commands demo remote login Editing: vi Example C programs celsius.c fibonacci.c Compilation we use the standard options: gcc -Wall -std=c99 celsius.c Running Reading: Textbook: Chapter 2 5

The UNIX/Linux shell: The machines in the CMPUT 201 lab are ugxx.cs.ualberta.ca, where XX ranges from 00 to 34 e.g., ug10.cs.ualberta.ca login as: ghlin ghlin@ug10.cs.ualberta.ca s password: Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.15.0-29-generic x86_64) Department of Computing Science University of Alberta Unauthorized use is prohibited. Problem reports can be made using mail to ist@ualberta.ca or https://www.ualberta.ca/computing-science/links-and-resources/technical-support Last login: Fri Aug 31 16:46:04 2018 from 129.128.184.5 ghlin@ug10:~> The shell prompts for commands to execute with ghlin@ug10 ls, mkdir, cd, cat, vi, gcc, cp, rm, mv,... man (manual pages are extremely useful) 6

The UNIX/Linux shell: For example, ghlin@ug10:~>man ls LS(1) User Commands LS(1) NAME ls - list directory contents SYNOPSIS ls [OPTION]... [FILE]... DESCRIPTION List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvsux nor --sort is speci fied. Mandatory arguments to long options are mandatory for short options too. -a, --all do not ignore entries starting with. -A, --almost-all do not list implied. and.. Manual page ls(1) line 1 (press h for help or q to quit) 7

The UNIX/Linux shell: Use an editor such as vi (vim, emacs) to create a new C source file if file exists, vi opens the file for editing for example (Pages 24 25), ghlin@ug10:~>vi celsius.c /* Converts a Fahrenheit temperature to Celsius */ #include <stdio.h> #define FREEZING_PT 32.0f #define SCALE_FACTOR (5.0f / 9.0f) int main(void) { float fahrenheit, celsius; printf("enter Fahrenheit temperature: "); scanf("%f", &fahrenheit); celsius = (fahrenheit - FREEZING_PT) * SCALE_FACTOR; printf("celsius equivalent: %.1f\n", celsius); } return 0; 8

The UNIX/Linux shell: Compile the C source file we use gcc, with various options Run the executable file ghlin@ug10:~>gcc celsius.c -o celsius ghlin@ug10:~>lc total 4 -rwx------+ 1 ghlin prof 8613 Jan 3 2017 celsius* -rw-------+ 1 ghlin prof 373 Jan 3 2017 celsius.c ghlin@ug10:~>./celsius Enter Fahrenheit temperature: 240 Celsius equivalent: 115.6 ghlin@ug10:~>./celsius Enter Fahrenheit temperature: 40 Celsius equivalent: 4.4 9

General form of a C program: /* directives */ int main(void) { } /* statements */ Typical directives, /* headers */ #include <stdio.h> /* macros */ #define FREEZING_PT 32.0f /* global variables */ int num_pt = 0; /* function prototypes */ void mst_prim(int n, int **point); /* main function */ int main(void) { } /* statements */ 10

General form of a C program: /* directives */ int main(void) { } /* statements */ Typical statements, /* declarations */ float fahrenheit, celsius; /* assignments */ celsius = (fahrenheit - FREEZING_PT) * SCALE_FACTOR; /* function calls */ scanf("%f", &fahrenheit); mst_prim(num_pt, point); /* function terminates, and returns a value */ return 0; 11

/* Converts a Fahrenheit temperature to Celsius */ /* directives */ /* headers */ #include <stdio.h> /* macros */ #define FREEZING_PT 32.0f #define SCALE_FACTOR (5.0f / 9.0f) /* main function */ int main(void) { /* statements */ /* declarations */ float fahrenheit, celsius; /* function calls */ printf("enter Fahrenheit temperature: "); scanf("%f", &fahrenheit); /* assignments */ celsius = (fahrenheit - FREEZING_PT) * SCALE_FACTOR; printf("celsius equivalent: %.1f\n", celsius); } /* function terminates, and returns a value */ return 0; 12

General form of a C program: As a whole, use of /*... */ to enclose comments explaining semantics what you do! /************************************************/ /* Converts a Fahrenheit temperature to Celsius */ /* Name: celsius.c */ /* Author: K. N. King */ /* September 11, 2017 ***************************/ Not only for correctness, also easy for eye to separate use of space to separate tokens (variables, constants, operators, etc) use of indention to construct blocks use of blank lines to separate logical blocks stick to standards! 13

Fundamentals: C s standard I/O (<stdio.h>): stdin keyboard / terminal screen stdout terminal screen stderr terminal screen /*... */ encloses comments main(void) function starts the program return 0; the program terminates and returns the value 0 (status code) Every variable must have a type (the kind of data to be held, size, operations, etc.) gcc -o specifies the executable name, otherwise a.out we use gcc -Wall -std=c99 14

Fundamentals: Use = for assignments e.g., celsius = (fahrenheit - FREEZING PT) * SCALE FACTOR different from defining names for constants (macros) e.g., #define FREEZING PT 32.0f Reading an input vs. printing an output use of & (memory address) float fahrenheit, celsius; scanf("%f", &fahrenheit); printf("celsius equivalent: %.1f\n", celsius); Identifiers names for variables, functions, macros, etc. quite flexible in general (name what it is for) must start with a letter or underscore case sensitive some keywords are reserved (such as union, see Table 2.1 in Page 26) some key prefixes are reserved (such as X... ) Don t abuse/mis-use any punctuation marks!!! 15