Download presentation
Presentation is loading. Please wait.
Published byGladys Elfrieda Henry Modified over 9 years ago
1
CHAPTER 1: Programming Fundamentals CSEB113 PRINCIPLES of PROGRAMMING by Badariah Solemon 1BS (May 2013)
2
Topics 1.Computer Programs and Programming – Introduction – Why Do Engineering Undergraduates Need to Take Programming Course? 2.Programming Languages – Machine Language ; Assembly Language; High-level Language 3.The C Language – Your first C Program – C Programming Environment 2BS (May 2013)
3
COMPUTER PROGRAMS AND PROGRAMMING Topic 1 3BS (May 2013)
4
Elements of a Computer 4BS (May 2013) Hardware Software 2 2 1 1 3 3 4 4 5 5 2 2 1 1 system software Application software
5
Computer and Software Computers can do a lot of exciting tasks. – However, computers must be given instructions in the form of computer programs before they can perform actions and make decisions. Software/program – a set of instructions stored inside a computer that allows the user to do a particular thing. 5BS (May 2013) Operating Systems Windows 8 Microsoft Word Application Software Utility Programs Disk Cleanup Language Translation Compiler System Software *Complete this list scanf( "%s", astring ); for ( i = 0; i < 10; ++i ) { if ( astring[i] == 'a' ) { printf( "You entered an a!\n" ); } scanf( "%s", astring ); for ( i = 0; i < 10; ++i ) { if ( astring[i] == 'a' ) { printf( "You entered an a!\n" ); } }
6
Computer programs that are embedded into hardware to control its operations. – Example: Telecommunication systems Consumer electronics Missiles and satellite Smart cards Medical equipment (e.g., electronic stetescope) and medical imaging (e.g. MRI, CT) Transportation systems BS (May 2013)6 Embedded Systems sscanf( "%s", astring ); for ( i = 0; i < 10; ++i ) { if ( astring[i] == 'a' ) { printf( "You entered an a!\n" ); } sscanf( "%s", astring ); for ( i = 0; i < 10; ++i ) { if ( astring[i] == 'a' ) { printf( "You entered an a!\n" ); }
7
What is Programming? Computer programming is: – not only about writing computer programs →the iterative process of designing, writing, testing, debugging, and maintaining the source code of computer programs This source code is written in one or more programming languages (such as C, C++, C#, Java, Python, Smalltalk, etc.) – often shortened to programming, scripting, or coding BS (May 2013)7
8
Why Should I Know Programming? “Everybody in this country should learn how to program a computer … because it teaches you how to think” – Steve Jobs BS (May 2013)8 Watch Me Source: http://www.youtube.com/watch?v=sGyH9tBie4M
9
Why Take Programming Course? BS (May 2013)9 Programming is not only for computer science people only. Writing computer programs to solve complicated engineering problems and to control mechanical devices is a basic skill all engineers must master. Introductory programming course isn't trying to teach you to program so that you can be a programmer. Instead, such course just want you to think like programmers because in the future you will run into problems that are too long and complex to do by hand. In those cases, you'll have to use MATLAB or Mapple or mathworks or some other math related application that allows you to solve these problems. Unfortunately, if you can't code your problem into the application, it won't do you any good.
10
PROGRAMMING LANGUAGES Topic 2 10BS (May 2013)
11
What is a Programming Language? 1 Technically, it is an artificial language designed to communicate instructions to, or to control the behavior of a machine, particularly a computer. It is different from our everyday-language (natural language -NL) – NL : Depends on circumstances; the context – one word can have many meaning depending on the situation (e.g., OPERATE) – PL: Very specific (one word means one thing – context free) since to 'talk' to a computer; to instruct a computer; our commands must be 100% clear and correct. 11BS (May 2013)
12
What is a Programming Language? 2 Conceptually, programming language is a framework within which we organize our ideas about data and procedures. – Data: 'objects' or ‘things’ we want to manipulate – Procedures: 'descriptions' or 'rules' or ‘processes’ that define how to manipulate data – Example: A simple program that determine sum of two numbers – Data ? – Procedures? 12BS (May 2013)
13
Types of Programming Languages BS (May 2013)13 1101 0001 1000 0101 1000 0110 0100 1100 0101 1110 0101 1010 1101 0001 1000 0101 1000 0110 0100 1100 0101 1110 0101 1010 LOAD A, 9999 LOAD B, 8282 SUB B MOV C, A LOAD A, 9999 LOAD B, 8282 SUB B MOV C, A printf (“Hello”); total = quiz + assignment; printf(“Total = %d”, total); printf (“Hello”); total = quiz + assignment; printf(“Total = %d”, total); Machine Language High-Level Language Assembly Language
14
1. Machine Language The only language that is directly understandable by a computer’s processor. – Certainly difficult for humans to understand Consists of binary codes: 0 and 1. Example: is the language into which all programs must be converted before they can be run is generally machine dependent, as it varies from processor to processor (e.g., Intel, AMD and ARM processors) is NOT portable – program may sometimes have to be completely rewritten to work on different type of processors Programming in machine language is very slow and tedious since it is hard to memorize all the instructions and mistakes can happen very easily 14BS (May 2013) 1101 0001 1000 0101 1000 0110 1111 0001 0100 1100 0101 1110 0101 1010 0001 1100 1101 0001 1000 0101 1000 0110 1111 0001 0100 1100 0101 1110 0101 1010 0001 1100
15
2. Assembly Language Uses a mnemonic code to represent each machine operation – in words and numbers An intermediary language that can be understood by humans – but is still quite difficult to use Cannot be processed directly by a computer, must be converted to machine language using assemblers Although easier to use than machine language, programmer is required to have a complete understanding of the computer hardware in order to program it. To do simple tasks such as printing out a message, programmer needs to write a substantial amount of code. Processor dependent and not portable. 15BS (May 2013) LOAD A, 9999 LOAD B, 8282 SUB B MOV C, A LOAD A, 9999 LOAD B, 8282 SUB B MOV C, A 00000000 00010101 00010110 00110101 01110111 Assembler
16
3. High-level Languages 1 Use more English words so easier to program in these languages. Example: The programming structure is problem oriented – does not need to know how the computer actually executes the instructions. Processor independent - the same code can be run on different processors. Programs written in these languages must be translated into executable machine language using – Compilers – translate instructions to create executable form – Interpreters – translate and execute instructions one after another 16BS (May 2013) printf (“Hello”); total = quiz + test + assignment; printf (“Hello”); total = quiz + test + assignment;
17
3. High-level Languages 2 Example: All have set of rules called syntax – must be followed – describe the form of a valid program and to get an accurate translation into machine language 17BS (May 2013) C PHPRubyAda JavaVisual BasicVisual Basic.NETMATLAB Objective-CPythonLISPLua C++PerlPascalBash C#JavascriptDelphiFORTRAN
18
THE C LANGUAGE Topic 3 18BS (May 2013)
19
The C Language 1 It was developed by Dennis Ritchie in the early 1970s at Bell Laboratories (now a part of Lucent Technologies, Inc). A high-level language that is highly portable. C combines the power of high-level languages with the power of assembly languages. It has influenced the newly created high-level language name Objective-C – which is the main programming language used by Apple for the OS X and iOS operating systems and their respective APIs, Cocoa and Cocoa Touch frameworks. 19BS (May 2013)
20
The C Language 2 C is a highly imperative programming language. This means: – It expresses what the program should accomplish by prescribing how to do it in terms of sequences of actions to be taken. – It was designed to be compiled using a relatively straightforward compiler. The language has become available on a very wide range of platforms, from embedded microcontrollers to supercomputers. 20BS (May 2013)
21
Your First C Program A C program (also called C source code): It must be translated into machine language. Once the machine language is executed, the program produces an output: BS (May 2013)21 /********************************************************** Author: Badariah Solemon Date: 01/01/2013 Description: A program that prints the famous “Hello World” message on the computer screen **********************************************************/ #include void main (void) { printf(“****************\n”); printf(“ Hello World\n”); printf(“****************\n”); } **************** Hello World ****************
22
C Programming Environment A modern C programming often made easy by the use of integrated development environments (IDEs). IDEs that support C language include Microsoft Visual Studio, Eclipse, and etc. Ms Visual Studio 2010 Express or Ms Visual Studio Express 2012 is free! – Highly recommended for your personal use – You must register to obtain a free product key for ongoing use BS (May 2013)22
23
Visual Studio C++ Express BS (May 2013)23
24
Summary Computers must be given instructions in the form of computer programs before they can perform actions and make decisions. Programming is the iterative process of designing, writing, testing, debugging, and maintaining the source code of computer programs. Conceptually, programming language is a framework within which we organize our ideas about data (object we want to manipulate) and procedures (how to manipulate the data). In general, programming languages may be categorized as 1) machine language (also called machine code), 2) assembly language, and 3) high- level languages. C is a highly imperative programming language. A modern C programming often made easy by the use of integrated development environments (IDEs). BS (May 2013)24
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.