1 / 11

Introduction_Cont .

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.

ailani
Télécharger la présentation

Introduction_Cont .

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Kingdom of Saudi Arabia • Prince Norah bint Abdul Rahman University • College of Computer Since and Information System • CS240 Introduction_Cont. T.NajahAl_Subaie

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. Streams(2) • Standard input stream (cin ) • Standard output stream (cout) Note: • Keyboard-- program ( cin>>) • Program --- screen (cout<<)

  7. 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.

  8. Escape Sequences

  9. Examples

  10. 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}.

  11. 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.

More Related