A limited time offer!

urgent 3h delivery guaranteed

• Programming Languages • History of C • Problem Solving – Flowcharts – Algorithms – Programs

Essay Topic: ,

Computer Fundamentals Lecture 7 Samin Khaliq Today’s Lecture • Programming Languages • History of C • Problem Solving – Flowcharts – Algorithms – Programs • C Program • Comments Types of Programming Languages Low Level Languages 1. Machine language (1GL) • • Strings of numbers giving machine specific instructions Example: Calculates nth Fibonacci number 8B542408 FA027706 B9010000 C84AEBF1 83FA0077 06B80000 0000C383 B8010000 00C353BB 01000000 008D0419 83FA0376 078BD98B 5BC3 2. Assembly language (2GL) • English-like abbreviations representing elementary computer operations (translated via assemblers) Example: fib: mov edx, [esp+8] cmp edx, 0 ja @f mov eax, 0 ret … 3 Types of Languages 3. High-level languages (3GL) • Codes similar to everyday English • Use mathematical notations (translated via compilers) • Example: grossPay = basePay + overTimePay • Languages: – C, C++, Java, FORTRAN, COBOL, Pascal 4 Development of programming languages Development of Programming Languages • 2000 ? C# . . • 2001 ? Visual Basic . NET .

We will write a custom essay sample on • Programming Languages • History of C • Problem Solving – Flowcharts – Algorithms – Programs

or any similar topic only for you

Order Now

. . . • 2009 ? Go by Google Inc. (Similar to C) A brief history of C • Developed Dennis M.Ritchie at AT&T Bell Labs between 1969–1973 for UNIX • Descendant of Ken Thompson’s language “B” • First published specification standard: – Ritchie and Brian Kernighan “The C Programming Language” in 1978 – C-dialect now known as K&R-Style • Ease of portability ? language began to spread • However language standard (K&R) insufficiently precise • A slightly modified version of K&R was standardised by ANSI 1989 – C-dialect now known as ANSI-C • The latest revision of the Standard is C99 (ISO) • ISO/IEC JTC1/SC22/WG14 is the international standardization working group for the programming language C.Dennis Ritchie and Ken Thompson C and C++ • C++ is descended from C – Written by Bjarne Stroustrup during 1983-1985 – Originally called “C with Classes” • ISO/IEC JTC1/SC22/WG21 has produced the standard ISO/IEC 14882:1998 on the programming language C++. • A technical corrigendum was approved in 2003. • C and C++ are different languages Why C / C++ ? • High level language – C is higher level than assembler but still close to the hardware and allows direct manipulation of many system aspects: pointers, memory allocation, bitwise manipulation. Widely used across the world – Portability – Programs can run on many different computers • Fast • Structured (Extensive use of functions) C and C++ popularity (www. tiobe. com) Problem Solving and Implementation • A typical programming task can be divided into two phases: • Problem solving phase – Produce an ordered sequence of steps that describe solution of problem – This sequence of steps is called an algorithm • Implementation phase – Implement the program in some programming language Developing a program Problem solving phase Implementation phaseDefinitions • Algorithm – A sequence of language independent steps which may be followed to solve a problem. • Flowchart – Diagrammatic representation of steps for solving the given problem. • Program – A precise sequence of steps to solve a particular problem • Programming languages – Languages for specifying sequences of directions to a computer. Problem • Read in the temperature. If the temperature is less than 32 indicate it as below freezing on the screen. Else if the temperature is above freezing then indicate the same on the monitor screen. Divide the above problem into manageable parts. – Input – Processing – Output Algorithm Input: Temp if (Temp < 32) then Print “BELOW FREEZING” else Print “ABOVE FREEZING” endif Flowchart Symbols Integrated Development Environment (IDE) • Software Application for software development • • • • A source code editor A compiler and / or an interpreter Build automation tools A Debugger Basics of a Typical C Program Development Environment Phases of C Programs: Editor Preprocessor Disk Disk Disk Disk Primary Memory 1. Edit 2. Preprocess Compiler Linker 3. Compile 4.Link 5. Load 6. Execute Program is created in the editor and stored on disk. Preprocessor program processes the code. Compiler creates object code and stores it on disk. Linker links the object code with the libraries Loader puts program in memory. Loader Disk .. .. .. Primary Memory CPU .. .. .. CPU takes each instruction and executes it, possibly storing new data values as the program executes. From C to an executable binary pp .lib bj bj Hello World Compiler converts human readable language to a language which is understandable by the operating system/hardwareExamples of C/C++ compilers of today: Visual C++ GCC/G++ DJGPP (open source for windows like GCC) Borland C Turbo (obsolete and not recommended) Hello World Program #include // Preprocessor Directive int main() // Function name, must for every program { // Opening brace – start of block of code printf(“Hello World”);// Function to display text on monitor return 0; // Indicates that program ended successfully } // Closing brace – end of block of code OUTPUT: Hello World 25 2. 2 A Simple C Program: Printing a Line of Text • int main() C/ C++ programs contain one or more functions, exactly one of which must be main • Defines entry point of the program. – Parenthesis “( and )” used to indicate a function – int means that main “returns” an integer value – Braces { and } indicate a block • The bodies of all functions must be contained in braces • Note: Block can be a function or a piece of code © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26 2. 2 A Simple C Program: Printing a Line of Text • printf( “Welcome to C!
” ); Instructs computer to perform an action • Specifically, prints the string of characters within quotes (” “) – Entire line called a statement • All statements must end with a semicolon (;) – Escape character () • Indicates that printf should do something out of the ordinary •
is the newline character © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 27 2. 2 A Simple C Program: Printing a Line of Text Escape Sequence Description
Newline. Position the cursor at the beginning of the next line. t a ” Horizontal tab. Move the cursor to the next tab stop. Alert. Sound the system bell. Backslash. Insert a backslash character in a string. Double quote. Insert a double quote character in a string. Fig. 2. 2 Some common escape sequences. © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 28 2. 2 A Simple C Program: Printing a Line of Text • return 0; – A way to exit a function – return 0, in this case, means that the program terminated normally • Right brace } – Indicates end of main has been reached • Linker When a function is called, linker locates it in the library – Inserts it into object program – If function name is misspelled, the linker will produce an error because it will not be able to find function in the library © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 2 3 4 5 6 7 8 9 10 11 12 /* Fig. 2. 3: fig02_03. c Printing on one line with two printf statements */ #include 29 Outline fig02_03. c /* function main begins program execution */ int main() { printf( “Welcome ” ); printf( “to C!
” ); return 0; /* indicate that program ended successfully */ 3 } /* end function main */ Welcome to C! Program Output © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 2 3 4 5 6 7 8 9 10 11 /* Fig. 2. 4: fig02_04. c Printing multiple lines with a single printf */ #include 30 Outline fig02_04. c /* function main begins program execution */ int main() { printf( “Welcome
to
C!
” ); return 0; /* indicate that program ended successfully */ 12 } /* end function main */ Welcome to C! Program Output © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc.All Rights Reserved. Comments /* … */ //… • Use comments liberally • Helps programmer and others understand program • Compiler ignores comments (reduce file size and execution time) • Two ways of writing comments /* Filename. cpp or Filename. h Author: Program version: Program Description: Date: */ // This statement will print “Hello World Program: Compilation to execution #include stdio Assemblers • Assembler – “An assembler is a program that translates the assembly-language program into machine language. ” McGraw-Hill Compiler • Compiler – translates complete code “A language translator program that converts the entire program into a machine language before computer execute the program” McGraw-Hill • Compiled Languages – Pascal, C, C++, Ada Interpreter • Interpreter – translates code one line at a time – “Translates language statements into machine language and execute it immediately, statement by statement ” McGraw-Hill • Interpreted Languages – Basic – JavaScript – LISP 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. Preprocessor Directive #include • Tells computer to load contents of a certain file • allows standard input/output operations 3 Stages of Compilation (con’t)Stage 2: Compilation o Performed by a program called the compiler o Translates the preprocessor-modified source code into object code (machine code) o Checks for syntax errors and warnings o 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. o An object code file will be generated if only warnings, not errors, are received. Object code • Machine language code that contains code specific to one operating system • Hence, object code written by one compiler is not only hardware dependent but also operating system dependent • If you have a Linux and a Windows operating system, then object file compiled by one Operating System (OS) will not get executed on the other OS 3 Stages of Compilation (con’t) Stage 3: Linking Combines the program object code with other object code to produce the executable file. o The other object code can come from the Run-Time Library, other libraries, or object files that you have created. o Saves the executable code to a disk file. On the Linux system, that file is called a. out. o If any linker errors are received, no executable file will be generated. Program Development Using gcc Editor Source File program. c Preprocessor Modified Source Code in RAM Compiler Program Object Code File program. o Other Object Code Files (if any) LinkerExecutable File a. out (Linux) The first Computer Bug C – the way it should not be written Indentation styles Case Sensitive • CaSe MaTtErS iN C A ! = a Syntax and Semantics • Syntax – Computer Program (language) – Grammar • Semantics – Meaning of the program Books ? ? ? ? Object Oriented Programming in C++ by Robert Lafore (4th Edition) C How to Program by Deitel and Deitel The C Programming Language by Kernighan and Ritchie Turbo C Programming by Robert Lafore © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.

How to cite this page

Choose cite format:
• Programming Languages • History of C • Problem Solving – Flowcharts – Algorithms – Programs. (2019, Feb 05). Retrieved July 22, 2019, from https://phdessay.com/programming-languages-history-of-c-problem-solving-flowcharts-algorithms-programs/.