Overview of a C Program

Size: px
Start display at page:

Download "Overview of a C Program"

Transcription

1 Overview of a C Program Programming with C CSCI 112, Spring 2015 Patrick Donnelly Montana State University

2 Programming with C (CSCI 112) Spring / 42 C Language Components Preprocessor Directives Comments The main function Variable Declarations and Data Types Executable Statements Reserved Words Identifiers

3 Programming with C (CSCI 112) Spring / 42 General Outline of a C Program preprocessor directives main function heading { declarations executable statements }

4 Programming with C (CSCI 112) Spring / 42 Example C Program # include <stdio.h> // printf, scanf definitions # define KMS_PER_MILE // conversion constant int main ( int argc, char ** argv ) { double miles ; // distance in miles double kms ; // equivalent distance in kilometers // get the distance in miles printf (" Enter the distance in miles > "); scanf ("%lf", & miles ); // convert the distance to kilometers kms = KMS_PER_MILE * miles ; // display the distance in kilometers printf (" That equals %f kilometers.\n", kms ); } return (0);

5 Anatomy of a C Program Programming with C (CSCI 112) Spring / 42

6 Programming with C (CSCI 112) Spring / 42 Example C Program: Preprocessor Directives #include <stdio.h> #define KMS PER MILE int main ( int argc, char ** argv ) { double miles ; // distance in miles double kms ; // equivalent distance in kilometers // get the distance in miles printf (" Enter the distance in miles > "); scanf ("%lf", & miles ); // convert the distance to kilometers kms = KMS_PER_MILE * miles ; // display the distance in kilometers printf (" That equals %f kilometers.\n", kms ); } return (0);

7 Programming with C (CSCI 112) Spring / 42 Example C Program: Declarations # include <stdio.h> // printf, scanf definitions # define KMS_PER_MILE // conversion constant int main ( int argc, char ** argv ) { double miles; double kms; // get the distance in miles printf (" Enter the distance in miles > "); scanf ("%lf", & miles ); // convert the distance to kilometers kms = KMS_PER_MILE * miles ; // display the distance in kilometers printf (" That equals %f kilometers.\n", kms ); } return (0);

8 Programming with C (CSCI 112) Spring / 42 Example C Program: Comments # include <stdio.h> // printf, scanf definitions # define KMS_PER_MILE // conversion constant int main ( int argc, char ** argv ) { double miles ; // distance in miles double kms ; // equivalent distance in kilometers } // get the distance in miles printf (" Enter the distance in miles > "); scanf ("%lf", & miles ); // convert the distance to kilometers kms = KMS_PER_MILE * miles ; // display the distance in kilometers printf (" That equals %f kilometers.\n", kms );

9 Programming with C (CSCI 112) Spring / 42 Example C Program: Executable Statements # include <stdio.h> // printf, scanf definitions # define KMS_PER_MILE // conversion constant int main ( int argc, char ** argv ) { double miles ; // distance in miles double kms ; // equivalent distance in kilometers // get the distance in miles printf("enter the distance in miles> "); scanf("%lf", &miles); // convert the distance to kilometers kms = KMS PER MILE * miles; // display the distance in kilometers printf("that equals %f kilometers.\n", kms); } return(0);

10 Programming with C (CSCI 112) Spring / 42 Our C Program # include <stdio.h> /* lab01. c ( name of your file ) * Philip J. Fry ( your name ), CSCI112, Lab 01 * 08/28/2014 ( current date ) */ int main ( void ) { printf (" Hello return (0); } World \n");

11 Programming with C (CSCI 112) Spring / 42 Preprocessor Directives Definition: Preprocessor Directives Preprocessor Directives are commands that give instructions to the C preprocessor. Definition: Preprocessor The Preprocessor is a program that modifies your C program before it is compiled. Preprocessor Directives start with a # symbol. #include #define #if #else #endif #pragma

12 Programming with C (CSCI 112) Spring / 42 #include #include is used to include other source files into your source file. #include gives a program access to a library/header file. stdio.h math.h time.h Libraries are a collection of useful functions and symbols. Standard libraries are predefined by the ANSI C language. You must include stdio.h if you want to use printf and scanf library functions. #include <stdio.h> inserts their definitions into your program before compilation.

13 Programming with C (CSCI 112) Spring / 42 #define The #define directive instructs the preprocessor to replace every occurance of a particular text with a given constant value. The replacement occurs before compilation. Your source code: #d e f i n e PI #d e f i n e EULERS NUMBER i n t main ( v o i d ) { double x = 5 PI ; double y = EULERS NUMBER 7 ; r e t u r n ( 0 ) ; } What actually gets compiled: i n t main ( v o i d ) { d o u b l e x = ; d o u b l e y = ; r e t u r n ( 0 ) ; }

14 Programming with C (CSCI 112) Spring / 42 Constants #define Constants Consists of 3 parts: #define constant name constant value There is no = sign or ; at the end # define MY_CONSTANT_NAME 123 # define ANSWER 42

15 Comments Comments provide extra information, making it easier for humans to understand the program. These comments are completely ignored by the compiler. Comments take two forms: /* */ - anything between asterisks is a comment. // - anything after is a comment, but only until EOL. Comments are used for documentation that helps other programmers read and understand the program. Programs should contain a comment at the top with the programmer s name, the date, and a brief description of what the program does. COMMENT YOUR CODE! Programming with C (CSCI 112) Spring / 42

16 Programming with C (CSCI 112) Spring / 42 The main function The heading int main(void) marks the beginning of the main function where your program execution begins. Every C program has a main function. Braces/Curly brackets: { } mark the beginning and end of the body of the function. A function body has two parts: declarations: (names of variables and data types) tell the compiler what memory cells are needed in the function and how they should be processed. executable statements: they reflect actions of your algorithm. These are translated into machine language by the compiler and later executed.

17 Programming with C (CSCI 112) Spring / 42 Declarations of Variables Variable: A memory cell used to store program data. A variables value can change with time. We use its name as a simple reference (instead of the actual address in memory). Variable declaration: Statement that communicates to the compiler the names of variables in the program and the data type they represent. Example: double miles ; This tells the compiler to create a space for a variable of type double in memory and refer to it each time we use the name miles in our program.

18 Programming with C (CSCI 112) Spring / 42 Numeric Data Types Definition: Data Type Data Type: a set of values and a set of operations that can be performed on those values. Numeric Data Types: int: Stores integer value (whole number). Examples: 65, -123 double: Stores real number (uses a decimal point). Examples: , 1.23e5 ( ) Arithmetic operations (+,-,*,/, %) can be used on ints and doubles.

19 Programming with C (CSCI 112) Spring / 42 Character Data Type Character Data Type: char: An individual character value. Examples: a,, 5, * (can be a letter, digit, or special symbol) Character Declaration Use single quotes, NOT double quotes char my_char = Z ; Comparison operations (<, >,, ) can be used on ints, doubles and chars.

20 Programming with C (CSCI 112) Spring / 42 ASCII Code A < B < C <... < X < Y < Z

21 Programming with C (CSCI 112) Spring / 42 Executable Statements Executable Statements: C statements used to write or code the algorithm. The C compiler translates the executable statements into machine code. Examples: Input/Output Operations and Functions printf function scanf function Assignment Statement (=) return Statement/Operation

22 Programming with C (CSCI 112) Spring / 42 Executable Statements: Input/Output Operations Input operation: data transfer from outside the program into computer memory that is usable by the program. Input may be received from: A program user An external file Another program Output operation: program results that can be displayed to the program user. Results can be printed to: The standard console output An external file

23 Programming with C (CSCI 112) Spring / 42 Executable Statements: Functions A function takes input parameters and produces an output. A function definition specifies the return type, the input parameters, and the body. A function call is used to call or activate a function. Calling a function means asking another piece of code to do some work for you.

24 Programming with C (CSCI 112) Spring / 42 Executable Statements: Functions - printf() By calling the printf() function, we are asking for the function to print to standard output. The first argument to printf is the formatting code (in string form), and all following arguments are the the variables to be used in the placeholders. double miles = 2.7; printf (" That is %f miles.\n", miles );

25 Programming with C (CSCI 112) Spring / 42 Executable Statements: Functions - printf() Multiple placeholders can be specified, and the corresponding arguments are then provided in order. Different types of variables require different formatting codes. int a = 1; double b = 2.0; char *c = " three "; printf (" Easy as %d, %f, %s!\n", a, b, c); Details on formatting codes can be found in the handout.

26 Programming with C (CSCI 112) Spring / 42 Executable Statements: Functions - scanf() Reading input data in a program is done via the scanf() function. The concept is very much the same as the printf() function. In this case, the format code is just the variable code for what data will be received (%d, %c, %lf), and the following arguments are the variables that will receive the data. double miles ; scanf ("%lf", & miles ); The & is the address operator in C. The & operator in front of variable miles informs the scanf() function about the location of variable miles in the computer s memory.

27 Programming with C (CSCI 112) Spring / 42 printf()/scanf() statements printf()/scanf() statements Use commas to deliminate printf/scanf arguments. char a =! ; int b = 7; float c = 3.7; double d = 1.5; printf ("%c %d %f %lf scanf ("%lf", &d); %c \n", a, b, c, d, a); Remember that %f is for floats, %lf is for doubles For printf(), doubles can be implicitly converted to floats printf ("%f\n", &d); printf ("%lf\n", &d); scanf ("%lf", &d);

28 Programming with C (CSCI 112) Spring / 42 Assignment Statements An assignment statement stores a value in a variable. The value assigned can be the result of another computation. kms = KMS_PER_MILE * miles ; The above assigns a value (content) to the variable kms. The value assigned in this case is the result of the multiplication of the constant KMS PER MILE by the variable miles. We should interpret an assignment statement: value = expression as: value expression This should be read as becomes, gets, or takes the value of rather than equals.

29 Programming with C (CSCI 112) Spring / 42 Assignment Statements Effect of kms = KMS PER MILE * miles;

30 Programming with C (CSCI 112) Spring / 42 Assignment Statements = is NOT an algebraic operator. Consider the following: sum = sum + item ; This is obviously not a correct algebraic equation (if item 0). This statement instructs the computer to add the current value of sum to the value of item. Afterward the result is stored back into sum. Equality: To test for equality, use the == operator. Be sure to keep these concepts separate. Remember! Every variable has contents, even before assignment.

31 Programming with C (CSCI 112) Spring / 42 Assignment Statements Effect of sum = sum + item;

32 Programming with C (CSCI 112) Spring / 42 Arithmetic Operators Operator Meaning Examples + addition = = 7.0 subtraction 5 2 = = 3.0 * multiplication 5 * 2 = * 2.0 = 10.0 / division 5.0 / 2.0 = / 2 = 2 % remainder (mod) 5 % 2 = 1 5 / 2 = 2

33 Programming with C (CSCI 112) Spring / 42 Expression Example Area of a Circle a = πr 2 can be written in C as: area = PI * radius * radius ; where PI is a constant macro set to

34 Expression Evaluation Programming with C (CSCI 112) Spring / 42

35 Programming with C (CSCI 112) Spring / 42 Expression Example 3 Evaluation Tree and Evaluation for v = (p2 - p1) / (t2 - t1);

36 Programming with C (CSCI 112) Spring / 42 Expression Example 4 Evaluation Tree and Evaluation for z - (a + b / 2) + w * -y;

37 Programming with C (CSCI 112) Spring / 42 The return statement In your main() function, the return statement will transfer control from your program to the operating system. return(0); returns a 0 to the operating system, which indicates that the program executed without error. This means that the end of the program was reached. It does not mean that the program did what it was supposed to do. There still may have been logical errors. Other functions also have return statements, which can return error codes, data, or nothing at all.

38 Programming with C (CSCI 112) Spring / 42 Punctuation & Special Symbols Semicolons: ; Mark the end of a statement (which may take more than one line). Curly Braces: { } Mark the beginning and end of the body of a function. Mathematical Symbols: *,/,+,- Are mainly used to compute numeric values. Note that some have additional meaning. In particular, we will talk about * later.

39 Programming with C (CSCI 112) Spring / 42 Reserved Words A reserved word is a word that has special meaning to C and can not be used for other purposes. These are words that C reserves for its own uses. They are often necessary for the compiler to analyze the language s grammar and to understand what the programmer wants to do (declaring variables, controlling data flow, etc). In example, you cannot have a variable named return or if. Reserved words are always lowercase. See your book or the reference links on the website for a complete list of reserved words.

40 Programming with C (CSCI 112) Spring / 42 Standard Identifiers An identifier is a name given to a variable or an operation. This is just a formal term for function names and variable names. A standard identifier is an identifier that is defined in the standard C libraries and has special meaning in this standard (such as ANSI C). Examples include printf and scanf Unlike reserved words, you can re-define a standard identifier It is not recommended to use standard identifiers in a non-standard way, especially when linking to other code that uses these standards.

41 Programming with C (CSCI 112) Spring / 42 User Defined Identifiers Variables: We choose our own identifiers to name memory cells that will hold data. Functions: We choose our own identifiers to name operations that we define. Common Rules for Naming Identifiers: May consist only of letters, digits, and underscores cannot begin with a digit reserved words cannot be used standard identifiers should not be redefined Valid Identifers: var1, inches, KM PER MILE Invalid Identifiers: 1var, the*var, return

42 Programming with C (CSCI 112) Spring / 42 Identifier Naming Guidelines Some compilers only recognize the first 31 characters of identifier names, so avoid long identifiers. Compilers are case-sensitive. Aviod very similar names (differ by case, or a single letter) ITEM is different than Item is different than item Note that conventional C code uses lowercase and underscores for variables (as opposed to camel-case used in Java) miles vehicle speed Constants and Macros usually use all uppercase KMS PER MILE is a defined constant Choose meaningful identifiers that are easily understood. distance = velocity * time is more intelligible than x = y * z.

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

CP Lab 2: Writing programs for simple arithmetic problems

CP Lab 2: Writing programs for simple arithmetic problems Computer Programming (CP) Lab 2, 2015/16 1 CP Lab 2: Writing programs for simple arithmetic problems Instructions The purpose of this Lab is to guide you through a series of simple programming problems,

More information

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

Chapter One Introduction to Programming

Chapter One Introduction to Programming Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

Chapter 13 - The Preprocessor

Chapter 13 - The Preprocessor Chapter 13 - The Preprocessor Outline 13.1 Introduction 13.2 The#include Preprocessor Directive 13.3 The#define Preprocessor Directive: Symbolic Constants 13.4 The#define Preprocessor Directive: Macros

More information

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share. LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Introduction to the C language Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) The C language

More information

arrays C Programming Language - Arrays

arrays C Programming Language - Arrays arrays So far, we have been using only scalar variables scalar meaning a variable with a single value But many things require a set of related values coordinates or vectors require 3 (or 2, or 4, or more)

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

Introduction to Python

Introduction to Python WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language

More information

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters The char Type ASCII Encoding The C char type stores small integers. It is usually 8 bits. char variables guaranteed to be able to hold integers 0.. +127. char variables mostly used to store characters

More information

CS 241 Data Organization Coding Standards

CS 241 Data Organization Coding Standards CS 241 Data Organization Coding Standards Brooke Chenoweth University of New Mexico Spring 2016 CS-241 Coding Standards All projects and labs must follow the great and hallowed CS-241 coding standards.

More information

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T) Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating

More information

Introduction to Visual C++.NET Programming. Using.NET Environment

Introduction to Visual C++.NET Programming. Using.NET Environment ECE 114-2 Introduction to Visual C++.NET Programming Dr. Z. Aliyazicioglu Cal Poly Pomona Electrical & Computer Engineering Cal Poly Pomona Electrical & Computer Engineering 1 Using.NET Environment Start

More information

The programming language C. sws1 1

The programming language C. sws1 1 The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan

More information

Java Crash Course Part I

Java Crash Course Part I Java Crash Course Part I School of Business and Economics Institute of Information Systems HU-Berlin WS 2005 Sebastian Kolbe skolbe@wiwi.hu-berlin.de Overview (Short) introduction to the environment Linux

More information

An Incomplete C++ Primer. University of Wyoming MA 5310

An Incomplete C++ Primer. University of Wyoming MA 5310 An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages

More information

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved.

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved. 1 6 JavaScript: Introduction to Scripting 2 Comment is free, but facts are sacred. C. P. Scott The creditor hath a better memory than the debtor. James Howell When faced with a decision, I always ask,

More information

The C Programming Language

The C Programming Language Chapter 1 The C Programming Language In this chapter we will learn how to write simple computer programs using the C programming language; perform basic mathematical calculations; manage data stored in

More information

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install

More information

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output CSCE 110 Programming Basics of Python: Variables, Expressions, and nput/output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Fall 2011 Python Python was developed

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

Chapter 2: Elements of Java

Chapter 2: Elements of Java Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

More information

Welcome to Basic Math Skills!

Welcome to Basic Math Skills! Basic Math Skills Welcome to Basic Math Skills! Most students find the math sections to be the most difficult. Basic Math Skills was designed to give you a refresher on the basics of math. There are lots

More information

Comp151. Definitions & Declarations

Comp151. Definitions & Declarations Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const

More information

Chapter 3. Input and output. 3.1 The System class

Chapter 3. Input and output. 3.1 The System class Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

Java Basics: Data Types, Variables, and Loops

Java Basics: Data Types, Variables, and Loops Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]

More information

Introduction to Java. CS 3: Computer Programming in Java

Introduction to Java. CS 3: Computer Programming in Java Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods

More information

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from

More information

Computer Programming Tutorial

Computer Programming Tutorial Computer Programming Tutorial COMPUTER PROGRAMMING TUTORIAL by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Computer Prgramming Tutorial Computer programming is the act of writing computer

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

Number Representation

Number Representation Number Representation CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Topics to be Discussed How are numeric data

More information

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void 1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

More information

Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar

Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar Lexical Analysis and Scanning Honors Compilers Feb 5 th 2001 Robert Dewar The Input Read string input Might be sequence of characters (Unix) Might be sequence of lines (VMS) Character set ASCII ISO Latin-1

More information

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named

More information

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing The scanner (or lexical analyzer) of a compiler processes the source program, recognizing

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

PL / SQL Basics. Chapter 3

PL / SQL Basics. Chapter 3 PL / SQL Basics Chapter 3 PL / SQL Basics PL / SQL block Lexical units Variable declarations PL / SQL types Expressions and operators PL / SQL control structures PL / SQL style guide 2 PL / SQL Block Basic

More information

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand: Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of

More information

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE PROGRAMMING IN C CONTENT AT A GLANCE 1 MODULE 1 Unit 1 : Basics of Programming Unit 2 : Fundamentals Unit 3 : C Operators MODULE 2 unit 1 : Input Output Statements unit 2 : Control Structures unit 3 :

More information

C++ Language Tutorial

C++ Language Tutorial cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain

More information

So far we have considered only numeric processing, i.e. processing of numeric data represented

So far we have considered only numeric processing, i.e. processing of numeric data represented Chapter 4 Processing Character Data So far we have considered only numeric processing, i.e. processing of numeric data represented as integer and oating point types. Humans also use computers to manipulate

More information

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

More information

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions Phys4051: C Lecture 2 & 3 Functions (Review) Comment Statements Variables & Operators Branching Instructions Comment Statements! Method 1: /* */! Method 2: // /* Single Line */ //Single Line /* This comment

More information

Programming in Java. 2013 Course Technology, a part of Cengage Learning.

Programming in Java. 2013 Course Technology, a part of Cengage Learning. C7934_chapter_java.qxd 12/20/11 12:31 PM Page 1 Programming in Java Online module to accompany Invitation to Computer Science, 6th Edition ISBN-10: 1133190820; ISBN-13: 9781133190820 (Cengage Learning,

More information

VHDL Test Bench Tutorial

VHDL Test Bench Tutorial University of Pennsylvania Department of Electrical and Systems Engineering ESE171 - Digital Design Laboratory VHDL Test Bench Tutorial Purpose The goal of this tutorial is to demonstrate how to automate

More information

As previously noted, a byte can contain a numeric value in the range 0-255. Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets!

As previously noted, a byte can contain a numeric value in the range 0-255. Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets! Encoding of alphanumeric and special characters As previously noted, a byte can contain a numeric value in the range 0-255. Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets! Alphanumeric

More information

Programmierpraktikum

Programmierpraktikum Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 21 10/16/2012 09:29 AM Java - A First Glance 2 of 21 10/16/2012 09:29 AM programming languages

More information

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms PROG0101 FUNDAMENTALS OF PROGRAMMING Chapter 3 1 Introduction to A sequence of instructions. A procedure or formula for solving a problem. It was created mathematician, Mohammed ibn-musa al-khwarizmi.

More information

Programming Languages CIS 443

Programming Languages CIS 443 Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception

More information

Some Scanner Class Methods

Some Scanner Class Methods Keyboard Input Scanner, Documentation, Style Java 5.0 has reasonable facilities for handling keyboard input. These facilities are provided by the Scanner class in the java.util package. A package is a

More information

Lecture 5: Java Fundamentals III

Lecture 5: Java Fundamentals III Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd

More information

1 Abstract Data Types Information Hiding

1 Abstract Data Types Information Hiding 1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content

More information

Lab Experience 17. Programming Language Translation

Lab Experience 17. Programming Language Translation Lab Experience 17 Programming Language Translation Objectives Gain insight into the translation process for converting one virtual machine to another See the process by which an assembler translates assembly

More information

5 Arrays and Pointers

5 Arrays and Pointers 5 Arrays and Pointers 5.1 One-dimensional arrays Arrays offer a convenient way to store and access blocks of data. Think of arrays as a sequential list that offers indexed access. For example, a list of

More information

PAYCHEX, INC. BASIC BUSINESS MATH TRAINING MODULE

PAYCHEX, INC. BASIC BUSINESS MATH TRAINING MODULE PAYCHEX, INC. BASIC BUSINESS MATH TRAINING MODULE 1 Property of Paychex, Inc. Basic Business Math Table of Contents Overview...3 Objectives...3 Calculator...4 Basic Calculations...6 Order of Operation...9

More information

CHAPTER 1 ENGINEERING PROBLEM SOLVING. Copyright 2013 Pearson Education, Inc.

CHAPTER 1 ENGINEERING PROBLEM SOLVING. Copyright 2013 Pearson Education, Inc. CHAPTER 1 ENGINEERING PROBLEM SOLVING Computing Systems: Hardware and Software The processor : controls all the parts such as memory devices and inputs/outputs. The Arithmetic Logic Unit (ALU) : performs

More information

Pemrograman Dasar. Basic Elements Of Java

Pemrograman Dasar. Basic Elements Of Java Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle

More information

6.1. Example: A Tip Calculator 6-1

6.1. Example: A Tip Calculator 6-1 Chapter 6. Transition to Java Not all programming languages are created equal. Each is designed by its creator to achieve a particular purpose, which can range from highly focused languages designed for

More information

ASSEMBLY LANGUAGE PROGRAMMING (6800) (R. Horvath, Introduction to Microprocessors, Chapter 6)

ASSEMBLY LANGUAGE PROGRAMMING (6800) (R. Horvath, Introduction to Microprocessors, Chapter 6) ASSEMBLY LANGUAGE PROGRAMMING (6800) (R. Horvath, Introduction to Microprocessors, Chapter 6) 1 COMPUTER LANGUAGES In order for a computer to be able to execute a program, the program must first be present

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper

More information

Hands-on Exercise 1: VBA Coding Basics

Hands-on Exercise 1: VBA Coding Basics Hands-on Exercise 1: VBA Coding Basics This exercise introduces the basics of coding in Access VBA. The concepts you will practise in this exercise are essential for successfully completing subsequent

More information

C PROGRAMMING FOR MATHEMATICAL COMPUTING

C PROGRAMMING FOR MATHEMATICAL COMPUTING UNIVERSITY OF CALICUT SCHOOL OF DISTANCE EDUCATION BSc MATHEMATICS (2011 Admission Onwards) VI Semester Elective Course C PROGRAMMING FOR MATHEMATICAL COMPUTING QUESTION BANK Multiple Choice Questions

More information

Java CPD (I) Frans Coenen Department of Computer Science

Java CPD (I) Frans Coenen Department of Computer Science Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials

More information

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following: In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our

More information

MATLAB Programming. Problem 1: Sequential

MATLAB Programming. Problem 1: Sequential Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 1 / 21 MATLAB Programming When we use the phrase computer solution, it should be understood that a computer will only follow directions;

More information

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6) Semantic Analysis Scoping (Readings 7.1,7.4,7.6) Static Dynamic Parameter passing methods (7.5) Building symbol tables (7.6) How to use them to find multiply-declared and undeclared variables Type checking

More information

J a v a Quiz (Unit 3, Test 0 Practice)

J a v a Quiz (Unit 3, Test 0 Practice) Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

More information

C / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu

C / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu C / C++ and Unix Programming Materials adapted from Dan Hood and Dianna Xu 1 C and Unix Programming Today s goals ú History of C ú Basic types ú printf ú Arithmetic operations, types and casting ú Intro

More information

Example of a Java program

Example of a Java program Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

More information

Variables, Constants, and Data Types

Variables, Constants, and Data Types Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight

More information

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java CS1020 Data Structures and Algorithms I Lecture Note #1 Introduction to Java Objectives Java Basic Java features C Java Translate C programs in CS1010 into Java programs 2 References Chapter 1 Section

More information

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 04 Digital Logic II May, I before starting the today s lecture

More information

1001ICT Introduction To Programming Lecture Notes

1001ICT Introduction To Programming Lecture Notes 1001ICT Introduction To Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 2, 2015 1 3 A First MaSH Program In this section we will describe a very

More information

Welcome to Introduction to programming in Python

Welcome to Introduction to programming in Python Welcome to Introduction to programming in Python Suffolk One, Ipswich, 4:30 to 6:00 Tuesday Jan 14, Jan 21, Jan 28, Feb 11 Welcome Fire exits Toilets Refreshments 1 Learning objectives of the course An

More information

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming 2.1 Introduction You will learn elementary programming using Java primitive data types and related subjects, such as variables, constants, operators, expressions, and input

More information

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives Introduction to Programming and Algorithms Module 1 CS 146 Sam Houston State University Dr. Tim McGuire Module Objectives To understand: the necessity of programming, differences between hardware and software,

More information

ChE-1800 H-2: Flowchart Diagrams (last updated January 13, 2013)

ChE-1800 H-2: Flowchart Diagrams (last updated January 13, 2013) ChE-1800 H-2: Flowchart Diagrams (last updated January 13, 2013) This handout contains important information for the development of flowchart diagrams Common Symbols for Algorithms The first step before

More information

FEEG6002 - Applied Programming 5 - Tutorial Session

FEEG6002 - Applied Programming 5 - Tutorial Session FEEG6002 - Applied Programming 5 - Tutorial Session Sam Sinayoko 2015-10-30 1 / 38 Outline Objectives Two common bugs General comments on style String formatting Questions? Summary 2 / 38 Objectives Revise

More information

3/13/2012. Writing Simple C Programs. ESc101: Decision making using if-else and switch statements. Writing Simple C Programs

3/13/2012. Writing Simple C Programs. ESc101: Decision making using if-else and switch statements. Writing Simple C Programs Writing Simple C Programs ESc101: Decision making using if- and switch statements Instructor: Krithika Venkataramani Semester 2, 2011-2012 Use standard files having predefined instructions stdio.h: has

More information

MAT 2170: Laboratory 3

MAT 2170: Laboratory 3 MAT 2170: Laboratory 3 Key Concepts The purpose of this lab is to familiarize you with arithmetic expressions in Java. 1. Primitive Data Types int and double 2. Operations involving primitive data types,

More information

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard INPUT & OUTPUT I/O Example Using keyboard input for characters import java.util.scanner; class Echo{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); // scanner for the keyboard

More information

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in

More information

Simple C Programs. Goals for this Lecture. Help you learn about:

Simple C Programs. Goals for this Lecture. Help you learn about: Simple C Programs 1 Goals for this Lecture Help you learn about: Simple C programs Program structure Defining symbolic constants Detecting and reporting failure Functionality of the gcc command Preprocessor,

More information

How To Write Portable Programs In C

How To Write Portable Programs In C Writing Portable Programs COS 217 1 Goals of Today s Class Writing portable programs in C Sources of heterogeneity Data types, evaluation order, byte order, char set, Reading period and final exam Important

More information

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage Outline 1 Computer Architecture hardware components programming environments 2 Getting Started with Python installing Python executing Python code 3 Number Systems decimal and binary notations running

More information

Tutorial on C Language Programming

Tutorial on C Language Programming Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:

More information

C++ Programming Language

C++ Programming Language C++ Programming Language Lecturer: Yuri Nefedov 7th and 8th semesters Lectures: 34 hours (7th semester); 32 hours (8th semester). Seminars: 34 hours (7th semester); 32 hours (8th semester). Course abstract

More information

Once the schema has been designed, it can be implemented in the RDBMS.

Once the schema has been designed, it can be implemented in the RDBMS. 2. Creating a database Designing the database schema... 1 Representing Classes, Attributes and Objects... 2 Data types... 5 Additional constraints... 6 Choosing the right fields... 7 Implementing a table

More information

Custom Linetypes (.LIN)

Custom Linetypes (.LIN) Custom Linetypes (.LIN) AutoCAD provides the ability to create custom linetypes or to adjust the linetypes supplied with the system during installation. Linetypes in AutoCAD can be classified into two

More information

Beyond the Mouse A Short Course on Programming

Beyond the Mouse A Short Course on Programming 1 / 22 Beyond the Mouse A Short Course on Programming 2. Fundamental Programming Principles I: Variables and Data Types Ronni Grapenthin Geophysical Institute, University of Alaska Fairbanks September

More information