110 likes | 232 Views
Kingdom of Saudi Arabia Prince Norah bint Abdul Rahman University College of Computer Since and Information System CS240. Introduction_Cont . T.Najah Al_Subaie. Objectives:. In this section you will learn: Learn C++ standard library, standard streams and names space.
E N D
Kingdom of Saudi Arabia • Prince Norah bint Abdul Rahman University • College of Computer Since and Information System • CS240 Introduction_Cont. T.NajahAl_Subaie
Objectives: • In this section you will learn: • Learn C++ standard library, standard streams and names space. • Learn how to get input from the keyboard. • Learn how to write an output on the screen. • Learn how to use the escape sequences. • Learn C++ syntax rules. • Learn how to write a psudocodeand convert it to a C++ program.
C++ Standard Library • Rich collections of existing code that can be reused in your applications: • Common math calculations e.g. sqrt,sin,cos • Input/output • Date/Time • Provided as part of the C++ development environment • All C++ library entities are defined in one or more standard headers. • You can use the capabilities by referring to the corresponding header file.
Iostream Library • Part of the C++ Standard Library • Provides a uniform way of handling input from (and output) predefined sources. • Based on the concept of a “stream”. • Stream: • Streams are generally connected to a physical source or destination of characters: • A disk file, the keyboard, or the screen.
Streams(1) • Two types: • Input streams: used to hold input from a data producer , such as keyboard, a file. • Output streams: used to hold output for a particular data consumer such as a monitor, a file or a printer.
Streams(2) • Standard input stream (cin ) • Standard output stream (cout) Note: • Keyboard-- program ( cin>>) • Program --- screen (cout<<)
Using cout • Stream insertion operator << • Value to right (right operand) inserted into left operand • Example: • Cout<<“Hello”; • Insert the string” Hello” into the standard output stream(cout). • Displays to the screen. • Escape characters: • A character preceded by”\” • Indicates “ special “ character output • Example: • “\n” • Courser moves to the beginning of the next line on the screen.
Syntax Rules • You must includes <iostream> for cout to work properly. • You must use the namespace std for the cout to work properly. • C++ is case sensitive. Make sure you don’t’ capitalize any of the letters in C++ keywords. • Every statement ends with a ; except for include statements. • String literals must be enclosed in “”. • Main function must return a value to the OS. • Every Opening brace { must have an enclosing brace}.
Examples(2): Adding integers • Write a program that displays the sum of two integers entered at the keyboard: • Define the problem precisely. • Write the psudocode that will solve the problem • Use an Editor to create source code in C++. • Use the compiler to • Check that source code obeys the language rules. • If no errors: Execute your program.