Introduction Chapter 1 1/22/16. Check zyBooks Completion Click on the boxes for each section.

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
Introduction to C Programming
C Programming for engineers Teaching assistant: Ben Sandbank Home page:
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Introduction to C Programming
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
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
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
A First Book of ANSI C Fourth Edition Chapter 3 Processing and Interactive Input.
Programming With C.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Patrick J. McSweeney MW: 5 – 8:30pm.
A First Look at Java Chapter 2 1/29 & 2/2 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
More about Java Chapter 2 9/8 & 9/9 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
A.Abhari CPS1251 Topic 2: C Overview C Language Elements Variable Declaration and Data Types Statement Execution C Program Layout Formatting Output Interactive.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics.
Chapter 2 Wrap Up 2/18/16 & 2/22/16. Topics Review for Exam I DecimalFormat More Style Conventions Debugging using eclipse The Java API.
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
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.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Lecture2.
Wrapper Classes Debugging Interlude 1
Chapter 2 - Introduction to C Programming
C Programming Hardik H. Maheta.
What's a Computer? Monitor Disk Main mouse Memory Keyboard Network
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Chapter 2 Overview of C.
ICS103 Programming in C Lecture 3: Introduction to C (2)
Variables, Expressions, and IO
Getting Started with C.
Chapter 2 - Introduction to C Programming
Repetition Chapter 6 12/06/16 & 12/07/16 1 1
Chapter 2 - Introduction to C Programming
Chapter 11 Introduction to Programming in C
Chapter 2 - Introduction to C Programming
Introduction to CS Your First C Programs
Chapter 2 - Introduction to C Programming
1) C program development 2) Selection structure
Chapter 2 - Introduction to C Programming
Lecture3.
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Chapter 1 c++ structure C++ Input / Output
Getting Started With Coding
Presentation transcript:

Introduction Chapter 1 1/22/16

Check zyBooks Completion Click on the boxes for each section.

Assignment See my website for the new assignment.

Today's Topics Output Parts of a C Program Comments Input Algorithms Errors and Warnings

Output printf function is used to display output. Must include the i/o library in the program. #include Now the printf function can be used. printf(“%d tons\n", 16);  Output: 16 tons  %d is format for integers.  Where tons is printed.

Displaying Text \n is a new line character If it is not there, the next output will continue on the same line. printf("Without Dennis Ritchie "); printf("there would be no\n"); printf("Steve Jobs.\n");

A Simple C Program A program is needed to figure out how many pets we have, given the number of dogs and cats that includes. Write a program to set the number of cats and dogs. Output the number of pets. The instructions in a program are called code. Here is the code: Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

#include //Program to add up the number of pets int main(void){ int cats = 4; int dogs = 3; int pets = cats + dogs; printf("We have %d pets\n", pets); return 0; }

A Simple C Program main function Where the execution begins. int main(void){ } Block begins and ends with brace { … } Statements within block end with a ;  Tell processor what to do. Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

Assignment Statement int cats = 4; int cats declares a variable. o A variable is a memory location. o Memory is a place to store values temporarily. cat = 4; sets cats to 4. int pets = cats + dogs; o D oes the addition on the right first. o Assigns the answer to pets.

Comments Documents the program Comments Begin line with double slash //  Ends with the end of the line. Span multiple lines between slash-star combination. /* */ Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

return Statement return 0; Ends the program and gives control back to operating system.

Questions What happens when a “\n” is put in the output? Where do the statements in a C program belong? Give an example of an assignment statement.

Input

Input Makes Program Useful Programs so far do one calculation  Example in dogyrs.c More useful if you can input human_yrs  doginput.c

scanf scanf("%d", &human_yrs); scanf – function name “%d” - input format, same as printf formats & -- “address of” operator &human_yrs – where data will be stored.

scanf Execution pauses until user enters a value and hits Value input stored in variable(s)‏ Prompt is recommended  printf to tell user input is expected.  I'll put one in doginput.c #include makes scanf available.

Find the Number of People Write a program to figure how many people are touring Yosemite Park today. Ask for the number of people one tour bus can hold and the number of buses in the park. Output the total number of passengers.

#include int main(void){ //Ask for the number of people on each bus int peopleOnBus; printf("People on one bus?"); scanf("%d", &peopleOnBus); //Ask for the number of buses int noBuses; printf("Number of Buses?"); scanf("%d", &noBuses); //Find total number of people int people = peopleOnBus * noBuses; //Output total number of people printf("%d people\n", people); return 0; }

Login and Password If you don't have a login, send me . Contact me if you forget your password. Change your password to something easy to remember.  ssh -Y onyx  Login again  passwd  Nothing shows while you are typing.

Questions What statement is used to handle input? What preprocessor directive must be in programs that have input or output?

Number of Meals Needed A coding conference provides three meals for each participant. Write a program to input the number of participants then output the total number of meals needed. Write an algorithm with a partner Along with your partner, code the program using vim. – Print it and hand in a copy with both names on it.

Errors and Warnings

Errors Syntax Error  Violation of programming language rules.  Caught by compiler.  Program will not compile. Logic Error  Error while program runs.  For example, incorrect computation. distance = rate/time;

Errors and Warnings Error prevents program from compiling Warning means something might be wrong.  Try to get rid of it.

Questions What kind of error is it? 1.The compiler prints an error message because a semicolon(;) is missing. 2. A program to convert Fahrenheit to Celcius gives incorrect results. 3. The program compiles but the compiler gives a message about a possible problem.