Fundamental Of Structured Programming Lecture 2 PDF

Summary

This document is a lecture on fundamental of structured programming in C++. The lecture covers topics such as programs and programming languages, variables, operators, punctuation, syntax, and examples. The document introduces the Benha university's computer science department lecture.

Full Transcript

Fundamental Of Structured Programming Lecture 2 By Dr. Naglaa Fathy Lecturer, Computer Science Department, Faculty of computers and artificial intelligence, benha university Lectures References Starting out with C++ F...

Fundamental Of Structured Programming Lecture 2 By Dr. Naglaa Fathy Lecturer, Computer Science Department, Faculty of computers and artificial intelligence, benha university Lectures References Starting out with C++ From Control Structures through Objects TONY GADDIS Ninth Edition. Course Materials All course material will be made available on Fundamental of Structured Programming Google Drive Folder https://drive.google.com/drive/folders/1tPM- 3Xj4whtwlWia_tA0GaZVx_FTvJoC?usp=sharing Assignments Using flowcharts, write an algorithm to read 100 numbers and then display the sum. Assignments Write an algorithm to read three numbers and then display the largest Programs and Programming Languages A program is a set of instructions a computer follows in order to perform a task. A computer program is a set of instructions that tells the computer how to solve a problem or perform a task. these instructions are called an algorithm. A programming language is a special language used to write computer programs. Program A program is a set of instructions given to the computer to execute successive operations that lead to solving specific problems. In general, to solve any problem with the computer we must follow these steps: Analyze the problem. Write an Algorithm. Draw flowchart. Convert the flowchart to the program. Run the program and test the solution. programming as a problem-solving process Define and analyze the problem. What is the input & output? What other information is necessary? Develop an algorithm. What steps must be done? Implement a program. Compile, test, and debug the program. Document and maintain the program. C++ Programming Languages A program can be written in a programming language, such as C++, which is much easier to understand than machine language. What can you do with C++? Gaming Develop computer software Desktop apps Web browsers OS( operating system ) C++ Programming Languages When a C++ program is written, it must be typed into the computer and saved to a file. A text editor, which is similar to a word processing program, is used for this task. The statements written by the programmer are called source code, and the file they are saved in is called the source file. After the source code is saved to a file, the process of translating it to machine language can begin. During the first phase of this process, a program called the preprocessor reads the source code. C++ Programming Languages The preprocessor searches for special lines that begin with the # symbol. These lines contain commands that cause the preprocessor to modify the source code in some way. During the next phase the compiler steps through the preprocessed source code, translating each source code instruction into the appropriate machine language instruction. This process will uncover any syntax errors that may be in the program. Syntax errors are illegal uses of key words, operators, punctuation, and other language elements. If the program is free of syntax errors, the compiler stores the translated machine language instructions, which are called object code, in an object file. Source Code, Object Code, and Executable Code 1. Source code refers to the lines of code that a programmer types into the computer. 2. A file containing source code is called a source file. 3. Object code is the output of a compiler after it translates source code 4. A file containing object code is called an object file. 5. Executable code" refers to the code that can run directly on your computer. This is usually obtained by linking your object code. From a High-Level Program to an Executable File Integrated Development Environments (IDEs) An integrated development environment, or IDE, combines all the tools needed to write, compile, and debug a program into a single software application. Examples are Microsoft Visual C++ What is a Program Made of? What is a Program Made of? Common elements in programming languages: Key Words Programmer-Defined Identifiers Operators Punctuation Syntax Key Words Also known as reserved words Have a special meaning in C++ Can not be used for any other purpose Written in lowercase letter Keywords in the Program 1-1 Programmer-Defined Identifiers Names made up by the programmer Not part of the C++ language Used to represent various things: variables (memory locations), functions, etc. In Program 1-1: hours, rate, and pay. Operators Used to perform operations on data Many types of operators: Arithmetic - ex: +,-,*,/ Assignment – ex: = Some operators in Program1-1: > = * Punctuation Characters that mark the end of a statement, or that separate items in a list In Program 1-1: , and ; Syntax The rules of grammar that must be followed when writing a program Controls the use of key words, operators, programmer-defined symbols, and punctuation What Is a Program Made Of ? Part of learning C++ is learning where to place semicolons and other punctuation symbols. Line, Variables, Lines vs. Statements In a source file, A line is all of the characters entered before a carriage return. Blank lines improve the readability of a program. Here are four sample lines. Line 3 is blank: 1. double num1 = 5, num2, sum; 2. num2 = 12; 3. 4. sum = num1 + num2; Lines vs. Statements In a source file, A statement is an instruction to the computer to perform an action. A statement may contain keywords, operators, programmer-defined identifiers, and punctuation. A statement may fit on one line, or it may occupy multiple lines. Here is a single statement that uses two lines: double num1 = 5, num2, sum; Variables A variable is a named storage location in the computer’s memory for holding a piece of data. To create a variable in a program you must write a variable definition (also called a variable declaration) There are many different types of data, which you will learn about in this course. A variable holds a specific type of data. The variable definition specifies the type of data a variable can hold and the variable name. Example int num1; Double grade ; String name; Input, Processing, and Output Input, Processing, and Output Three steps that a program typically performs: 1) Gather input data: from keyboard from files on disk drives 2) Process the input data 3) Display the results as output: send it to the screen write to a file The Programming Process The programming process consists of several steps, which include design, creation, testing, and debugging activities. define what the program is to do. Visualize the program running on the computer. Use design tools to create a model of the program(Hierarchy charts, flowcharts, pseudocode, etc.) Check the model for logical errors. Write the program source code. Compile the source code. Correct any errors found during compilation. Link the program to create an executable file. Run the program using test data for input. Correct any errors found while running the program. Validate the results of the program. Chapter 2: Introduction to C++ The Parts of a C++ Program // sample C++ program comment #include preprocessor directive using namespace std; which namespace to use int main() beginning of function named main { beginning of block for main cout

Use Quizgecko on...
Browser
Browser