CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) 2012 - CSC 1201 Course at KSU1.

Slides:



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

True or false A variable of type char can hold the value 301. ( F )
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Programming Switch command. COMP102 Prog. Fundamentals: Switch command / Slide 2 Multiple Selection: The switch Statement value1 action 1 value2 action.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
Quiz 1 Exam 1 Next Week. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) cout
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.
CHAPTER 2 BASIC ELEMENTS OF C++. In this chapter, you will:  Become familiar with the basic components of a C++ program, including functions, special.
Section 2 - More Basics. The char Data Type Data type of a single character Example char letter; letter = 'C';
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.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
CS1201: Programming Language 2 Recursion By: Nouf Almunyif.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan Snd Term Nouf Aljaffan (C) CSC 1201 Course at KSU1.
C++ Programming: Basic Elements of C++.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term
Chapter 05 (Part III) Control Statements: Part II.
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: Introduction to C++. Language Elements Keywords Programmer-defined symbols (identifiers) Operators Punctuation Syntax Lines and Statements.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
CS1201: PROGRAMMING LANGUAGE 2 FUNCTIONS. OVERVIEW What is a Function? Function Prototype Vs Decleration Highlight Some Errors in Function Code Parameters.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
 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++
Chapter 2 Creating a C++ Program. Elements of a C++ Program Four basic ways of structuring a program Four basic ways of structuring a program 1.Sequencing.
1 Structure of Simple C++ Program Chapter 1 09/09/13.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 15, 2004 Lecture Number: 11.
1 17/4/1435 h Monday Lecture 3 The Parts of a C++ Program.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
Bill Tucker Austin Community College COSC 1315
C++ Lesson 1.
Chapter 1.2 Introduction to C++ Programming
Chapter 3 Selection Statements
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
LESSON 2 Basic of C++.
Basic Elements of C++.
Introduction to C++ October 2, 2017.
Programming Fundamentals
Lecture 2-3 C++ Basic Constructs
Chapter 2 part #3 C++ Input / Output
Basic Elements of C++ Chapter 2.
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
Chapter 3: Input/Output
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Summary Two basic concepts: variables and assignments Basic types:
If Statements.
Chapter 4: Control Structures I (Selection)
CS1201: Programming Language 2
C++ Programming Lecture 3 C++ Basics – Part I
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Fundamental Programming
Reading from and Writing to Files
COMS 261 Computer Science I
Chapter 1 c++ structure C++ Input / Output
Reading from and Writing to Files
Presentation transcript:

CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1

C++ OVERVIEW Nouf Aljaffan (C) CSC 1201 Course at KSU2

“Hello World” program #include using namespace std; int main ()‏ { cout << “Hello World\n”; Return 0; } include information from the standard input/output library, iostream. The instruction is more properly called a “preprocessor” instruction The # hash character starts the line to denote a preprocessor instruction. library name must be enclosed by angled brackets. 3 Nouf Aljaffan (C) CSC 1201 Course at KSU

“Hello World” program using namespace std; The second line of the program makes all the functions within the iostream library available for use by their standard names, which are in the namespace std. One of these is a function named cout that is used to write the output from a program. int main ()‏ In the function declaration the data type is specified as int, meaning integer. This means that after executing its statements this function must return an integer value to the operating system. The braces { } contain the statements to be executed by the program. The final statement in the main function Return a value of zero to the operating system to indicate that the program executed correctly. 4 Nouf Aljaffan (C) CSC 1201 Course at KSU

DATA TYPES Nouf Aljaffan (C) CSC 1201 Course at KSU5

DATA TYPES 6 Nouf Aljaffan (C) CSC 1201 Course at KSU

RESERVED WORDS Key Words 7 Nouf Aljaffan (C) CSC 1201 Course at KSU

ESCAPE SEQUENCES 8 Nouf Aljaffan (C) CSC 1201 Course at KSU

Declaring and Initializing Variables To declare variables for example ◦ int first, second; ◦ char ch; ◦ double x; ◦ bool flage; To declare and initialize variables for example ◦ int first = 13, second = 10; ◦ char ch = ‘A’; ◦ double x = 12.6; ◦ bool flage = true; 9 Nouf Aljaffan (C) CSC 1201 Course at KSU

Input (Read) Statement The syntax of cin together with >> is: cin >> variable >> variable >> ……….; ◦ For example: cin >> first >> second; 10 Nouf Aljaffan (C) CSC 1201 Course at KSU

Output The syntax of cout together with << is: cout << expression or manipulator << expression or manipulator ……….; The expression is evaluated and its value is printed at the current insertion point on the output device. A manipulator is used to format the output. The simplest manipulator is endl. 11 Nouf Aljaffan (C) CSC 1201 Course at KSU

Working with String The C++ class provides methods to manipulate strings of text. This is an example of Declaring and initializing a string variable #include using namespace std; int main()‏ { string str = "C++ is fun"; …………} 12 Nouf Aljaffan (C) CSC 1201 Course at KSU

Control Structures IF statement: if (condition) { statement(s); } IF Else statement: if (condition) { statement(s); ← True Branch } else { statement(s); ← False Branch } 13 Nouf Aljaffan (C) CSC 1201 Course at KSU

Example : If statement #include using namespace std; int main() { int num=2; bool flag=0; if( (num==2) && (flag) ) { cout << "The first test is true\n"; } else if( (num==2) && (!flag) ) { cout << "The second test is true\n"; } return 0; } 14 Nouf Aljaffan (C) CSC 1201 Course at KSU

Switch Structures 15 Nouf Aljaffan (C) CSC 1201 Course at KSU

Example: Switch Structures #include #include using namespace std; int main() {} 16 char letter; cout << "Enter any a-z character: "; cin >> letter; switch(letter) { case 'a' : cout << "Letter \'a\' found\n"; break; case 'b' : cout << "Letter \'b\' found\n"; break; case 'c' : cout << "Letter \'c\' found\n"; break; default : cout << "Letter is not a, b or c\n"; } return 0; Nouf Aljaffan (C) CSC 1201 Course at KSU

Relational Operators in C++ 17 Nouf Aljaffan (C) CSC 1201 Course at KSU

Logical Operators in C++ 18 Nouf Aljaffan (C) CSC 1201 Course at KSU

While looping Structure While (condition) { statement(s); } 19 Nouf Aljaffan (C) CSC 1201 Course at KSU

Example: While loop #include using namespace std; int main() { int i=0; while( i<=20 ) { cout << i << " "; i = i + 5 ; } cout << endl; return 0; } output: Nouf Aljaffan (C) CSC 1201 Course at KSU20

For looping Structure  for (expression1; condition; expression2)  {  statement(s)  } 21 Nouf Aljaffan (C) CSC 1201 Course at KSU

Example: For Loop #include using namespace std; int main() { int i,num; cout<<"enter any number: "; cin>>num; for ( i=1 ; i<=10 ; i++ )‏ { cout << endl << num << "*“ << i << "=“ << num*i << endl; } return 0; } Nouf Aljaffan (C) CSC 1201 Course at KSU22 Output : enter any number : 1 1*1=1 1*2=2 1*3=3..