1 / 18

Agenda

Agenda. Computer Languages Machine Language High-Level Programming Language Features of C Programming Language How to Write a Simple C Program How to Record a C Program (typescript). Computer Programs. A program is a set of instructions to tell the computer what to do.

fabian
Download Presentation

Agenda

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. Agenda • Computer Languages • Machine Language • High-Level Programming Language • Features of C Programming Language • How to Write a Simple C Program • How to Record a C Program (typescript)

  2. Computer Programs • A program is a set of instructions to tell the computer what to do. • In order to better understand the programming process, we will first see how computer programs have developed over the past 50 years.

  3. Computers • Computers are electronic devices that transfer and store data in wires (or gates). • Because the computer is an electronic device, the data within these wires or gates are either ON or OFF (like a light switch). • A collection of these ON and OFF combinations are used to represent data in the form of binary code(eg 010100001010111 )

  4. Evolution of Programs • Early programmers needed to write programs using binary code or “machine language” to tell the computer to perform various tasks • Although the computer finds machine code efficient to perform tasks, early programmers found writing programs in machine code tedious and time-consuming.

  5. Evolution of Programs • Grace Hopper, while working for the U.S. Navy in the 50’s developed a program to convert programs written in symbols to machine language - this was more convenient than writing a program using machine language. • This program used symbols to represent operations. Unfortunately, these programs didn’t work on all computers

  6. Evolution of Programs • High-level languages were developed to allow the program to be run on many different computer systems. These “high-level” languages are considered “portable” programming languages since they can run on many different computers. • The programs are written in a form easily understood by the programmers (source code) and then a “compiler” program converts the source code into machine code to be run by the computer. • Examples of high-level languages: FORTRAN, COBOL & C

  7. C Programming Language • The C programming language was developed by Dennis Ritchie at Bell AT&T labs in the early 1970s. • Dennis Ritchie and Ken Thompson used the C programming language to rewrite the UNIX operating system in 1973. • This contributed to the portability and popularity of C as UNIX operating system became widely accepted.

  8. Features of C Programming Language • C is portable (can write and compile C programs on many different computer systems without major adjustments) • C is powerful, but also efficient. • C conforms to the ASNI standard for programming languages • C provides the basis for more complex programming languages such as C++

  9. Steps to Create a Program • Step 1: Determine the requirements for the program (inputs, outputs, formulas) • Step 2: Plan out on paper the logic of the program (flowchart, pseudo code) • Step 3: Use Text editor to enter program (Source Code) • Step 4: Walk through program’s logic and syntax (look for errors) • Step 5: Compile the source code into an executable file • Step 6: Run the executable file & test the program’s logic as much as possible.

  10. Debugging a Program • Debugging a program is the process of finding and removing errors from your program if it fails to compile or run properly • The compiler will NOT create an executable file if the source code contains syntax errors (but compiler will give error messages to help solve problem) • If you can compile your source code, errors can still occur due to improper logic, structure, or design approach.

  11. Writing a Simple C Program Indicates to include a file that provides “standard input / output” functions (printf, scanf) which will be linked when source file is compiled • #include <stdio.h> • main () • { • printf (“Hello World!\n”); • }

  12. Writing a Simple C Program • #include <stdio.h> • main () • { • printf (“Hello World!\n”); • } Indicates main function or “main part” of the program. All C programs have one main function. Note alllowercase. Syntax may also allow:main (void)int main (void)

  13. Writing a Simple C Program • #include <stdio.h> • main () • { • printf (“Hello World!\n”); • } Notice braces follow the main function. Other functions or commands are placed within these brackets to be executed when main function is run or “called” begin end

  14. Writing a Simple C Program • #include <stdio.h> • main () • { • printf (“Hello World!\n”); • } Notice how commands within braces are indented to “stand-out”. This allows programmers to be able to easily read code. Indenting is very important!

  15. Writing a Simple C Program • #include <stdio.h> • main () • { • printf (“Hello World!\n”); • } The printf command allows the display of output to be formatted: Some special codes include:\n - new line\t - tab (indent)\a - beep (alarm) Note: lowercase

  16. Writing a Simple C Program • #include <stdio.h> • main () • { • printf (“Hello World!\n”); • } Most C commands end with a semi-colon.

  17. Writing a Simple C Program • Task: • Write a C program to display the following information on a separate line: • Your name • Your student number • Your section • Tell us about yourself

  18. Typescript • The script command in the Unix operating system is like a “tape recorder”: • Entering command script starts recording • all output on screen is saved to a file called typescript • Entering command exit stops recording • Refer to Assignment #0 for practice of printing out - Assignment is not for marks.

More Related