Example 21 #include<iostream.h> int main() { char Letter = 0;

Slides:



Advertisements
Similar presentations
1 C++ string Class Chapter 6. 2 Agenda String Basics (cin, getline )  string operations mixed I/O using >> & getline() Table Output using setw() Functions.
Advertisements

True or false A variable of type char can hold the value 301. ( F )
Conditional Operator (?:) Conditional operator (?:) takes three arguments (ternary) Syntax for using the conditional operator:
Programming Switch command. COMP102 Prog. Fundamentals: Switch command / Slide 2 Multiple Selection: The switch Statement value1 action 1 value2 action.
C++ Typecasting. Math Library Functions.. Operator / Operands A = x + y.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays –Structures of related data items –Static entity (same size throughout program) A few types –Pointer-based.
1 CS 105 Lecture 6 While Loops Wed, Feb 16, 2011, 5:13 pm.
Multiple-Subscripted Array
What is the out put #include using namespace std; void main() { int i; for(i=1;i
Arrays.
Quiz 1 Exam 1 Next Week. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) cout
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
Input and Output in Console Mode UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
 Write a program that uses a one dimension to do a table look-up  Learn about parallel arrays.
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.
Switch Statement in C++. Syntax switch (selector) { case L1: statements1; break; case L2: statements2; break; … default: statements_n; } Semantics: This.
Copyright © Nancy Acemian 2004 For Loops-Break-Continue COMP For loop is a counter controlled loop. For loop is a pretest loop. Used when number.
Chapter 05 (Part III) Control Statements: Part II.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
1 CS161 Introduction to Computer Science Topic #8.
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
CSci 162 Lecture 6 Martin van Bommel. Functions on Structures Rather than pass a copy of structure to a function, or return a copy back as the function.
Array. Array is a group of data of the same type. Array elements have a common name –The array as a whole is referenced through the common name Individual.
Lecture 2 Arrays. Topics 1 Arrays hold Multiple Values 2 Accessing Array Elements 3 Inputting and Displaying Array Contents 4 Array Initialization 5 Using.
Switch Statements Comparing Exact Values
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
Infinite for Loop If you omit the test condition, the value is assumed to be TRUE so the loop will continue indefinitely unless you provide some other.
EC-111 Algorithms & Computing Lecture #10 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Pointers What is the data type of pointer variables?
生查子 ~ 歐陽修 去年元夜時,花市燈如晝, 月上柳梢頭,人約黃昏後; 今年元夜時,月與燈依舊, 不見去年人,淚濕春衫袖。
Pointers & Arrays.
Chapter 7 – Arrays.
Recursion Chapter 12.
Arrays Arrays exist in almost every computer language.
Chapter 3. Expressions and Interactivity
Array An “average.cpp” program
A mechanism for deciding whether an action should be taken
CSC 113: Computer Programming (Theory = 03, Lab = 01)
Programming Fundamentals
Chapter 2.2 Control Structures (Iteration)
C++ Arrays.
C++ Data Types Simple Structured Address Integral Floating
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
Introduction to Programming
Working With Arrays.
Counting Loops.
Lecture 12 Oct 16, 02.
الوحدة الرابعة البرمجة وصياغة حل المسائل البرمجة وأهميتها أهداف الدرس الأول مفهوم البرمجة. الفرق بين المبرمج ومستخدم البرنامج. الحاجة إلى البرامج.
Decision Structures Case Structures.
Chapter 2.2 Control Structures (Iteration)
String What it is Why it’s useful
CS150 Introduction to Computer Science 1
Dynamic Memory A whole heap of fun….
CPS120: Introduction to Computer Science
Fundamental Programming
do/while Selection Structure
Arrays Arrays A few types Structures of related data items
Fundamental Programming
Pointers & Arrays.
C++ Programming Lecture 18 Pointers – Part II
C++ Programming Lecture 20 Strings
The Stack.
The switch Statement When we want to compare a variable against several values to see which one it has, we can use the switch statement: switch (status)
CS150 Introduction to Computer Science 1
Arrays Prepared By Paritosh Srivastava PGT (CS) KV NHPC Banbasa.
C++ Programming Lecture 7 Control Structure I (Selection) – Part II
Programming Fundamental
Presentation transcript:

Example 21 #include<iostream.h> int main() { char Letter = 0; cout <<"Enter a lower case letter: "; cin >> Letter; switch (Letter * (Letter>='a' && Letter <= 'z')) case 'a': case 'e': case 'i': case 'o': case 'u': cout <<endl <<"You have entered a vowel."; break; case 0: cout <<endl << Letter <<" it is not a lower case letter."; default: cout <<endl <<"You entered a consonant." ; } cout <<endl; return 0;

Example 22 #include<iostream.h> int main() { char indicator ='n'; long value =0, factorial = 0; do cout <<"Enter an integer value: "; cin >> value; factorial = 1; for (int i=2; i<=value; i++) factorial *=i; cout <<"Factorial " <<value <<" is " <<factorial; cout <<endl <<"Do you want to enter another value (y or n)?"; cin >>indicator; } while ((indicator == 'y')|| (indicator == 'y')); return 0; }

Example 23 #include<iostream.h> #include<iomanip.h> int main() { int SIZE =9; int i=0, j=0; cout <<SIZE <<" by " <<SIZE <<"multiplication table"; cout <<endl; cout <<endl <<" |"; for (i=1; i<=SIZE; i++) cout <<setw(3) <<i <<" "; for (i=0; i<=SIZE; i++) cout <<"_____"; cout <<endl <<setw(3) <<i <<" |"; for (j=1; j<=SIZE; j++) cout <<setw(3) <<i*j <<" "; } return 0;

Arrays An array is simply a number of memory locations, each of which can store an item of data of the same data type and which are all referenced through the same variable name. Type name[size] Type name[row][column]

Example 24 #include <iostream.h> #include <iomanip.h> int main() { int array1[6]={1, 2, 3 ,4, 5, 6}; int array2[6]={1, 2, 3}; int array3[6]; for (int i=0; i<6; i++) cout <<setw(12) <<array1[i]; cout <<endl; for (i=0; i<6; i++) cout <<setw(12) <<array2[i]; cout <<setw(12) <<array3[i]; cout <<endl; return 0; }

Example 25 #include <iostream.h> #include <iomanip.h> int main() { int array1[2][6]={ {1, 2, 3 ,4, 5, 6}, {6, 5, 4, 3, 2, 1} }; int array2[2][6]={ {1, 2, 3}, {4, 3, 2, 1} int array3[2][6]={0}; for (int i=0; i<2; i++) for (int j=0; j<6; j++) cout <<setw(12) <<array1[i][j]; cout << endl <<endl; for (i=0; i<2; i++) cout <<setw(12) <<array2[i][j]; cout <<endl <<endl; cout <<setw(12) <<array3[i][j]; cout <<endl; return 0; }