Introducing C++ Elements. CSCE 1062 Outline Main algorithms’ constructs General form of a C++ program {section 2.5} C++ language elements {section 2.1}

Slides:



Advertisements
Similar presentations
Programming Funamental slides1 Control Structures Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing Sequencing.
Advertisements

C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Structure of a C program
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
The Fundamentals of C++ Basic programming elements and concepts JPC and JWD © 2002 McGraw-Hill, Inc.
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
Chapter 2: Introduction to C++.
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Lecture 5: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept.
Basic Elements of C++ Chapter 2.
By Dr. Awad Khalil Computer Science & Engineering Department
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Variables, Data Types and Constants Yared Semu Addis Ababa Institute of Technology Mar 31, 2012.
High-Level Programming Languages: C++
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
CIS Computer Programming Logic
Input & Output: Console
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.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Chapter 2 Overview of C++. A Sample Program // This is my first program. It calculates and outputs // how many fingers I have. #include using namespace.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Overview of C++ Chapter C++ Language Elements t Comments make a program easier to understand t // Used to signify a comment on a single line.
Lecture #5 Introduction to C++
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
1 C++ Syntax and Semantics, and the Program Development Process.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
C++ Programming: Basic Elements of C++.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Control Structures (B) Topics to cover here: Sequencing in C++ language.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Bill Tucker Austin Community College COSC 1315
C++ Lesson 1.
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 1.2 Introduction to C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 2: Introduction to C++
Computing Fundamentals
Basic Elements of C++.
Lecture2.
Basic Elements of C++ Chapter 2.
Chapter 2.
2.1 Parts of a C++ Program.
CS150 Introduction to Computer Science 1
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Introduction to C++ Programming
Chapter 2: Introduction to C++.
Fundamental Programming
C++ Programming Basics
The Fundamentals of C++
Presentation transcript:

Introducing C++ Elements

CSCE 1062 Outline Main algorithms’ constructs General form of a C++ program {section 2.5} C++ language elements {section 2.1} Executable statements {section 2.4} Reserved words and symbols {section 2.2} Data types {section 2.3}

CSCE 1063 Main Algorithms’ Constucts An algorithm is written as a step-by-step procedure (sequence) in which choices can be made where necessary (selection), and all or part of the algorithm can be repeated (repetition). Thus, the basic control structures of algorithms are: 1- Sequence 2- Selection 3- Repetition

CSCE 1064 Sequence An algorithm is based on the notion of sequence, which is the ordering of steps/statements. Step n cannot be started until step n-1 is complete.

CSCE 1065 General Form of a C++ Program // File: filename // Program description: …. #include directives using namespace std; void main() { Variables declaration section Executable statements section }

CSCE 1066 General Form of a C++ Program (cont’d) Function (a collection of related statements) is the basic unit in C++ A C++ program must contain a main function void main ()  void - function returns no value  main - lower case followed by ()  { } - braces define the function body

CSCE 1067 General Form of a C++ Program (cont’d) General form of function body parts  Declaration statements  Variables and constants  Executable statements  C++ statements

CSCE 1068 Comments Comments make a program easier to understand They are ignored (i.e. not translated) by the compiler // used to signify a comment on a single line /* Text text */ used for comments on multiple lines

CSCE 1069 Compiler Directives #include  Compiler directive  Processed during compilation process  Instructs on what you want in the program #include  Adds library class/file called iostream to program  Used with  Also “ “ user defined

CSCE Program Processing Diagram

CSCE Program Processing Diagram (2)

CSCE Included in iostream  cout refers to the standard output device; i.e. the screen cout << "Hello!";  << output operator (insertion operator)  cin refers to the standard input device; i.e. the keyboard cin >> N1 >> N2;  >> input operator (extraction operator) directs input to variable

CSCE Executable Statements cout displays output on the screen cout << “Enter the distance in miles: ”; cin gets input from the keyboard cin >> miles; Assignment kms = KM_PER_MILES * miles;

CSCE Reserved Words and Symbols Reserved words have special meanings  Can NOT be used for other purposes (const, float and void are some examples) Special symbols / delimiters  C++ has rules for special symbols = * ; { } ( ) // > [ ], + -

CSCE Data Types Predefined data types  int(integer)  Positive or negative whole number   The size of an int depends on the machine and the compiler. On a PC it is usually a word (16 bits).  Other integers types are: short: uses less bits (usually a byte) long: typically uses more bits (usually 2 words)

CSCE Data Types (cont’d)  float(floating point / real number)  Positive or negative decimal number   Integer part and fraction part  The number breaks down into the following parts integer part fractional part  Other floating-point data types are: double long double  bool(boolean)  true  false

CSCE Data Types (cont’d)  char(character)  Represents a character  Individual character value (letter or number)  Character literal enclosed in single quotes ‘A’  Characters are encoded using a scheme where an integer represents a particular character

CSCE Exercise Problem Analyse, design (using a flow chart), and implement (using C++) an algorithm that calculates, and outputs the sum (sum) of three numbers (n1, n2 & n3) input by the user. Analysis  Input float n1: first variable float n2: second variable float n3: third variable  Output float sum: sum of n1, n2, & n3

CSCE Exercise (cont’d) INPUT n1, n2, n3 OUTPUT sum START STOP sum = n1 + n2 + n3 Design Implementation (C++) #include using namespace std; void main () { float n1, n2, n3, sum; cout << “Please input three numbers”; cin >> n1 >> n2 >> n3; sum = n1 + n2 +n3; cout << “The sum is” << sum; } Processing

CSCE Addition.cpp /* FILE: Addition.cpp PROGRAM: Adds three numbers input by the user */ #include using namespace std; void main () { float n1, n2, n3, sum;// declaring variables cout << “Please input three numbers”; cin >> n1 >> n2 >> n3;// inputting 3 variables sum = n1 + n2 + n3;// adding the 3 variables cout << “The sum is:” << sum;// outputting sum }

CSCE Next lecture will be about Arithmetic Expressions