Week 1 Part II Kyle Dewey. Overview Lab The art of programming Basic data types Variable declaration and initialization Data representation.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Chapter 11 Introduction to Programming in C
An Introduction to Programming By :- Vishal Hirani B.Tech II year (CSE)
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
CS16 Week 2 Part 2 Kyle Dewey. Overview Type coercion and casting More on assignment Pre/post increment/decrement scanf Constants Math library Errors.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
CS 201 Functions Debzani Deb.
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
If You Missed Last Week Go to Click on Syllabus, review lecture 01 notes, course schedule Contact your TA ( on website) Schedule.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
The little language that could Remember C is a “small language”
‘C’ LANGUAGE PRESENTATION.  C language was introduced by Dennis Ritchie..  It is a programming language, which can make a interaction between user and.
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
Chapter Introduction to Computers and Programming 1.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
01- Intro-Java-part1 1 Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology June 2008.
Week 3 Part I Kyle Dewey. Overview Odds & Ends Constants Errors Functions Expressions versus statements.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
CIS Computer Programming Logic
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Chapter 1: Introduction to Computers and Programming.
Input & Output: Console
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Computer Programming TCP1224 Chapter 3 Completing the Problem-Solving Process and Getting Started with C++
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
IXA 1234 : C++ PROGRAMMING CHAPTER 1. PROGRAMMING LANGUAGE Programming language is a computer program that can solve certain problem / task Keyword: Computer.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Fundamental Programming: Fundamental Programming Introduction to C++
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Computers, Variables and Types Engineering 1D04, Teaching Session 2.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
CS Class 03 Topics  Sequence statements Input Output Assignment  Expressions Read pages Read pages 40 – 49 for next time.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
9/29/99B-1 CSE / ENGR 142 Programming I Variables, Values, and Types © 1998 UW CSE.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Chapter 1: Introduction to Computers and Programming.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Last week: We talked about: History of C Compiler for C programming
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
A bit of C programming Lecture 3 Uli Raich.
Microprocessor Systems Design I
EPSII 59:006 Spring 2004.
Getting Started with C.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Introduction to CS Your First C Programs
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
פרטים נוספים בסילבוס של הקורס
Variables in C Topics Naming Variables Declaring Variables
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
Primitive Types and Expressions
Variables in C Topics Naming Variables Declaring Variables
C Language B. DHIVYA 17PCA140 II MCA.
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

Week 1 Part II Kyle Dewey

Overview Lab The art of programming Basic data types Variable declaration and initialization Data representation

Lab 1

The Art of Programming

General Advice Top-down programming: Start with the big picture and get more specific Bottom-up programming: work up to the big picture by glueing together smaller, existing pieces Divide and conquer: break a problem up into individual piecs

Top-Down Programming Start general and gradually become specific, filling in the details as you go along

Top-Down Make Sandwich

Top-Down Make Sandwich Put Meat on Bread Put Sides Together

Top-Down Make Sandwich Put Sides Together Put Meat on Bread Get Meat from Fridge Get Bread from Cabinet

Top-Down Make Sandwich Put Sides Together Put Meat on Bread Get Meat from Fridge Get Bread from Cabinet Open Fridge... Open Cabinet...

Bottom-Up Programming Glue preexisting pieces together to derive a solution

Bottom-Up Handlebars Frame Wheels Chain Gears

Handlebars Frame Wheels Chain Gears Bolt

Bottom-Up Handlebars Frame Wheels Chain Gears Bolt

Bottom-Up Handlebars Frame Wheels Chain Gears Bolt Oil

Bottom-Up Handlebars Frame Wheels Chain Gears Bolt Oil Chain Tool

Combination printf / scanf are generally written once (preexisting) A middle ground

Divide and Conquer Really part of top-down and bottom-up Break a problem down into distinct subproblems, solve them individually, and finally combine them

Divide and Conquer Program Input Output

Divide and Conquer Subprogram 1 Input Output Subprogram 2 Output / Input

Divide and Conquer Input Output Subprogram 2 Subprogram A Subprogram B Output / Input

General Five Step Process 1. Problem Statement 2. Input / Output Description 3. Hand Example 4. Algorithm Development 5. Testing

General Five Step Process 1. Problem Statement 2. Input / Output Description 3. Hand Example 4. Algorithm Development 5. Testing

Problem Statement What are we trying to solve? (Believe it or not, real software often goes astray here arguably more than anywhere else)

General Five Step Process 1. Problem Statement 2. Input / Output Description 3. Hand Example 4. Algorithm Development 5. Testing

Input / Output Description What are the program inputs and what are the outputs? Program Input I Input 2 (A miracle occurs) Output 1 Output 2

General Five Step Process 1. Problem Statement 2. Input / Output Description 3. Hand Example 4. Algorithm Development 5. Testing

Hand Example Do the problem by hand See if you actually understand what must be done

General Five Step Process 1. Problem Statement 2. Input / Output Description 3. Hand Example 4. Algorithm Development 5. Testing

Algorithm Development Steps needed to solve the problem Ultimately involves writing code “Days of coding can save you hours of planning”

General Five Step Process 1. Problem Statement 2. Input / Output Description 3. Hand Example 4. Algorithm Development 5. Testing

Testing See if solution actually works Important step! “50% of our code is tests”

TDD Test-driven development Write tests before code Wildly popular right now The point: testing is important!

C

hello.c

Running Code Via make / gcc / cc (compilation) Via ch (interpretation)

Compilation Code is ultimately converted to a form the machine understands directly The result runs as fast as the machine Certain interdependencies not handled

Object Files 1: somethingFromHere(); 2: somethingFromElsewhere(); 3: somethingElseFromHere(); somethingFromHer e somethingElseFromHer e somethingFromElsewh ere

Linking Technically separate from compilation, but the two often get conflated Connects different pieces of code together

Linking somethingFromHer e somethingElseFromHer e somethingFromElsewhere

Linking somethingFromHeresomethingFromElsewheresomethingElseFromHere

Overall Process Source Code File #1 Source Code File #2 Object File #1 Object File #2 Executable Compilation Linking

Question Why separate compilation and linking?

Interpretation As with ch A program that understands the language runs it directly Runs as fast as the interpreter

Questions Why compile versus interpret? Why interpret versus compile?

Types

All data in C has a type Types determine: What can be done with the data How much space they take up (as with the sizeof operator)

Basic Types int : Integers (i.e. 1, 2, 3...) Come in both signed and unsigned forms double : floating point numbers (i.e. 5.1, 7.8, 2.93,...) char : A character (i.e. a, b, c,...)

Variables A container for a value Must have a type

Variable Declaration Telling the compiler that a variable with a given name and type can be used int myInteger; double myFloatingPoint; char myCharacter;

Question int myVariable; int x = myVariable + 1; // what does x equal?

Answer? ch : 1 gcc : 1

Uninitialized Variables Officially, the initial value is “undefined” Undefined means “anything goes” Can be a source of tricky bugs

Variable Assignment The values of variables can be initialized... int myVariable = 0; -or- int myVariable; myVariable = 0;

Variable Assignment...or changed on the fly... int myVariable = 0; myVariable = 5 + 2;

Variable Assignment...or even be used to update the same variable! int myVariable = 0; myVariable = 5 + 2; myVariable = 10 - myVariable;

Data Representation

Many programming languages abstract away data representation C is not (exactly) one of those languages

Some Definitions bit: binary digit (true/false, 0/1, yes/no) byte: 8 bits kilobyte: 1024 bytes

Sizes If a bit can hold two possible values... And a byte holds 8 bits... How many possible values in a byte? A kilobyte?

Sizes and Types The actual size of variables depends on the compiler and the particular computer sizeof is your friend if it’s important, as is limits.h (see typelimits.c )

Questions Integers are often 4 bytes. How many possible values can this hold? Signed versus unsigned integers: Does this make a difference for size?

Questions What’s the largest number that can be stored in an unsigned 4 byte integer? What’s around the largest number that can be stored in a signed 4 byte integer?