Full Transcript

Computer Programming in Engineering (GEU1090) Lecture 2 Faroq Razzaz Outline Inputs and Output (I/O) Streams Operators in C++ Common Functions in Inputs and Output (I/O) Streams I/O: sequence of bytes (stream of bytes) from source to destination Stream: sequen...

Computer Programming in Engineering (GEU1090) Lecture 2 Faroq Razzaz Outline Inputs and Output (I/O) Streams Operators in C++ Common Functions in Inputs and Output (I/O) Streams I/O: sequence of bytes (stream of bytes) from source to destination Stream: sequence of characters from source to destination Input stream: sequence of characters from an input device to the computer Output stream: sequence of characters from the computer to an output device Inputs and Output (I/O) Streams Use iostream header file to extract (receive) data from keyboard and send output to the screen Contains definitions of two data types: o istream - input stream o ostream - output stream Has two variables: o cin - stands for common input o cout - stands for common output To use cin and cout, the preprocessor directive #include must be used Inputs and Output (I/O) Streams cin >> var_name1, var_name2; Inputs and Output (I/O) Streams cout , =, greater than = greater than or equal to The results of the expressions containing these operators are called Boolean values and they are either True or False. Operators in C++: Logical Operators The logical operators help in forming the Boolean expressions and the results of the expressions containing these operators are also called Boolean values and they are either True or False. && AND || OR ! NOT These Operators are performed based on the main Truth Table. A B A&&B A||B !A !B 0 0 0 0 1 1 0 1 0 1 1 0 1 0 0 1 0 1 1 1 1 1 0 0 Operators in C++ Precedence of Logical and Relational Operators 1. < >= 2. == != 3. && 4. || e.g.: (-6=10) True && True True e.g.: (3.0>2.0)||(3.0>=4.0) True || False True e.g.: (3.0>2.0)&&(3.0>=4.0) True && False False Common Functions in Common Functions in Common Functions in Example:

Use Quizgecko on...
Browser
Browser