1 / 35

CGS 3460 PROGRAMMING USING C

CGS 3460 PROGRAMMING USING C. Spring 2007 Instructor: Rong Zhang TAs: Ting Chen and Sungwook Moon. Goals. We will learn Read: Understand programs written in C language Write: Design and implement programs using C language

felicity
Download Presentation

CGS 3460 PROGRAMMING USING C

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. CGS 3460 PROGRAMMING USING C Spring 2007 Instructor: Rong Zhang TAs: Ting Chen and Sungwook Moon

  2. Goals • We will learn • Read: Understand programs written in C language • Write: Design and implement programs using C language • Compile: Use compiler to convert C code into executable file under UNIX • Execute: Run corresponding code to get results • Debug: Identify and fix syntax and semantic errors in C code. • Appropriate for • Technically oriented people with little or no programming experience • Experienced programmers who want a deep and rigorous treatment of the language

  3. New View of Computers • From a programmer’s viewpoint • Computers are tools • A computer program turns raw data into meaningful information • A program is the driving force behind any job that any computer does • A program is a list of detailed instructions • These instructions are written in certain programming language

  4. Available Programming Languages • Machine Languages • Assembly Languages • High-level Languages • C/C++ • COBOL • Pascal • BASIC • Fortran • JAVA • Etc.

  5. Machine Languages • System of instructions and data directly understandable by a computer's central processing unit. • Example: 100011 00011 01000 00000 00001 000100 000010 00000 00000 00000 10000 000001 000000 00001 00010 00110 00000 100000 • Every CPU model has its own machine code, or instruction set, although there is considerable overlap between some

  6. Assembly Languages • Human-readable notation for the machine language that a specific computer architecture uses representing elementary computer operations (translated via assemblers) • Example: load hourlyRate mul workHours store salary • Even into the 1990s, the majority of console video games were written in assembly language.

  7. High-level Languages • Higher level of abstraction from machine language • Codes similar to everyday English • Use mathematical notations (translated via compilers) • Example: salary = hourlyRate * workHours • Make complex programming simpler

  8. Why Programming using C • Initial development occurred at Bell Labs in early 70’s by Ritchie • General-purpose computer programming language • high-level assembly • Simplicity and efficiency of the code • The most widely used programming languages • Commonly used for writing system software • Widely used for writing applications • Hardware independent (portable) • Great influence on many other popular languages

  9. Textbooks • Required Programming in C (3rd Edition) by Stephen Kochan. ISBN: 0672326663. Link for the book from amazon: http://www.amazon.com/gp/product/0672326663 • Recommended Reading Absolute Beginner's Guide to C by Greg Perry. ISBN: 0672305100. Link http://www.amazon.com/gp/product/0672305100

  10. Outline of the Course – I • Introductions • Familiarization with programming environment, telnet / SSH Secure Shell, ftp / SSH Secure File Transfer, UNIX, Compiling / gcc • C program structure • Basic data types and variables declaration • Arithmetic expressions and operators • Control statements. • Conditional statements • The while loop • The do while loop • The for loop • The if else statement • The switch statement • The break statement • The continue statement

  11. Outline of the Course – II • Formatted Input and Output • Arrays and Strings • Functions • Declarations • Calling • Pointers • Struct, Union, Enums • Preprocessor • * Advanced Material • Debug using gdb • Arrays and Pointer Arithmetic • Binary Trees • Link Lists • Recursive Functions * may be adjusted according to time and interests of students

  12. Grading Scale • You earn your grade • Final grade is calculated according to the following schedule Home works 30% Quizzes 20% Mid-term exam 20% Final exam / Project 30% • Grade scale is: A(100-90),B+(89-85),B(84-80),C+(79-75), C(74-70),D+(69-65),D(64-60),F(59-0)

  13. Policies • Attendance and Expectations • Homework Policies • Make-up Exam Policy • Other Policies • Re-grading • Course is on WebCT http://lss.at.ufl.edu/services/webct/

  14. History - I • The first freely programmable binary computer • Konrad Zuse's in Germany • Innovations • Floating-point arithmetic • High-capacity memory • Modules or relays operating on the yes/no principle. Konrad Zuse's Z1 Circa 1936 From http://inventors.about.com/library/blcoindex.htm

  15. History - II • The first electronic-digital computer • Iowa State University • Innovations • A binary system of arithmetic • Parallel processing • Regenerative memory • Separation of memory and computing functions Atanasoff-Berry Computer From http://inventors.about.com/library/blcoindex.htm

  16. History- III • ENIAC I (Electrical Numerical Integrator And Calculator) • John Mauchly and J Presper Eckert • 500,000 dollars • Thousand times faster • 17,468 vacuum tubes • 70,000 resistors • 10,000 capacitors, etc • 800 square feet floor space • 30 tons • 160 kilowatts of electrical power The ENIAC 1946 From http://inventors.about.com/library/blcoindex.htm

  17. History- IV • First home computer • Scelbi  • Mark-8 Altair • IBM 5100 Computers • 1974/1975 • Altair • 8080 CPU • 256 Byte RAM card • $400 • The consumer needs to put them together, make it work and write any needed software. • Paul Allen and Bill Gates develop BASIC for the Altair 8800 Mark-8 Altair From http://inventors.about.com/library/blcoindex.htm

  18. History- V • Personal computer • IBM PC in 1981 • Apple Macintosh in 1984 • Microsoft Windows 1.0 ships in November, 1985 • Network original IBM PC 1981 http://www.pbs.org/nerds/timeline/

  19. Operating System • What is OS? • A program that allows you to interact with the computer -- all of the software and hardware • With a command-line operating system (e.g., DOS) • With a graphical user interface (GUI) operating system (e.g., Windows) • Two major classes of operating systems • Windows • Nice interface, easy to learn • Unix • reliable timesharing operating system

  20. Why we choose UNIX • Powerful • Multi-user operating system • Good programming tools • Most heavy-duty database management systems started out on Unix • Flexible   • Thousands of tools that can be combined and recombined. • Reliable • Unix is hard to crash.

  21. Your personal computer (client) grove.ufl.edu (server) How to Access a UNIX Machine telnet / ftp telnet: allows you to connect to other computers and use softwares there ftp: allows you to retrieve files from other computers.

  22. Telnet • TELetype NETwork • A network protocol used on the Internet / LAN • By extension, refers to the program which provides the client part of the protocol • Once connected • Log on as a regular user with access to • application / software • data • A Telnet command request looks like this • telnet grove.ufl.edu

  23. FTP • File Transfer Protocol • A network protocol used on the Internet / LAN • Allow to transfer files to and from remote computers • A ftp command request looks like this • ftp grove.ufl.edu

  24. SSH • Why SSH • Download SSH • http://www.openssh.org/ Figures from http://www.suso.org/docs/shell/ssh.sdf

  25. More about SSH • Recommendation for Windows • Putty as telnet tool • http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html • WinSCP as ftp tool • http://winscp.net/eng/download.php • Other choices • ftp, telnet using command line in windows • Other softwares • Core FTP http://www.coreftp.com/download.html

  26. Your First Program Preprocessor: interactwith input/output of your computer #include <stdio.h> int main() { printf("Hello World\n"); return 0; } You will see this at the beginning of nearly all programs Tells computer to load file named <stdio.h> <stdio.h> allows standard input/output operations

  27. Your First Program Preprocessor: interactwith input/output of your computer #include <stdio.h> int main() { printf("Hello World\n"); return 0; } Start point of the program • C programs contain one or more functions, exactly one of which must be main • int means that the function main will "return" an integer value

  28. Your First Program Preprocessor: interactwith input/output of your computer #include <stdio.h> int main() { printf("Hello World\n"); return 0; } Start point of the program Start and finish of function

  29. Your First Program Preprocessor: interactwith input/output of your computer #include <stdio.h> int main() { printf("Hello World\n"); return 0; } Start point of the program Start and finish of function Printing a line of Text

  30. New line character Your First Program Preprocessor: interactwith input/output of your computer #include <stdio.h> int main() { printf("Hello World\n"); return 0; } Start point of the program Start and finish of function Printing a line of Text

  31. Your First Program Preprocessor: interact with input/output of your computer #include <stdio.h> int main() { printf("Hello World\n"); return 0; } Start point of the program Start and finish of function Printing a line of Text Finish and return value 0 • A way to exit a function • It means that the program terminated normally in this case

  32. Comments for programs • Why need comments • Good habit • Readable to others • Remind yourself • How to comment • /* … */ • // … • Effects on compiler • Examples

  33. Compiler • What is compiler • A computer program (or set of programs) that translates text written in a computer language ( the source code) into another computer language (most time the executable file) • Why we need a compiler • Available C compiler in UNIX system: gcc gcc sourcefile.c –o exefile.exe

  34. Text Editor in UNIX • Edit your code Using wordpad, MS word on your personal computer • Need to transfer your program to UNIX machine using ftp • Edit your code in UNIX using • vi • pico • emacs

  35. helloworld.c #include <stdio.h> int main() { printf("Hello World\n"); return 0; } C-compiler helloworld.exe 0011 0000 1010 0110 1100 0110 1011 0101 1010 1110 0110 1110 Procedure This is your C program. Type the code in any standard text editor, and save it as helloworld.c. Transfer it to grove.ufl.edu if necessary Type gcc helloworld.c –o helloworld.exe to compile helloworld.c into helloworld.exe using the gcc compiler The gcc compiler generate corresponding executable code named helloworld.exe. The computer can execute this machine readable code if you type ./helloworld.exe

More Related