Programming 1 (CS112) Dr. Mohamed Mostafa Zayed 1.

Slides:



Advertisements
Similar presentations
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
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 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.
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
If You Missed Last Week Go to Click on Syllabus, review lecture 01 notes, course schedule Contact your TA ( on website) Schedule.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Chapter 8: Introduction to High-Level Language Programming Invitation to Computer Science, C++ Version, Fourth Edition.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
COMPUTER SCIENCE I C++ INTRODUCTION
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Instructor: Tina Tian. About me Office: RLC 203A Office Hours: Wednesday 1:30 - 4:30 PM or .
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
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.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan Snd Term Nouf Aljaffan (C) CSC 1201 Course at KSU1.
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.
Course Title: Introduction to C++ Course Instructor: ADEEL ANJUM Chapter No: 01 1 BY ADEEL ANJUM (MCS, CCNA,WEB DEVELOPER)
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.
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:
CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Basic Program Construction
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
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.
Program Development Cycle 1.Edit program 2.Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied,
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
Lecture 4 Computer Programming // sample C++ program #include using namespace std; int main() { cout
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Bill Tucker Austin Community College COSC 1315
C++ Lesson 1.
Programming what is C++
Chapter Topics The Basics of a C++ Program Data Types
Topic Pre-processor cout To output a message.
CMPT 201.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE
Chapter 1: Introduction to computers and C++ Programming
Chapter 2 Introduction to C++ Programming
CSC201: Computer Programming
CS-103 COMPUTER PROGRAMMING
Chapter 2, Part I Introduction to C Programming
Computing Fundamentals
Chapter 2 part #1 C++ Program Structure
Basic Elements of C++.
Beginning C++ Programming
Data types and variables
Getting Started with C.
Computer science By/ Midhat Mohiey. Introduction to Programming using C ++ 2.
Basic Elements of C++ Chapter 2.
Chapter 8: Introduction to High-Level Language Programming
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Introduction to C++ Programming
Lecture 2 Fall 2011 September 13-15, 2011 Ghufran Ahmed
C++ Programming Basics
COMS 261 Computer Science I
Introduction to C Programming
Chapter 1 c++ structure C++ Input / Output
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Programming 1 (CS112) Dr. Mohamed Mostafa Zayed 1

Outline An idea about program and algorithm design and application of C++ language Variables, data types Input / Output functions Arithmetic and relational operators and mathematical expressions Control statements through the – conditional statement with its different types – looping with its types Matrices of one and two dimensions – Functions – Pointers – an Sturcts. 2

Books 3 Main Textbook: – C++: How To Program, Deitel and Deitel, 4th edition, Prentice Hall, – Available from Taibah University Library Alternative: – Any book that introduces computer science and programming principles using C++. – NB: should be an introductory book on C++.

Schedules & Assesment system Periodical test1 (20%) – ( Last week before mid-term holiday ) 3:00~4:00 – Tue 1/5/1432, 5/4/2011 Periodical test2 (20%) Projects (10%) Lab assignments and attendance (10%) Final (40%) 4

Programming with C++ 5

Learning C++ C++ joins three separate programming traditions – The procedural language tradition – The object-oriented language tradition, represented by the class enhancements C++ adds to C – Generic programming, supported by C++ templates. 6

Procedural Languages Earlier procedural languages, such as FORTRAN and BASIC, ran into organizational problems as programs grew larger. For example, programs often use branching statements, which route execution to one or another set of instructions depending upon the result of some sort of test. It was virtually impossible to understand a program by reading it 7

Structured programming structured programming limits branching (choosing which instruction to do next) to a small set of well-behaved constructions. C incorporates these constructions (the for loop, the while loop, the do while loop, and the if else statement) into its vocabulary. 8

Object Oriented Programming (OOP) Encapsulation – The technical term for combining data and functions together as a bundle is encapsulation. Inheritance – lets you derive new classes from old ones. Polymorphism – Poly refers many. So Polymorphism as the name suggests is a certain item appearing in different forms or ways. That is making a function or operator to act in different forms depending on the place they are present is called Polymorphism. 9

Generic Programming The term generic means to create code that is type- independent. generic programming provides tools for performing common tasks, such as sorting data or merging lists. for example, if you want to sort data of various types, you normally have to create a separate sorting function for each type. Generic programming involves extending the language so that you can write a function for a generic (that is, not specified) type once, and use it for a variety of actual types. C++ templates provide a mechanism for doing that. 10

Portability and Standards If you move the program to another platform Can you run your program on the new platform? Of course, you'll have to recompile the program using a C++ compiler designed for the new platform. But will you have to make any changes to the code you wrote? If you can recompile the program without making changes and it runs without a change, we say the program is portable. 11

Portability and Standards Cont. There are a couple of obstacles to portability, the first of which is hardware. The second obstacle to portability is language divergence. Although most implementers would like to make their versions of C++ compatible with others, it's difficult to do so without a published standard describing exactly how the language works. Therefore, the American National Standards Institute (ANSI) created a committee in 1990 to develop a standard for C++. 12

The Mechanics of Creating a Program 13

Creating the Source Code 14

Compiler?? 15 Compiler Is a computer program that translates a high-level language to an object program.

Hello World program #include using namespace std; int main() { cout << “Hello World"; return 0; } 16

Explanation of Hello World program There are other common header files. #include 17

#include Preprocessor directive Lines beginning with a hash sign (#) are directives for the preprocessor. They are not regular code lines with expressions but indications for the compiler's preprocessor. The directive #include tells the preprocessor to include the iostream standard header file. This specific file (iostream) includes the declarations of the basic standard input-output library in C++. There are other common header files. #include

using namespace std; All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name std. So 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.

int main(void){ } – All C++ programs begin processing at the first executable statement in main. – The “()” indicate that main is a block of code called a function. – The int in front of main declares main to be a function that is expected to “return" an integer. – The lines of code in between the “{ }” is called the function body. 20

Using Cout To print a value to the screen, write the word cout, followed by the insertion operator (<<) cout << “Welcome to C++"; 21

Comments Comments are simply text that is ignored by the compiler, but that may inform the reader of what you are doing at any particular point in your program. Types of Comments – The double-slash (//) comment – The slash-star (/*) comment. 22

Escape Sequences 23 cout << "Here is a very big number:\t" << <<

Example1 #include using namespace std; int main() {cout<<“Welcome”; cout<<“to ”; cout<<“c++”; return 0; } Output ?? Welcome to c++ 24

Example2 Int main() {cout<<“Welcome\nto\nc++”; } Output Welcome To C++ 25

Case Sensitivity C++ is case-sensitive. In other words, uppercase and lowercase letters are considered to be different. A variable named age is different from Age, which is different from AGE. 26