Introduction to Programming Systems

Similar documents
Review: Constants. Modules and Interfaces. Modules. Clients, Interfaces, Implementations. Client. Interface. Implementation

CSE2301. Functions. Functions and Compiler Directives

C Libraries. Bart Childs Complementary to the text(s)

COS 217: Introduction to Programming Systems

Computer Programming

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

Chapter 8 C Characters and Strings

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

EE 209: Programming Structures for Electrical Engineering

Scientific Programming in C V. Strings

EE 209: Programming Structures for Electrical Engineering. (Many Slides Borrowed from Princeton COS 217)

THE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY. ISA 563: Fundamentals of Systems Programming

CS3157: Advanced Programming. Outline

C: How to Program. Week /May/28

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

COS 217: Introduction to Programming Systems

Functions. Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

C Programs: Simple Statements and Expressions

COS 217: Introduction to Programming Systems!

Characters and Strings

Outline. Computer Programming. Structure of a function. Functions. Function prototype. Structure of a function. Functions

Programming in C. Part 1: Introduction

The C standard library

Course organization. Course introduction ( Week 1)

C mini reference. 5 Binary numbers 12

Chapter 8 - Characters and Strings

Reading Assignment. Strings. K.N. King Chapter 13. K.N. King Sections 23.4, Supplementary reading. Harbison & Steele Chapter 12, 13, 14

COS 217: Introduction to Programming Systems. Goals for Todayʼs Class. Introductions

! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade

Getting Started. Project 1

CSE123. Program Design and Modular Programming Functions 1-1

Review Topics. Final Exam Review Slides

Index. backslash character, 19 backup, off-site, 11. abs, 72 abstraction, 63, 83, 133, 141, 174, 181 acos, 72

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

AIR FORCE SCHOOL,BAMRAULI COMPUTER SCIENCE (083) CLASS XI Split up Syllabus (Session ) Contents

COS 217: Introduction to Programming Systems!

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from

CS201 Lecture 2 GDB, The C Library

Course organization. Part I: Introduction to C programming language (Week 1-12) Chapter 1: Overall Introduction (Week 1-4)

mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut

JTSK Programming in C II C-Lab II. Lecture 3 & 4

Introduction to Algorithms and Data Structures. Lecture 6 - Stringing Along - Character and String Manipulation

Functions. Systems Programming Concepts

CSE2301. Introduction. Streams and Files. File Access Random Numbers Testing and Debugging. In this part, we introduce

Princeton University Computer Science 217: Introduction to Programming Systems. Modularity design principles

Language Design COMS W4115. Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science

C PROGRAMMING. Characters and Strings File Processing Exercise

Split up Syllabus (Session )

Lecture 3. Review. CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions. Conditions: Loops: if( ) / else switch

C Functions. 5.2 Program Modules in C

C for C++ Programmers

C: Arrays, and strings. Department of Computer Science College of Engineering Boise State University. September 11, /16

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called.

File Access. FILE * fopen(const char *name, const char * mode);

CS167 Programming Assignment 1: Shell

Fall, $ cat welcome.c #include <stdio.h>

by Pearson Education, Inc. All Rights Reserved.

Programming Fundamentals for Engineers Functions. Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. Modular programming.

Lecture 03 Bits, Bytes and Data Types

Programming in C week 1 meeting Tiina Niklander

Other C materials before pointer Common library functions [Appendix of K&R] 2D array, string manipulations. <stdlib.

Programming in C First meeting

Programming Paradigms. Literate Programming

today cs3157-fall2002-sklar-lect05 1

C Examples. Goals of this Lecture. Overview of this Lecture

C Characters and Strings

8. Characters, Strings and Files

Multiple Choice Questions ( 1 mark)

Contents. Preface. Introduction. Introduction to C Programming

Programming in C First meeting Tiina Niklander

ECET 264 C Programming Language with Applications

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Library and function of C. Dr. Donald Davendra Ph.D. (Department of ComputingLibrary Science, andfei function VSB-TU of COstrava)

Final Exam 1 /12 2 /12 3 /10 4 /7 5 /4 6 /10 7 /8 8 /9 9 /8 10 /11 11 /8 12 /10 13 /9 14 /13 15 /10 16 /10 17 /12. Faculty of Computer Science

File IO and command line input CSE 2451

C Review. SWE2004: Principles in Programming Spring 2014 Euiseong Seo

Chapter 8: Character & String. In this chapter, you ll learn about;

,$5(0%(''(':25.%(1&+ $16,&'(9(/230(17722/6 EMBEDDED WORKBENCH ANSI C COMPILER C-SPY FOR NATIONAL SEMICONDUCTOR CORP. S &RPSDFW5,6& 70 &5

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36

Structured programming

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Overview. Concepts this lecture String constants Null-terminated array representation String library <strlib.h> String initializers Arrays of strings

C Input/Output. Before we discuss I/O in C, let's review how C++ I/O works. int i; double x;

In class, Wednesday March 14; split between here and CS 105

High-performance computing and programming I. Introduction to C programming in *NIX

Programming in C Quick Start! Biostatistics 615 Lecture 4

Princeton University Computer Science 217: Introduction to Programming Systems. Agenda. COS 217: Introduction to Programming Systems.

Holtek C and ANSI C Feature Comparison User s Guide

Programming Tips for CS758/858

CCE1111 Programming for Engineers [C Programming Language]

Tutorial 5. PDS Lab Section 16 Autumn Functions The C language is termed as function-oriented programming

Testing, Timing, Profiling, & Instrumentation. Testing, Profiling, & Instrumentation

Characters, c-strings, and the string Class. CS 1: Problem Solving & Program Design Using C++

OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES II

Recitation: C Review. TA s 20 Feb 2017

Midterm Review (overview of fall 2005 midterm)" Jennifer Rexford!

OBJECTIVE QUESTIONS: Choose the correct alternative:

CS 211 Programming I for Engineers

Transcription:

Introduction to Programming Systems CS 217 Thomas Funkhouser & Bob Dondero Princeton University Goals Master the art of programming Learn how to be good programmers Introduction to software engineering Learn C and the Unix development tools C is the systems language of choice Unix has a rich development environment Introduction to computer systems Machine architecture Operating systems Compilers 1

Outline First four weeks C programming Second four weeks Machine architecture Third four weeks Unix operating system Coursework Six programming assignments (60%) String library Hash table ADT Circuit simulator Sparc assembly Assembler Shell Exams (30%) Midterm Final Class participation (10%) 2

Materials Required textbooks C Programming: A Modern Approach, King SPARC Architecture, etc. Paul Recommended textbooks The Practice of Programming, Kernighan & Pike Programming with GNU Software. Loukides & Oram Other textbooks The C Programming Language, Kernighan & Ritchie C: A Reference Manual. Harbison & Steele C Interfaces and Implementations. Hanson The UNIX Programming Environment. Kernighan & Pike Web pages www.cs.princeton.edu/courses/cs217/ Facilities Unix machines CIT s arizona cluster SPARC lab in Friend 016 Your own laptop ssh access to arizona run GNU tools on Windows run GNU tools on Linux 3

Logistics Lectures Introduce concepts Work through programming examples M,W 10AM CS105 Precepts Review concepts Demonstrate tools (gdb, makefiles, emacs, ) Work through programming examples T,Th 1:30 Friend 110 M,W 1:30 Friend 111 TBA Software is Hard What were the lessons I learned from so many years of intensive work on the practical problem of setting type by computer? One of the most important lessons, perhaps, is the fact that SOFTWARE IS HARD. From now on I shall have significantly greater respect for every successful software tool that I encounter. During the past decade I was surprised to learn that the writing of programs for TeX and Metafont proved to be much more difficult than all the other things I had done (like proving theorems or writing books). The creation of good software demands a significantly higher standard of accuracy than those other things do, and it requires a longer attention span than other intellectual tasks. Donald Knuth, 1989 4

Software in COS126 Specification Design Programming 1 Person 10 2 Lines of Code 1 Type of Machine 0 Modifications 1 Week Debugging Testing Software in the Real World Specification Design Programming Lots of People 10 6 Lines of Code Lots of Machines Lots of Modifications 1 Decade or more Debugging Testing 5

Good Software in the Real World Understandable Well-designed Consistent Documented Robust Works for any input Tested Reusable Components Efficient Only matters for 1% with well-defined interfaces and test them separately that can be used elsewhere and optimize the slow ones Good Software in the Real World Understandable Well-designed Consistent Documented Robust Works for any input Tested Reusable Components Efficient Only matters for 1% with well-defined interfaces and test them separately that can be used elsewhere and optimize the slow ones 6

Modules Programs are made up of many modules Each module is small and does one thing string manipulation mathematical functions set, stack, queue, list, etc. Deciding how to break up a program into modules is a key to good software design Read Strings Sort Strings Print Strings String List Interfaces An interface defines what the module does decouple clients from implementation hide implementation details An interface specifies data types and variables functions that may be invoked StringList *StringList_create(void); void StringList_delete(StringList *list); void StringList_insert(StringList *list, char *string); void StringList_remove(StringList *list, char *string); int StringList_write(StringList *list); 7

Implementations An implementation defines how the module does it Can have many implementations for one interface different algorithms for different situations machine dependencies, efficiency, etc. StringList *StringList_create(void) StringList *list = malloc(sizeof(stringlist)); list->entries = NULL; list->size = 0; void StringList_delete(StringList *list) free(list); etc. Clients A client uses a module via its interface Clients see only the interface can use module without knowing its implementation Client is unaffected if implementation changes as long as interface stays the same int main() StringList *list = StringList_create(); StringList_insert(list, CS217 ); StringList_insert(list, is ); StringList_insert(list, fun ); StringList_write(list); StringList_delete(list); 8

Clients, Interfaces, Implementations Interfaces are contracts between clients and implementations Clients must use interface correctly Implementations must do what they advertise Client Interface Implementation Examples from real world? Clients, Interfaces, Implementations Advantages of modules with clean interfaces de-couples clients from implementations localizes impact of change to single module allows sharing of implementations (re-use) allows separate compilation improves readability simplifies testing etc. int main() StringList *list = StringList_create(); StringList_insert(list, CS217 ); StringList_insert(list, is ); StringList_insert(list, fun ); StringList_write(list); StringList_delete(list); 9

C Programming Conventions Interfaces are defined in header files (.h) stringlist.h StringList *StringList_create(void); void StringList_delete(StringList *list); void StringList_insert(StringList *list, char *string); void StringList_remove(StringList *list, char *string); void StringList_write(StringList *list); etc. C Programming Conventions Implementations are described in source files (.c) stringlist.c #include stringlist.h StringList *StringList_create(void) StringList *list = malloc(sizeof(stringlist)); list->entries = NULL; list->size = 0; void StringList_delete(StringList *list) free(list); etc. 10

C Programming Conventions Clients include header files main.c #include stringlist.h int main() StringList *list = StringList_create(); StringList_insert(list, CS217 ); StringList_insert(list, is ); StringList_insert(list, fun ); StringList_write(list); StringList_delete(list); Standard C Libraries assert.h ctype.h errno.h math.h limits.h signal.h stdarg.h stddef.h stdio.h stdlib.h string.h time.h assertions character mappings error numbers math functions metrics for ints signal handling variable length arg lists standard definitions standard I/O standard library functions string functions date/type functions 11

Standard C Libraries (cont) Utility functions stdlib.h atof, atoi, rand, qsort, getenv, calloc, malloc, free, abort, exit String handling string.h strcmp, strncmp, strcpy, strncpy, strcat, strncat, strchr, strlen, memcpy, memcmp Character classifications ctypes.h isdigit, isalpha, isspace, isupper, islower Mathematical functions math.h sin, cos, tan, ceil, floor, exp, log, sqrt Example: Standard I/O Library stdio.h hides the implementation of FILE extern FILE *stdin, *stdout, *stderr; extern FILE *fopen(const char *, const char *); extern int fclose(file *); extern int printf(const char *, ); extern int scanf(const char *, ); extern int fgetc(file *); extern char *fgets(char *, int, FILE *); extern int getc(file *); extern int getchar(void); extern char *gets(char *);... extern int feof(file *); 12

Summary We will learn good programming in first third of this class A key to good programming is modularity A program is broken up into meaningful modules An interface defines what a module does An implementation defines how the module does it A client sees only the interfaces, not the implementations First assignment is to provide the implementation of the standard C string manipulation module defined in string.h (due Sunday) 13