C++ fundamentals Lecture 1, Chapter 2 – pp49 -98 11/22/2018 Y K Choi.

Slides:



Advertisements
Similar presentations
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
Advertisements

1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Chapter 2 Data Types, Declarations, and Displays
Basic Elements of C++ Chapter 2.
CHAPTER 2 BASIC ELEMENTS OF C++. In this chapter, you will:  Become familiar with the basic components of a C++ program, including functions, special.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Seventh.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Input & Output: Console
M. Taimoor Khan #include void main() { //This is my first C++ Program /* This program will display a string message on.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
1 C++ Syntax and Semantics, and the Program Development Process.
Lecture 3: The parts of a C++ program Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
C++ Programming: Basic Elements of C++.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
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
CHAPTER 2 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
C++ Basics Programming. COMP104 Lecture 5 / Slide 2 Introduction to C++ l C is a programming language developed in the 1970s with the UNIX operating system.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
1 17/4/1435 h Monday Lecture 3 The Parts of a C++ Program.
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.
Today Variable declaration Mathematical Operators Input and Output Lab
C++ First Steps.
Chapter 2: Basic Elements of C++
Chapter Topics The Basics of a C++ Program Data Types
Computer Programming BCT 1113
Topic Pre-processor cout To output a message.
Electrical Engineering Department 1st Year Programming Languages
Chapter 1.2 Introduction to C++ Programming
Chapter 2: Introduction to C++
Wel come.
Basic Elements of C++.
Introduction to C++ October 2, 2017.
Programming Fundamentals
Basics (Variables, Assignments, I/O)
Chapter 2: Introduction to C++
Basic Elements of C++ Chapter 2.
Chapter 2: Introduction to C++
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
2.1 Parts of a C++ Program.
Introduction to C++ Programming
Programming Funamental slides
Basics of ‘C’.
Programming Funamental slides
CS150 Introduction to Computer Science 1
Introduction to C++ Programming
CS150 Introduction to Computer Science 1
Chapter 2: Introduction to C++.
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
What Actions Do We Have Part 1
COMS 261 Computer Science I
COMS 261 Computer Science I
Modifying Objects Assignment operation Assignment conversions
The Fundamentals of C++
Presentation transcript:

C++ fundamentals Lecture 1, Chapter 2 – pp49 -98 11/22/2018 Y K Choi

Topics to Be Covered A simple C++ program Comments in program Assigning a value in C++ Constants Names Definitions Expressions Output statements A simple application Summary 11/22/2018 Y K Choi

A simple program – hello world include: instructs preprocessor to copy contents of isotream.h and string.h into the program, you can use search to find where they are. // This is the hello world #include <iostream> #include <string> using namespace std; void main() { cout << "hello world" <<endl; } Says the program will be using objects that are named in a region called std. cout: character out, note “<<“ and endl 11/22/2018 Y K Choi

Sample Output program Output from DOS 11/22/2018 Y K Choi

Comments It is a good programming practice to add comments for maintenance purpose In c++, there are types of comments: // and /*… */ // for a single line /*….. */ for a block of lines Example: //this is the first program a++; // increment the variable a Example /* ------------------- This is the first program. It involves comments */ For a block of lines 11/22/2018 Y K Choi

Example block Single line 11/22/2018 Y K Choi

Assigning a value Assigning a value to x // This program accepts and output a value #include <iostream> #include <string> using namespace std; int main() { //display the following cout <<"Enter a value (integer)?"; int x; //defines as integer cin >> x; //input a value cout << "The ouput of three times your input is" << 3*x <<endl; return 0; } Assigning a value to x 11/22/2018 Y K Choi

Example Name of file output 11/22/2018 Y K Choi

Constants – a string constant is a sequence of zero or more characters enclosed Use “ “ to quote a string If the string consists of “, use backslash \” Newline \n Tab \t Backspace \b Bell \a Single quote \” 11/22/2018 Y K Choi

Example 11/22/2018 Y K Choi

Constants – integer, octal, hexadecimal and long integer: C++ reserves 4 bytes Example: 23 564 873 Octal: with a leading zero (also 4 bytes) Example: 023 065 01234 Hexadecimal: prefix with 0x or 0X Example: 0x24 0x1F Long: with L (reserves 8 bytes) Example: 12234L 11/22/2018 Y K Choi

Example 11/22/2018 Y K Choi

Floating Point 1234 The general format is Mantissa x 10 ^ exponent 67 11/22/2018 Y K Choi

Names – some words are reserved as part of the language and cannot be used by programmer Definition are: short, int, long, float, double, char Identifiers are: main, cout, endl, cin, switch, this, if, else, for, do , while, class, template, asm, auto You cannot int main //define main as the integer variable 11/22/2018 Y K Choi

Definitions General format Type ID, ID,,,,,; Example int x, y, z; float speed, weight, height; With initialisation int x = 3, y = 4, z= 5; 11/22/2018 Y K Choi

Expressions Simple expressions int weight = 123.5; Binary arithmetic expressions a = b + c; // add two together a = 3*6 //18 a = 12/4; //equal to 3 A = 10%3 // remainder, value is 1 Unary expression int i = 1; ~i; //unary, means 0 – 1 11/22/2018 Y K Choi

Output statements cout (pronounced as “C out” ) cout << (here << is the insertion operator) cout << endl; (endl is a special class of object called a manipulator which means to insert a new line and output the stream to the display (VDU) cout << “CityU”; cout << endl; Can be merged into one as follows cout <<“CItyU” <<endl; 11/22/2018 Y K Choi

Summary Comments // or /*….. */ Assigning a value, use cin >> m Constants, 234 (integer), 45.6 (float) Definition, int a; float f; char c; Names: cannot use defined words such as main Expressions, + - * / and % Output statements, cout 11/22/2018 Y K Choi

11/22/2018 Y K Choi