CS2311 Computer Programming

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

CS105 INTRODUCTION TO COMPUTER CONCEPTS INTRO TO PROGRAMMING Instructor: Cuong (Charlie) Pham.
Introduction Kingdom of Saudi Arabia Shaqra University
INTRODUCTION T.Najah Al_Subaie Kingdom of Saudi Arabia Prince Norah bint Abdul Rahman University College of Computer Since and Information System CS240.
COSC 120 Computer Programming
Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming.
Three types of computer languages
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
CHAPTER 1: INTORDUCTION TO C LANGUAGE
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
CS102 Introduction to Computer Programming
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Chapter Introduction to Computers and Programming 1.
COMPUTER SCIENCE I C++ INTRODUCTION
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Introducing Java.
“C” Programming Language What is language ? Language is medium of communication. If two persons want to communicate with each other, they have to use.
High-Level Programming Languages: C++
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 1- 1 October 20, October 20, 2015October 20, 2015October 20,
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
INTRODUCTION Kingdom of Saudi Arabia Princess Nora bint Abdul Rahman University College of Computer Since and Information System CS240.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
Introduction to C++.  Computers: CPU, Memory & Input / Output (IO)  Program: Sequence of instructions for the computer.  Operating system: Program.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Chapter 1: Introduction to Computers and Programming.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Software Engineering Algorithms, Compilers, & Lifecycle.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.
Chapter 1: Introduction to computers and C++ Programming
Introduction to C++ Programming
CSC201: Computer Programming
Beginning C++ Programming
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Introduction to C++ Programming
CS105 Introduction to Computer Concepts Intro to programming
Introduction to Computer Programming
Programs written in C and C++ can run on many different computers
Capitolo 1 – Introduction C++ Programming
Introduction to Programming - 1
CS105 Introduction to Computer Concepts Intro to programming
Presentation transcript:

CS2311 Computer Programming Dr. Yang, Qingxiong (with slides borrowed from Dr. Yuen, Joe) LT1: Introduction to Programming

Outline What is a Computer? What is a Computer Program? Programming Language Programmer Basic Concept of programming Simple Program

What is a Computer CPU (Central Processing Unit) Motherboard Memory Secondary Storage

Stored Program Computer (Von Neumann Machines)

Personal Computer Input Unit: Get input from user or external environment Output Unit: Show result to user or other programs

Personal Computer CPU (Central Processing Unit): Read instruction from main memory and execute the instruction. Update main memory value or send instruction to motherboard Main Memory: fast storage of program and data in action Secondary Storage: (Slow) storage of program and data files (e.g., maintain them after shutting down the computer).

What is a Computer Program? A list of instructions that instructs a computer to do some tasks

A Computer Program A way to communicates with computers Written in Programming Language

Programming Languages To write a program for a computer, we must use a computer language. Machine Language Language directly understood by the computer binary code

The Multiplication Program in Machine Language The only language understood by computer hardware is machine language.

Programming Languages To write a program for a computer, we must use a computer language. Machine Language Language directly understood by the computer Symbolic Language English-like abbreviations representing elementary computer operations binary code assembly language

The Multiplication Program in Symbolic Language Symbolic language uses symbols, or mnemonics, to represent the various machine language instructions.

Programming Languages To write a program for a computer, we must use a computer language. Machine Language Language directly understood by the computer Symbolic Language English-like abbreviations representing elementary computer operations High-level Language Close to human language. Example: a = a + b [add values of a and b, and store the result in a, replacing the previous value] binary code assembly language C, C++, Java, Basic

The Multiplication Program in C high-level languages are easier for us to understand.

Building a C++ program Writing source code as an C++ file. e.g. “hello.cpp” file Preprocessing Processes the source code for compilation. Compilation Checks the grammatical rules (syntax). Source code is converted to object code in machine language (e.g. “hello.obj” file) Linking Combines object code and libraries to create an executable (e.g. “hello.exe” file). Library: common functions (input, output, math, etc).

There are many Programming Languages in the world!! ActionScript Ada ASP.NET Assembler Basic C C++ C# Cobol Cobra CODE ColdFusion Delphi Eiffel Fortran FoxPro GPSS HTML J# J++ Java JavaScript JSP LISP Logo LUA MEL Modula-2 Miranda Objective-C Perl PHP Prolog Python SQL Visual Basic Visual Basic.NET VBA Visual-FoxPro

Programming Languages Programming languages usually differ in two aspects Language Syntax Standard libraries/SDKs/functions Java if (a>b){ System.out.println(“a is larger than b”); }else{ System.out.println(“a is smaller than or equal to b”); } Pascal if a>b then writeln(‘a is larger than b’); else writeln(‘a is smaller than or equal to b’);

Programming Languages Syntax is well-defined, no exception if (…){…}else{…}; for (;;;){…} while (){…} Basic Components: Variable / structure /function declaration Variable / structure /function access Conditional statement Iteration statement SDK/built-in functions

Programmer

Some Difficulties Computer only follows instructions. It won’t solve problems by itself Programmer needs to: develop an appropriate solution (logic) express the solution in programming language (implementation) validate the logic and implementation (testing)

Requirements Correct syntax Correct logic Efficient Running properly under various constraints Scalability, Maintainability Platform independent

Basic Concept of Programming

Computer Program (External View) Basic elements of a Computer Program Input Process Output

Computer Program (Internal View) A list of instructions ordered logically Usually involve data access

Computer Program Instructions Logic Flow Variable (data) A set of predefined action that a computer can perform E.g. addition, subtraction, read , write Logic Flow Arrangement of Instructions E.g. Calculate BMI (Body Mass Index‎) Read weight from keyboard Read height from keyboard Weight x weight/height Write BMI to screen Variable (data) A space for temporarily store value for future process Constant (data) A value that will not be changed for the whole processing

Logic Flow Turn on the mobile Hand off Key in xxxx - xxxx Wait for connection Wait for connection Turn on the mobile Talking Talking Hang up

Logic Flow Turn on the mobile Turn on the mobile Key in xxxx - xxxx Wait for connection Wait for connection Connection made? Connection made? Yes Yes No Talking Talking Hang up Hang up

Sample Program (Framework)

Simple Program /* The traditional first program in honor of Dennis Ritchie who invented C at Bell Labs in 1972 */ #include <iostream> using namespace std; void main() { cout << "Hello, world!\n"; }

Simple Program /* The traditional first program in honor of Dennis Ritchie who invented C at Bell Labs in 1972 */ Enclosed by “/*” and “*/” or begin with “//” // single line comments // this is a single line comment // each line must begin with “//” sign

Preprocessor directive Give information / instruction to compiler for program creation #include <iostream> Preprocessor directive Tells computer to load contents of a certain file / library In this program, we include the library iostream into the program as it contains the definition of coutwhich is used to print something to the screen. No semi-colon at the end of the include directive using namespace std Specifying that the standard (std) namespace is used such that we can use a shorthand name for the object cout std::cout <-> cout

Functions When writting program, programmer usually group related code (instructions) into functions for easy design and maintenance. We will talk about function and how to write your own function in later lectures.

Function - main void main() { } The starting point of program (the first function called by the computer)

Function - main void main() { } main is the name of the function void means there is no return value no semi-colon after main() C++ is case sensitive: E.g., void Main(), VOID main() are incorrect { } Braces: left brace begins the body of a function. The corresponding right brace must end the function

Simple Program /* The traditional first program in honor of Dennis Ritchie who invented C at Bell Labs in 1972 */ #include <iostream> using namespace std; void main() { cout << "Hello, world!\n”; }

Library / SDK /Package Normally, we won’t write a program all by ourselves. Instead, we will reuse the code written by ourselves / other developers. Especially for the repeating tasks or low-level operation like disk I/O. The reusing code is well designed and pack a library / SDK / Package. Standard C++ program comes with a set of package to make programmer task easier. cout is one of the example.

Object - cout cout << "Hello, world!\n“ ; Object is a programming unit that store values (attributes) and provide functions (methods) to manipulate the values (we will elaborate this concept in future classes) cout: object provided by iostream library (package) for screen (console) output <<: output (also called insertion) operator that output values to an output device. In this case, the output device is cout (the screen) The value on the right hand side of the operator ("Hello, world!\n“ ) is the string you want to output

Object - cout \n escape sequence: the character following \ is not interpreted in the normal way represents a newline character: the effect is to advance the cursor on the screen to the beginning of the next line newline: position the character to the beginning of next line \\ backslash: Insert the backslash character \ in a string \" double quote: Insert the double quote character " in a string

Summary Basic components of a computer program are: Instructions Logic Flow Variable and Constant A correct logic is important in programming Programmer usually reuse code written by the others and the code is commonly in form of library / SDK / packages cout is an object provided by iostream package for screen output

Summary A simple C++ program will have #include <iostream> //A preprocessor using namespace std; //namespace declaration void main(){ /* the starting point of program execution */ }

Summary Development cycle Write a program in plan text via Text editor Notepad, UltaEdit Integrated Development Environment (IDE) E.g. Visual Studio 2005/2008, NetBean Compile the program IDE / ANSI C++ Execute the program IDE / Console shell Debug the program