Computer Programming Lecturer: Ir Dr Frank H.F. LEUNG

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

EC-111 Algorithms & Computing Lecture #1 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
 2005 Pearson Education, Inc. All rights reserved Introduction.
COSC 120 Computer Programming
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Course Introduction and Getting Started with C 1 USF - COP C for Engineers Summer 2008.
Systems Software Operating Systems.
Object Oriented Software Development 1. Introduction to C# and Visual Studio.
1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
1 ENG236: ENG236: C++ Programming Environment (2) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
Principles of Programming Chapter 1: Introduction  In this chapter you will learn about:  Overview of Computer Component  Overview of Programming 
A First Program Using C#
Intro. to Game Programming Want to program a game?
 2008 Pearson Education, Inc. All rights reserved Introduction to Computers, the Internet and World Wide Web.
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
CS Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
C++ Programming Language Lecture 1 Introduction By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
Just as there are many human languages, there are many computer programming languages that can be used to develop software. Some are named after people,
Computer Science I How to Configure Visual Studio.NET 2003 for C++ Colin Goble.
Systems Software Operating Systems. What is software? Software is the term that we use for all the programs and data that we use with a computer system.
3. The Nuts and Bolts of C++ Computer Programming 3. The Nuts and Bolts of C++ 1 Learning the C++ language 3. The Nuts and Bolts of C++
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
Liang, Introduction to C++ Programming, (c) Chapter 1 Introduction to Computers, Programs, and C++
N from what language did C++ originate? n what’s input, output device? n what’s main memory, memory location, memory address? n what’s a program, data?
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Principles of Programming Chapter 1: Introduction  In this chapter you will learn about:  Overview of Computer Component  Overview of Programming 
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Software Engineering Algorithms, Compilers, & Lifecycle.
Dive Into® Visual Basic 2010 Express
Chapter 1 Introduction to Computers, Programs, and C++
Installing Java on a Home machine
Putting Computer Systems to Work
Development Environment
Chapter 2: The Visual Studio .NET Development Environment
Introduction to Computers, the Internet and the World Wide Web
Computer Terms Review from what language did C++ originate?
Chapter 1: Introduction to computers and C++ Programming
CSCI-235 Micro-Computer Applications
Introduction to Visual Basic 2008 Programming
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Beginning C++ Programming
Introduction to Computers and Java
Java programming lecture one
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
VISUAL BASIC.
Hands-on Introduction to Visual Basic .NET
Advanced Programming Lecture 02: Introduction to C# Apps
CIS16 Application Development Programming with Visual Basic
CIS16 Application Development – Programming with Visual Basic
Chapter 1: An Overview of Computers and Programming Languages
1. Open Visual Studio 2008.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
CMP 131 Introduction to Computer Programming
Chapter 3 – Introduction to C# Programming
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Programs written in C and C++ can run on many different computers
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Computer Terms Review from what language did C++ originate?
1.3.7 High- and low-level languages and their translators
Chapter 2 part #1 C++ Program Structure
IS 135 Business Programming
Presentation transcript:

Computer Programming Lecturer: Ir Dr Frank H.F. LEUNG THE HONG KONG POLYTECHNIC UNIVERSITY Computer Programming Department of Electronic and Information Engineering Lecturer: Ir Dr Frank H.F. LEUNG Room: CD633 Tel: 2766 6224 E-Mail: frank-h-f.leung@polyu.edu.hk On-line tutorial in Blackboard (L@PU理學網): https://learn.polyu.edu.hk ENG2002_20161_x: Computer Programming  Discussions

References: S. Rao, Sams Teach Yourself C++ in One Hour a Day (7th ed.) Indianapolis, Ind.: Sams, 2012. P.J. Deitel and H.M. Deitel, C++ How To Program (9th ed.) Boston, MA: Prentice Hall, 2014. J Liberty and R. Cadenhead, Sams Teach Yourself C++ in 24 hours (5th ed.) Indianapolis, Ind.: Sams, 2011.

Contents What is Computer Programming? A Taste of C++ Nuts and Bolts of C++ Program Flow Control Program Design and Debugging Objects and Classes in C++ Pointers and Arrays Stream I/O

What is Computer Programming? Getting Started What is Computer Programming?

Computer Programming What is Computer Programming? Computer Programming A systematic approach to instruct a computer doing something for us. Hardware I/O devices CPU Memory

(Compile, link and load) Process of Computer Programming Way of thinking Computer Computing Problems Operating System Hardware Algorithms and Data Structures Mapping Coding Application Software High-level Language Binding (Compile, link and load)

Coding Computer can only manipulate 0 and 1 The most direct way to communicate with the computer is to use 0 and 1  Machine Language Programming 0110001111000010 0001000111100011 : 0011000100001000 1000001001010101 Machine Language Program Very tedious and can make error easily

Coding - Assembly Language Assembly Language is created to help human instructing CPU to work By using a software tool called Assembler, assembly language programs can be converted into machine language programs. Assembly Language Machine Language LD R0, #05 ADD R0, $1234 : SUB R0, #22 LD $2345, R0 0110001111000010 0001000111100011 : 0011000100001000 1000001001010101 Assembler

Coding - High Level Language Assembly language programming is still too complicated for general users They are far from human used language, e.g. Set W equal to W plus X minus Y divided by Z Repeat the next sequence of instructions until X is less than 0 or Y equals Z A high level language is required to reduce the gap between human and computers.

Compiler Linker Start Give me the result of adding 1 to 10 1011010101 High Level Language Program Start Details in the following slides Compiler Object code .cpp file 1011010101 0101010101 : Executable Machine Language Program .exe file Finish Linker Library

Compiler: Generate the object code Object code  Similar to the machine language code but cannot be executed because of the missing of some information. Linker: Resolve the missing information from the library or other programs. For a program, it is very common that some of the information in the program needs to be obtained from the Library provided by the programming tool. It is the job of linker to obtain these missing information.

Coding - High Level Languages From time to time, high level languages (HLL) are designed for different purposes Earlier examples: BASIC: for simple and general computing (obsolete for long) COBOL: for data processing (still using in banks) FORTRAN: for scientific computation (ever replaced by C or C++) Recent examples: Pascal: a sophisticated but complex HLL (replaced by C or C++) C: a simple structural HLL for general computing (still in use) Current examples: C++: the most well-known object-oriented (OO) language Java: an OO language designed with the concept of networking.

Programming Language C++ The Object-Oriented programming concept is overwhelming OO Programming has the advantage of achieving reuse of software components C++ is an extension to the popular C language The C++ programming language is created to implement the concept of OO programming It has become the predominant language for the development of commercial software Standardized by the American National Standards Institute (ANSI), C++ program is portable to different machines.

Getting Started A Taste of C++ Learn the development environment

Programming Environment Before doing any C++ programming, first we need to familiarize with the programming environment. A programming environment is a software package that can help us develop and test program code. For PCs, one of the most popular programming environment is the Microsoft Visual Studio. It is more popular because of the direct support to and from the Microsoft Windows environment.

Visual Studio Community 2015 Visual C++ is one of the components of the product – Visual Studio, which also contains development tools for other programming languages, e.g. Visual Basic, Visual C#, etc. The version we use is Visual Studio Community 2015 (Visual Studio Enterprise 2015 in lab). The compiler that is incorporated is Visual C++ 2015. Additional features include Produce C++/CLI codes that run in the Common Language Runtime (CLR) Allow the use of .NET Framework class libraries. NOT covered in ENG2002

Solution and Project They are all in files In Visual Studio, each user task is referred to as a solution to a problem. A solution refers to the computer resource (such as memory, disk space, etc.) required for one or more projects to complete the task. Every project contains executable code and debug information the C++ programs (source code) classes and objects used in the project other related resources such as icon images used in the project graphical user interface (GUI), e.g. button, menu. ONE solution ONE project in this subject They are all in files NOT covered in ENG2002

A Solution must contain at least one Project Files A Solution must contain at least one Project Solution Project 1 A Project must contain at least one File Project 2 Project 3 ONE solution ONE project in this subject ENG2002

Build your first project - HelloWorld To Build a project means to produce target executable file(s) (.exe file) based on the program code. Project can be built to execute in console or windows mode Console mode: Use the Command Prompt for input and output Windows mode: Use the Windows environment for program execution. NOT covered in ENG2002

Command Prompt It is a traditional interface between the user and computer The user types in commands to instruct the computer to work.

Build your first project - HelloWorld a.cpp: File containing a C++ program that prints a message "Hello World!" on the console output, i.e. the display screen The returned type of main() MUST be declared in Visual Studio 2015 (void is needed if you return nothing.) #include <iostream> int main() { std::cout << "Hello World!" << std::endl; return 0; }

Step 1: Start Visual Studio 2015 Click New Project... First time starting may take minutes, be patient. Step 1: Start Visual Studio 2015 Click New Project...

Step 2 You can modify the location of the files of your project. Note where you create this project

Click Next > NEVER click Finish

Step 3

Step 4: Right-click Source Files, select Add → New Item...

Step 5: Choose C++ File (.cpp). Give a name to the C++ file you are going to add

Display compilation results Solution Explorer Display resources of the solution, such as, projects and files inside Source Program Editing Display compilation results

Step 6: Type the program on p.21 in here Click Build → Build Solution See the built result

Step 7: Execute the program by clicking Debug → Start Without Debugging Do you see the following result? Note: The result is shown in the Command Prompt (cmd.exe) because we are developing a Console Application

What actually has been done? C++ source file: a.cpp In this HelloWorld example, one solution is created that contains a project called chap2p1. Inside the project, there is one C++ source file called a.cpp. Solution Project: chap2p1

All files generated in this project is stored in C:\VS_Proj\chap2p1 The C++ Compiler of Visual Studio compiles the program in a.cpp and generates an executable file named chap2p1.exe. When you click Debug → Start Without Debugging, Visual Studio actually runs the executable file chap2p1.exe for you. All files generated in this project is stored in C:\VS_Proj\chap2p1 Build Seen from Windows Explorer

Windows Explorer Contains files created after building the solution Contains info. about the project. Double-click this will automatically start the project The C++ source file you created

The EXE (executable) file created

We can always run the program under Command Prompt

Exercise 2.1 Consider the two programs on the RHS. For each program, construct a new project in Visual Studio and then build the solution. For each program, note the error messages on building the project. Fix the errors and execute them so that you can read the string "C++" on the screen. #include <iostream> int main() std::cout << "C++" << endl; return 100; } #include <iostream> int Main() { std::cout << "C++" << std::endl; return 0; }

Exercise 2.2 Observe the output and explain. 1. Build the project in P.21. Open the Command Prompt. By using the command cd, change the current folder to the folder that contains chap2p1.exe. (You may want to use the command dir to show the content of a folder.) Run chap2p1.exe by typing its file name and press Enter. Compare the result with that you run the program inside Visual Studio. State the difference between them. Add the following lines of code before "return 0;" of a.cpp. std::cout<<"Press Enter to continue!"<<std::endl; std::cin.get(); Rebuild the solution. Repeat steps 1 to 4 and try to guess the use of "std::cin.get();".