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.

Slides:



Advertisements
Similar presentations
Module 6: Introduction to C Language ITEI102 Introduction to Programming Structure of C++ Program - Programming Terminologies - Microsoft Visual Studio.
Advertisements

 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
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
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
Three types of computer languages
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Programming is instructing a computer to perform a task for you with the help of a programming language.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Introduction to C++ Programming
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed.
Chapter 01: Introduction to Computer Programming
COMPUTER SCIENCE I C++ INTRODUCTION
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
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.
Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2.
Creating your first C++ program
Programming With C.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
1 C++ Syntax and Semantics, and the Program Development Process.
Week 1 Algorithmization and Programming Languages.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE 1 st semester H 1 King Saud University College of Applied studies and Community Service Csc 1101 By:
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
INTRODUCTION Kingdom of Saudi Arabia Princess Nora bint Abdul Rahman University College of Computer Since and Information System CS240.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
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.
Basic Program Construction
1 A simple C++ program // ======================================================= // File:helloworld.cpp // Author:Vana Doufexi // Date:1/4/2006 // Description:Displays.
Chapter 2 part #1 C++ Program Structure
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
Learners Support Publications Introduction to C++
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.
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 Structure of Simple C++ Program Chapter 1 09/09/13.
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.
Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Introduction to C Topics Compilation Using the gcc Compiler
C++ Lesson 1.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE
Chapter 1: Introduction to computers and C++ Programming
Introduction to C++ Programming
CSC201: Computer Programming
CS-103 COMPUTER PROGRAMMING
Chapter 2 part #1 C++ Program Structure
Basic Elements of C++.
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.
Beginning C++ Programming
Computer Engineering 1nd Semester
Introduction to C Topics Compilation Using the gcc Compiler
Basic Elements of C++ Chapter 2.
1.13 The Key Software Trend: Object Technology
Programming Fundamentals Lecture #3 Overview of Computer Programming
Programs written in C and C++ can run on many different computers
Capitolo 1 – Introduction C++ Programming
Introduction to Programming - 1
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

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 Program is created in the editor and stored on disk. Preprocessor program processes the code. Loader puts program in memory. CPU takes each instruction and executes it, possibly storing new data values as the program executes. Compiler Compiler creates object code and stores it on disk. Linker links the object code with the libraries, creates a.out and stores it on disk Editor Preprocessor Linker CPU Primary Memory Disk

C++ INPUT AND OUTPUT C++ programs make use of a library called iostream (input / output stream library). Input/output cin Standard input stream An input stream gets data bytes from some input device and routes them to a program. Normally keyboard

C++ INPUT AND OUTPUT Cout Standard output stream An output stream is something that takes character data and gets them to an output device. Normally computer screen cerr Standard error stream Display error messages

First program // my first program in C++ #include using namespace std; int main () { cout << "Hello World!"; Return o; } Hello World!

First Program The easy way to start learning a programming language is to start by a program. it is one of the simplest programs that can be written in C++. it contains the fundamental components that every C++ program has. As an entry point to C++, the above program is explained line by line.

First Program // my first program in C++ This is a comment line. All lines beginning with two slash signs (//) are considered comments. they do not have any effect on the behaviour of the program. The programmer can use them to include short explanations or observations within the source code itself. In this case, the line is a brief description of what our program is.

Directives #include Lines beginning with a hash sign (#) are directives for the pre-processor. not regular code lines with expressions. indications for the compiler's pre-processor. In this case the directive #include tells the pre-processor to include the iostream standard file. This specific file (iostream) includes the declarations of the basic standard input-output library in C++. it is included because its functionality is going to be used later in the program.

Namespace using namespace std; All the elements of the standard C++ library are declared within what is called a namespace. its name is std. in order to access its functionality we declare with this expression that we will be using these entities. This line is very frequent in C++ programs that use the standard library. it will be included in most of the source codes during this course.

The main function int main () This line corresponds to the beginning of the definition of the main function. The main function is the point by where all C++ programs start their execution, independently of its location within the source code. It does not matter whether there are other functions with other names defined before or after it. the instructions contained within this function's definition will always be the first ones to be executed in any C++ program. it is essential that all C++ programs have a main function.

Cont. Main function int main () The word main is followed in the code by a pair of parentheses (()). because it is a function declaration. In C++, what differentiates a function declaration from other types of expressions are these parentheses that follow its name. Optionally, these parentheses may enclose a list of parameters within them. Example: int main (int x, int y)

Cont. Main function int main () { } after these parentheses we can find the body of the main function enclosed in braces ({}). What is contained within these braces is what the function does when it is executed.

Statements cout << "Hello World!"; This line is a C++ statement. A statement is a simple or compound expression that can actually produce some effect. this statement performs the only action that generates a visible effect in our first program. Cout represents the standard output stream in C++. the meaning of the entire statement is to insert a sequence of characters (in this case the “Hello World” sequence of characters) into the standard output stream (which usually is the screen).

Cont. Statement cout is declared in the iostream standard file within the std namespace, so this is why we included the using namespace std; Notes: The statement ends with a semicolon character (;). If you forget the semicolon character after a statement you will face syntax error.

Cont. Statement return 0; The return statement causes the main function to finish. return may be followed by a return code (in our example is followed by the return code 0). A return code of 0 for the main function is generally interpreted as the program worked as expected without any errors during its execution. This is the most usual way to end a C++ console program.

conclusion Not all the lines in this program perform actions when the code is executed. There were lines containing only comments (those beginning by //). There were lines with directives for the compiler's pre- processor (those beginning by #). There were lines that began the declaration of a function (in this case, the main function). There were lines with statements (like the insertion into cout), which were all included within the block delimited by the braces ({}) of the main function.

The program has been structured in different lines in order to be more readable, but in C++, we do not have strict rules on how to separate instructions in different lines. For example, instead of int main () { cout << "Hello World!"; Return o; } We could do something like int main () { cout << "Hello World!"; return 0; } As long as each statement has to ends by #.