LECTURE 4 التعامل مع VISUAL C++ 2008 + المفاهيم الاساسية في البرمجة

Embed Size (px)

DESCRIPTION

طريقة تثبيت Visual C   3

Citation preview

LECTURE 4 VISUAL C Visual C : 2 Visual C 3 Visual C 4 Visual C 5 visual C 7 Terms : 9 Source code Program in a form suitable for reading and writing by a human being Executable program (executable) Program in a form suitable for running on a computer Compilation Process of translating source code into object code Compiler Program that performs compilation as defined above How to Write a Program 10 1) Define the problem precisely 2) Find and/or create the algorithms that will solve the problem 3) Use a C++ Editor to implement the algorithm to obtain the source code 4) Use the Compiler to Check correctness of source code If No errors, Translate source code into executable program (object code with machine language ) 5) The user runs the resulting executable program on a computer Editor Source Code 11 12 13 14 Typical C++ Environment C++ : , ((.cpp, : student.cpp. (source code ) compiler object code ) ) : student.obj linker : student.exe , , executing : , cpu, , . editor preprocessor compiler linker 15 More Details 16 Source code Vs. object code refer to the "before" and "after" versions of a computer program that is compiled before it is ready to run in a computer To write C++ programs a text editor (Notepad) or a visual programming tool is needed The object code file contains a sequence of instructions that the processor can understand but that is difficult for a human to read or modify. Standard Library Rich collections of existing code that can be reused in your applications Common math calculations e.g. sqrt, pow etc String / character manipulations Date / Time functions Input / output Error checking Provided as part of C++ development environment You can use their capabilities by referring to the corresponding header file that certain library defined in 17 17 iostream Library Part of the C++ Standard Library Provides a uniform way of handling input from and output to predefined sources Based on the concept of a "stream " 18 18 Streams Pre-connected input and output channels between a computer program and its environment when it begins execution A stream is an object where a program can either insert or extract characters to or from it Streams are generally associated to a physical source or destination of characters a disk file, the keyboard, or the screen 19 19 Streams (cont.) Two types Input streams are used to hold input from a data producer, such as a keyboard, a file Output streams are used to hold output for a particular data consumer, such as a monitor, a file, or a printer Programmer only has to learn how to interact with the streams Details about how the stream interacts with the actual devices is left up to the environment or operating system 20 20 Streams (cont.) Standard Input Stream ( cin ) Standard Output Stream ( cout ) Standard Error Stream ( cerr ) 21 program keyboard screen cin cout cerr 21 cin and cout 22 Think of cout as a variable that accepts all data bound for standard output Think of cin as a variable that accepts all data bound for standard input The cout and cin declarations and definitions are located in the header file iostream All of the Standard C++ libraries are wrapped in a single namespace std standard 22 Common Errors Syntax (compilation) Errors encountered during compilation occurs when an instruction does not follow the syntax rules of the programming language e.g. forgetting a semicolon Logic (Semantic) Errors Not detected during compilation produces unintended or undesired results e.g. forgetting to initialize a sum variable 23 23 Common Errors (cont.) Runtime (Execution-time) Errors occurs during the execution of a program May sometimes cause the program to crash e.g. division by zero 24 24 end 25