CS 101 INTRODUCTION TO PROGRAMMING REFERCENCE WWW NETACAD

  • Slides: 42
Download presentation
CS 101 INTRODUCTION TO PROGRAMMING REFERCENCE: WWW. NETACAD. COMPUTER SCIENCE DEPARTMENT JORDAN UNIVERSITY OF

CS 101 INTRODUCTION TO PROGRAMMING REFERCENCE: WWW. NETACAD. COMPUTER SCIENCE DEPARTMENT JORDAN UNIVERSITY OF SCIENCE AND TECHNOLOGY REFERCENCE: WWW. NETACAD. COM

www. netacad. com REFERCENCE: WWW. NETACAD. COM

www. netacad. com REFERCENCE: WWW. NETACAD. COM

To start: REFERCENCE: WWW. NETACAD. COM

To start: REFERCENCE: WWW. NETACAD. COM

CS 101 CS 112 REFERCENCE: WWW. NETACAD. COM

CS 101 CS 112 REFERCENCE: WWW. NETACAD. COM

Categories of Computers Super Computers Mainframe computers Midsize computers personal computers Embedded computers C++

Categories of Computers Super Computers Mainframe computers Midsize computers personal computers Embedded computers C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN, THIRD EDITION 5

Elements of a Computer System 1. ◦ ◦ 2. Hardware Central Processing Unit (CPU)

Elements of a Computer System 1. ◦ ◦ 2. Hardware Central Processing Unit (CPU) Main Memory Secondary Storage Input/ Output Devices Software C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN, THIRD EDITION 6

Central Processing Unit (CPU) The main components of the CPU are: 1. Control unit

Central Processing Unit (CPU) The main components of the CPU are: 1. Control unit (CU) 2. Arithmetic and logic unit (ALU). 3. Registers. C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN, THIRD EDITION 8

Central Processing Unit (CPU) 1. CU (Control Unit): ◦ Fetches and decodes instructions ◦

Central Processing Unit (CPU) 1. CU (Control Unit): ◦ Fetches and decodes instructions ◦ Controls flow of information in and out of MM ◦ Controls operation of internal CPU components 2. ALU (arithmetic logic unit): carries out all arithmetic and logical operations C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN, THIRD EDITION 9

Central Processing Unit (CPU) 3. Registers. 1. PC (program counter): points to next instruction

Central Processing Unit (CPU) 3. Registers. 1. PC (program counter): points to next instruction to be executed 2. IR (instruction register): holds instruction currently being executed C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN, THIRD EDITION 10

Main Memory Directly connected to the CPU All programs must be loaded into main

Main Memory Directly connected to the CPU All programs must be loaded into main memory before they can be executed All data must be brought into main memory before it can be manipulated When computer power is turned off, everything in main memory is lost C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN, THIRD EDITION 11

Secondary Storage Secondary storage: Device that stores information permanently Examples of secondary storage: ◦

Secondary Storage Secondary storage: Device that stores information permanently Examples of secondary storage: ◦ Hard disks ◦ Floppy disks ◦ Zip disks ◦ CD-ROMs ◦ Tapes ◦ Flash drives C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN, THIRD EDITION 13

Input/output Devices Input devices feed data and programs into computers. They include: ◦ Keyboard

Input/output Devices Input devices feed data and programs into computers. They include: ◦ Keyboard ◦ Mouse ◦ Secondary storage Output devices display results. They include: ◦ Monitor ◦ Printer ◦ Secondary storage C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN, THIRD EDITION 14

Software: Programs that do specific tasks 1. System programs take control of the computer,

Software: Programs that do specific tasks 1. System programs take control of the computer, such as an operating system Operating System monitors the overall activity of the computer and provides services. 2. Application programs perform a specific task ◦ Word processors ◦ Spreadsheets ◦ Games Software usullay witten using a programming language. 15

1. 1 Natural language vs. programming language REFERENCE: WWW. NETACAD. COM 16

1. 1 Natural language vs. programming language REFERENCE: WWW. NETACAD. COM 16

1. 1 Natural language vs. programming language What is a language? ◦ a language

1. 1 Natural language vs. programming language What is a language? ◦ a language is a tool for expressing and recording human thoughts What is a programming language? ◦ A programming language is defined by a certain set of rigid rules, these rules determine which symbols (letters, digits, punctuation marks, and so on) could be used in the language REFERENCE: WWW. NETACAD. COM 17

1. 1 Natural language vs. programming language Any programming language consists of: ◦ Syntax:

1. 1 Natural language vs. programming language Any programming language consists of: ◦ Syntax: is a set of rules determines the appropriate ways of collating the symbols ◦ Semantic: the ability to recognize the meaning of every statement expressed in the given language Any program we write must be error-free in these three ways: lexically, syntactically and semantically, otherwise, the program won’t run, or it will produce unacceptable results REFERENCE: WWW. NETACAD. COM 18

1. 1 Natural language vs. programming language Why we need to use a programming

1. 1 Natural language vs. programming language Why we need to use a programming language? ◦ The machine language is the simplest and the most primary language we can use to give commands to our computer (very difficult to understand for humans) ◦ A high-level programming language is a bridge between the people's language (natural language) and computer language (machine language) ◦ A high-level programming language is similar to a natural language: it uses symbols, words and conventions readable to humans. ◦ High-level languages include Basic, FORTRAN, COBOL, Pascal, C, C++, C#, and Java REFERENCE: WWW. NETACAD. COM 19

The Language of a Computer Digital signals are sequences of 0 s and 1

The Language of a Computer Digital signals are sequences of 0 s and 1 s Machine language: language of a computer Binary digit (bit): ◦ The digit 0 or 1 Binary code: ◦ A sequence of 0 s and 1 s Byte: ◦ A sequence of eight bits C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN, THIRD EDITION 20

Programming Language Evolution Early computers were programmed in machine language To calculate wages =

Programming Language Evolution Early computers were programmed in machine language To calculate wages = rates * hours in machine language: 10010001 //Load 100110 010010 //Multiply 100010 010011 //Store C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN, THIRD EDITION 22

Assembly Language Assembly language instructions are mnemonic. Mnemonic (easy-to-remember). Assembler: translates a program written

Assembly Language Assembly language instructions are mnemonic. Mnemonic (easy-to-remember). Assembler: translates a program written in assembly language into machine language C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN, THIRD EDITION 23

High-Level Languages High-level languages include Basic, FORTRAN, COBOL, Pascal, C++, C, and Java Compiler:

High-Level Languages High-level languages include Basic, FORTRAN, COBOL, Pascal, C++, C, and Java Compiler: translates a program written in a high-level language machine language The equation wages = rate • hours can be written in C++ as: wages = rate * hours; C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN, THIRD EDITION 24

Processing a C++ Program #include <iostream> using namespace std; int main() { cout <<

Processing a C++ Program #include <iostream> using namespace std; int main() { cout << "My first C++ program. " << endl; return 0; } Sample Run: My first C++ program. C++ Programming: From Problem Analysis to Program Design, Fifth Edition REFERENCE: WWW. NETACAD. COM 25

Chapter 0 INSTALLING AND USING YOUR PROGRAMMING ENVIRONMENT REFERCENCE: WWW. NETACAD. COM

Chapter 0 INSTALLING AND USING YOUR PROGRAMMING ENVIRONMENT REFERCENCE: WWW. NETACAD. COM

Creating your work environment: Where to write your code? ◦ Paper and a pencil!!

Creating your work environment: Where to write your code? ◦ Paper and a pencil!! Its good for first draft ◦ You requires a computer equipped with some additional tools. REFERCENCE: WWW. NETACAD. COM

Processing a C++ Program (cont'd. ) To execute a C++ program: ◦ Use an

Processing a C++ Program (cont'd. ) To execute a C++ program: ◦ Use an editor to create a source program in C++ ◦ Preprocessor directives begin with # and are processed by the preprocessor. (A set of preliminary information that the compiler needs is included in header files such iostream header file) ◦ Use the compiler to: ◦ Check that the program obeys the rules ◦ Translate into machine language (object program) ◦ Linker: ◦ Combines object program with other programs provided by the SDK to create executable code ◦ Loader: ◦ Loads executable program into main memory ◦ The last step is to execute the program C++ Programming: From Problem Analysis to Program Design, Fifth Edition REFERENCE: WWW. NETACAD. COM 28

Processing a C++ Program (cont'd. ) C++ Programming: From Problem Analysis to Program Design,

Processing a C++ Program (cont'd. ) C++ Programming: From Problem Analysis to Program Design, Fifth Edition REFERENCE: WWW. NETACAD. COM 29

What is IDE? REFERCENCE: WWW. NETACAD. COM

What is IDE? REFERCENCE: WWW. NETACAD. COM

What is IDE? IDE (Integrated Development Environment) is a software application that typically consists

What is IDE? IDE (Integrated Development Environment) is a software application that typically consists of a code editor, a compiler, a debugger, and a graphical user interface (GUI) builder. Programming with an IDE gives you a toolkit containing everything you may need. However, they may consume a lot of resources and, you probably don’t need most of the functions they can perform. REFERCENCE: WWW. NETACAD. COM

Using on-line tools allows you to write, store and run your code without installing

Using on-line tools allows you to write, store and run your code without installing anything REFERCENCE: WWW. NETACAD. COM

Choose your IDE There are many IDEs on the market, both free and not

Choose your IDE There are many IDEs on the market, both free and not free We wrote and tested all our examples with Net. Beans. REFERCENCE: WWW. NETACAD. COM

Choose your IDE Microsoft © Visual Studio Express ® (Now changed to: Visual Studio

Choose your IDE Microsoft © Visual Studio Express ® (Now changed to: Visual Studio Community) A single-platform development environment designed especially for building C++ programs, both under and for the MS Windows operating system. Now it has even multi-platform support: ◦ Runs on Windows and Mac. OS to develop applications for Android, i. OS, Windows, web, and cloud. home site: https: //www. visualstudio. com REFERCENCE: WWW. NETACAD. COM

Choose your IDE Eclipse Multi-platform development environment designed especially for Java. C++ programming possible

Choose your IDE Eclipse Multi-platform development environment designed especially for Java. C++ programming possible without additional configuration (dedicated C++ version available for download). home site: https: //eclipse. org downloads: https: //www. eclipse. org/downloads license: Eclipse Public License (free and open) REFERCENCE: WWW. NETACAD. COM

Choose your IDE Net. Beans Multi-platform development environment designed especially for Java. C++ programming

Choose your IDE Net. Beans Multi-platform development environment designed especially for Java. C++ programming possible without additional configuration (dedicated C++ version available for download). home site: https: //netbeans. org downloads: https: //netbeans. org/downloads/index. html license: Common Development and Distribution License or GNU Public License version 2 (free and open) REFERCENCE: WWW. NETACAD. COM

Choose your IDE Code: : Blocks Multi-platform development environment designed for C/C++ programming. Default

Choose your IDE Code: : Blocks Multi-platform development environment designed for C/C++ programming. Default Windows installer does not include C++ compiler - use the one containing “mingw-setup” inside the file name instead. home site: http: //www. codeblocks. org downloads: http: //www. codeblocks. org/downloads/binaries license: GNU Public License version 3 (free and open) REFERCENCE: WWW. NETACAD. COM

Choose your IDE XCode Single-platform development environment designed especially for building applications for operating

Choose your IDE XCode Single-platform development environment designed especially for building applications for operating systems designed by Apple Inc. Programming in C++ fully available. home site: https: //developer. apple. com/xcode downloads: https: //developer. apple. com/xcode/download license: proprietary but free for Max OS X users; integrated with OS X and preinstalled. REFERCENCE: WWW. NETACAD. COM

 On-line tools: ideone REFERCENCE: WWW. NETACAD. COM

On-line tools: ideone REFERCENCE: WWW. NETACAD. COM

 On-line tools: ideone The first one is a tool named ideone available at

On-line tools: ideone The first one is a tool named ideone available at http: //ideone. com. ◦ Although you don’t need to register to start your work, we suggest that you do – it’ll enable some additional, valuable features. After signing in, you’ll have to do some customizing, and two things are essential: ◦ change your default programming language to “C++” (don't forget to do that) ◦ enable syntax highlighting – it’ll make it easier to do your work. For help: ◦ Check http: //ideone. com/faq for more details. REFERCENCE: WWW. NETACAD. COM

 On-line tools: ideone To test the ideone environment, go to the “new code”

On-line tools: ideone To test the ideone environment, go to the “new code” tab and just copy-and-paste the following text into the source code field: #include <iostream> using namespace std; int main(void) { cout << "It's working" << endl; return 0; } REFERCENCE: WWW. NETACAD. COM

On-line tools: cpp. sh Another on-line tool with very similar functionality is C++ shell,

On-line tools: cpp. sh Another on-line tool with very similar functionality is C++ shell, available at http: //cpp. sh. You don’t need to register and its principle operation is very similar to ideone, although C++ shell doesn't offer as many useful features as ideone (e. g. you can neither save nor publish your code). It also doesn't include any support (to tell you the truth, it’s so simple to use that you actually don’t need any help). Now it's time to start learning some real programming. Let us go to chapter 1 REFERCENCE: WWW. NETACAD. COM