Presentation is loading. Please wait.

Presentation is loading. Please wait.

12/06/2016 03:04:41 CSC Alliance — 1 Kimera Richard Phone: 0701 437989 INSTITUTE OF COMPUTER SCIENCE DEPARTMENT.

Similar presentations


Presentation on theme: "12/06/2016 03:04:41 CSC Alliance — 1 Kimera Richard Phone: 0701 437989 INSTITUTE OF COMPUTER SCIENCE DEPARTMENT."— Presentation transcript:

1 12/06/2016 03:04:41 CSC Alliance — 1 Kimera Richard E-mail: rkimera@must.ac.ugrkimera@must.ac.ug Phone: 0701 437989 INSTITUTE OF COMPUTER SCIENCE DEPARTMENT OF INFORMATION SYSTEMS AND TECHNOLOGY Kimera Richard E-mail: rkimera@must.ac.ugrkimera@must.ac.ug Phone: 0701 437989 INSTITUTE OF COMPUTER SCIENCE DEPARTMENT OF INFORMATION SYSTEMS AND TECHNOLOGY COMPUTER PROGRAMMING IN C MTH2209 FRIDAY 27 th Feb 2015 http://kimrichies.blogspot.com

2 MUST- ICS rkimera@must.ac.ug The Ground Rules  Teaching will take place between 8:00am and 11:00 am every Friday in Semester 2.  If a Lecture must be postponed or cancelled you will be informed by a notice on one of the notice boards, blog or E-learning system  Lectures will begin at 8.10 am prompt, please arrive by 8:00am to ensure you have a seat and are settled.  After 08.10am access to the Lecture will be refused.  In the event of the Lab being opened late, the Lecture will start 10 minutes after the opening of the Lab and entry will be refused after this time has elapsed.

3 MUST- ICS rkimera@must.ac.ug The Ground Rules  All PC’s will remain turned OFF unless you are otherwise requested to carry out research.  All Mobile phones must be turned off or on silent. No phone should be answered during the Lecture, if it is it will be confiscated and returned to the owner at the End of the Working Day.  Students will have to carry out additional reading in and around the Subjects covered as the Lecturer cannot guarantee the exact content covered in Lectures will be examined.

4 MUST- ICS rkimera@must.ac.ug The Ground Rules  Ask Questions  Show Initiative  All of the Content covered in Lectures with either be on slides, books or written on the White Board  Don’t aim at just passing exams but also your future

5 MUST- ICS rkimera@must.ac.ug Course works  Tests: Two or more tests will be done in the semester  Assignments: 2 or more assignments will be given.  Similar/duplication of Course works is highly prohibited and this will lead to no mark by the concerned parties.  Time is a crucial factor for course works  Always report to the class president if u are to miss any coursework and the president should inform the lecturer before the end of the lecture  Hand in on time and verify that your marks exist before its too late

6 MUST- ICS rkimera@must.ac.ug Examinations  You only qualify to do an exam if you have attended 70% of the lectures and done all the coursework's  If you fail the exam (<50%), you will be required to do a supplementary in August 2015  Failing a Supplementary calls for a repeat of the failed course Unit in 2015, NOT a retake

7 MUST- ICS rkimera@must.ac.ug Generally  Practice, practice, practice..  Pre-requisite: Computer usage  Consultations: I will be available for consultations every Tuesday 12:00PM – 1:00PM  Notes and Support: We will be using a book called “Sams, Teach yourself C in 21 days” in combination with other books. More support can be accessed on the LMS: http://lms.must.ac.ug and the blog: http://kimrichies.blogspot.comhttp://lms.must.ac.ughttp://kimrichies.blogspot.com  Once marks are given, they can not be changed.

8 MUST- ICS rkimera@must.ac.ug Introduction – Course Objectives By the end of this course, students should have knowledge on;  Knowledge about the various programming languages  Knowledge and skills in programming.  Knowledge in planning and organization of programming projects  Techniques of evaluating syntactic and semantic correctness of a computer program

9 MUST- ICS rkimera@must.ac.ug Introduction: Course Outline  Introduction to Programming  Program Structure  Data types  Variables and operators  Conditional Statements  Looping Statements  Arrays and strings  Functions  Pointers  Structures  Working with files

10 MUST- ICS rkimera@must.ac.ug Evaluation  Cousework (30%)  Assignments and class participation (15%)  Tests (15%)  Exam (70%)

11 MUST- ICS rkimera@must.ac.ug Reference Materials and Books  C- by Example  Teach yourself C in 21 days  Behrouz A. Forouzan and Richard F. Gilberg.Computer Science: A Structured Programming Approach Using C. Third Edition, Cengage Learning, February, 2006Behrouz A. ForouzanRichard F. Gilberg  Dan Gookin.C For Dummies. First Edition, For Dummies,April, 1997 Dan Gookin  K. N. King and K.N. King.C Programming: A Modern Approach. W W Norton & Co Inc, February 1996 K. N. King  Greg M. Perry. C Programming in 12 Easy Lessons Prentice Hall, January 1994 Greg M. Perry

12 12/06/2016 03:04:41 CSC Alliance — 12 Kimera Richard E-mail: rkimera@must.ac.ugrkimera@must.ac.ug Phone: 0701 437989 INSTITUTE OF COMPUTER SCIENCE DEPARTMENT OF INFORMATION SYSTEMS AND TECHNOLOGY Kimera Richard E-mail: rkimera@must.ac.ugrkimera@must.ac.ug Phone: 0701 437989 INSTITUTE OF COMPUTER SCIENCE DEPARTMENT OF INFORMATION SYSTEMS AND TECHNOLOGY Introduction to Structured Programming(C) This lecture has major focus on programming, compilation and some key concepts

13 MUST- ICS rkimera@must.ac.ug What is a program  A sequence of instructions that a computer can interpret and execute;  If I tell you the way from FoS to Administration Block … I will tell sequence of instructions…. Any wrong instruction leads to a undesired result.  A program is something that runs on your computer. In case of MS Windows program is of.EXE or.COM extensions  MS Word, Power point, Excel are all computer programs

14 MUST- ICS rkimera@must.ac.ug Why we need programming language(s)  Writing machine language code is very difficult if not impossible  Standard manner to type instructions on computers  Why standard? >  If there was no such standard then everyone would have to write his/her own compiler…. Or use machine language  One problem with using machine language is the machine language expert of one machine cannot be an expert of other machine as both machines might have totally different architectures and calls  Another use is that makers of programming language often supply us with pre-built functions that help us save time (hence money )

15 MUST- ICS rkimera@must.ac.ug Evolution of programming languages  The lack of portability between different computers led to the development of high-level languages—so called because they permitted a programmer to ignore many low-level details of the computer's hardware

16 MUST- ICS rkimera@must.ac.ug How people used to program  Machine Language….. Damn! It was difficult  Assembly Language…. Remember ADD?  Required too much user involvement  To much to remember  Less semantic  C Language  B Language.. Bell Labs  Improved to C Language  Is a compiled language

17 MUST- ICS rkimera@must.ac.ug Writing C Programs  A programmer uses a text editor to create or modify files containing C code.  Code is also known as source code.  A file containing source code is called a source file.  After a C source file has been created, the programmer must invoke the C compiler before the program can be executed (run).

18 MUST- ICS rkimera@must.ac.ug Compiler converts human readable language to a language which is understandable by the operating system/hardware Examples of C/C++ compilers of today: Visual C++ GCC/G++ DJGPP (open source for windows like GCC) Borland C Codeblocks

19 MUST- ICS rkimera@must.ac.ug 3 Stages of Compilation Stage 1: Preprocessing  Performed by a program called the preprocessor  Modifies the source code (in RAM) according to preprocessor directives (preprocessor commands) embedded in the source code  Strips comments and white space from the code  The source code as stored on disk is not modified.

20 MUST- ICS rkimera@must.ac.ug 3 Stages of Compilation (con’t) Stage 2: Compilation  Performed by a program called the compiler  Translates the preprocessor-modified source code into object code (machine code)  Checks for syntax errors and warnings  Saves the object code to a disk file, if instructed to do so (we will not do this).  If any compiler errors are received, no object code file will be generated.  An object code file will be generated if only warnings, not errors, are received.

21 MUST- ICS rkimera@must.ac.ug Object code:  It is machine language code containing various calls specific to operating system… e.g the object code written by compiler is not only hardware dependent but also operating system dependent.  So if you have linux and windows both operating systems then object file compiled by one Operating System (OS) will not get executed on the other OS

22 MUST- ICS rkimera@must.ac.ug 3 Stages of Compilation (con’t) Stage 3: Linking oCombines the program object code with other object code to produce the executable file. oThe other object code can come from the Run-Time Library, other libraries, or object files that you have created. oSaves the executable code to a disk file. On the Linux system, that file is called a.out. oIf any linker errors are received, no executable file will be generated.

23 MUST- ICS rkimera@must.ac.ug Program Development Using gcc Source File pgm.c Program Object Code File pgm.o Executable File a.out Preprocessor Modified Source Code in RAM Compiler Linker Other Object Code Files (if any) Editor

24 MUST- ICS rkimera@must.ac.ug A Simple C Program /* I am a comment */ #include //This is preprosessor directive int main ( void )//this tells the starting point of your program { printf (“Hello World” ); //print the text on monitor return 0 ; //return to operating system }

25 MUST- ICS rkimera@must.ac.ug Anatomy of a C Program program header comment preprocessor directives (if any) int main ( ) { statement(s) return 0 ; }

26 MUST- ICS rkimera@must.ac.ug Program Header Comment  A comment is descriptive text used to help a reader of the program understand its content.  All comments must begin with the characters /* and end with the characters */  These are called comment delimiters  The program header comment always comes first.

27 MUST- ICS rkimera@must.ac.ug Preprocessor Directives  Lines that begin with a # in column 1 are called preprocessor directives (commands).  Example: the #include directive causes the preprocessor to include a copy of the standard input/output header file stdio.h at this point in the code.  This header file was included because it contains information about the printf ( ) function that is used in this program.

28 MUST- ICS rkimera@must.ac.ug stdio.h  When we write our programs, there are libraries of functions to help us so that we do not have to write the same code over and over.  Some of the functions are very complex and long. Not having to write them ourselves make it easier and faster to write programs.  Using the functions will also make it easier to learn to program!

29 MUST- ICS rkimera@must.ac.ug int main ( void )  Every program must have a function called main. This is where program execution begins.  main() is placed in the source code file as the first function for readability.  The reserved word “int” indicates that main() returns an integer value.  The parentheses following the reserved word “main” indicate that it is a function.  The reserved word “void” means nothing is there.

30 MUST- ICS rkimera@must.ac.ug The Function Body  A left brace (curly bracket) -- { -- begins the body of every function. A corresponding right brace -- } -- ends the function body.  The style is to place these braces on separate lines in column 1 and to indent the entire function body 3 to 5 spaces.

31 MUST- ICS rkimera@must.ac.ug Printf( “Hello, World!”) ;  This line is a C statement.  It is a call to an object with a single argument (parameter),  Even though a string may contain many characters, the string itself should be thought of as a single quantity.  Notice that this line ends with a semicolon. All statements in C end with a semicolon.

32 MUST- ICS rkimera@must.ac.ug return 0 ;  Because function main() returns an integer value, there must be a statement that indicates what this value is.  The statement return 0 ; indicates that main() returns a value of zero to the operating system.  A value of 0 indicates that the program successfully terminated execution.  Do not worry about this concept now. Just remember to use the statement.

33 MUST- ICS rkimera@must.ac.ug Another C Program #include int main( void ) { int value1, value2, product ; printf(“Enter two integer values: “) ; scanf(“%d%d”, &value1, &value2) ; product = value1 * value2 ; printf(“Product = %d\n”, product) ; return 0 ; }

34 MUST- ICS rkimera@must.ac.ug Good Programming Practices  C programming standards and indentation styles are available in the book  You are expected to conform to these standards for all programming projects in this class  The program just shown conforms to these standards, but is uncommented (later).  Subsequent lectures will include more “Good Programming Practices” slides.

35 MUST- ICS rkimera@must.ac.ug Tokens  The smallest element in the C language is the token.  It may be a single character or a sequence of characters to form a single item.

36 MUST- ICS rkimera@must.ac.ug Tokens are:  Tokens can be:  Numeric constants  Character constants  String constants  Keywords  Names (identifiers)  Punctuation  Operators

37 MUST- ICS rkimera@must.ac.ug Numeric Constants  Numeric constants are an uninterrupted sequence of digits (and may contain a period). They never contain a comma.  Examples:  123  98.6  1000000

38 MUST- ICS rkimera@must.ac.ug Character Constants  Singular!  One character defined character set.  Surrounded on the single quotation mark.  Examples:  ‘A’  ‘a’  ‘$’  ‘4’

39 MUST- ICS rkimera@must.ac.ug String Constants  A sequence characters surrounded by double quotation marks.  Considered a single item.  Examples:  “UMBC”  “I like ice cream.”  “123”  “CAR”  “car”

40 MUST- ICS rkimera@must.ac.ug Keywords  Sometimes called reserved words.  Are defined as a part of the C language.  Can not be used for anything else!  Examples:  int  while  for

41 MUST- ICS rkimera@must.ac.ug Names  Sometimes called identifiers.  Can be of anything length, but on the first 31 are significant (too long is as bad as too short).  Are case sensitive:  abc is different from ABC  Must begin with a letter and the rest can be letters, digits, and underscores.

42 MUST- ICS rkimera@must.ac.ug Punctuation  Semicolons, colons, commas, apostrophes, quotation marks, braces, brackets, and parentheses.  ; :, ‘ “ [ ] { } ( )

43 MUST- ICS rkimera@must.ac.ug Operators  There are operators for:  assignments  mathematical operations  relational operations  Boolean operations  bitwise operations  shifting values  calling functions  subscripting  obtaining the size of an object  obtaining the address of an object  referencing an object through its address  choosing between alternate subexpressions


Download ppt "12/06/2016 03:04:41 CSC Alliance — 1 Kimera Richard Phone: 0701 437989 INSTITUTE OF COMPUTER SCIENCE DEPARTMENT."

Similar presentations


Ads by Google