Full Transcript

PROGRAMMING FUNDAMENTALS USING C School of CSA Deepa B G OUTLINE Course Objectives Course Contents Learning Resources TEXT BOOKS REFERENCE BOOKS Course Outcomes Computer Basics COURSE OBJECTIVES...

PROGRAMMING FUNDAMENTALS USING C School of CSA Deepa B G OUTLINE Course Objectives Course Contents Learning Resources TEXT BOOKS REFERENCE BOOKS Course Outcomes Computer Basics COURSE OBJECTIVES 3. To introduce concepts like 1.To model datatypes, 4. 2. To teach how problems using functions, To develop a to Solve various algorithm and memory console based Problems flowchart management application and file handling COURSE CONTENTS: Unit-1 Computer Problem-Solving, Fundamental Algorithms & Basics of C Programming Introduction To Computer Problem-Solving, The Problem Solving Aspect, Top-Down Design Fundamental Algorithms: Introduction, Exchanging the Values of Two variables, Counting, Summation of a Set of Numbers, Factorial Computation, Generation of the Fibonacci Sequence. Basic Structure of C Programs, C Tokens, Data types in C, Storage classes in C, I/O Statement in C: Scanf() and printf(). COURSE CONTENTS: Unit-2 Operators, Expressions & Structured Constructs Operators and Expressions: Introduction, Arithmetic Operators, Relational Operators, Logical Operators, Assignment Operators, Increment and Decrement Operators, Conditional Operator, Bitwise Operators, Special Operators, Arithmetic Expressions, Evaluation of Expressions, Precedence of Arithmetic Operators. Structured Constructs: Decision Making and Branching, Looping Constructs. COURSE CONTENTS: Unit-3 Arrays, Library and User Defined Functions Arrays &Functions: Arrays: Introduction, One-Dimensional Arrays, Initialization of One-Dimensional Arrays, Two Dimensional Arrays, Initializing Two Dimensional Arrays, Multi Dimensional Arrays, Character Arrays and Strings: Introduction, Declaring and Initializing String Variables, Reading Strings from Screen, Writing Strings to Screen, predefined String-Handling and mathematical Functions. User-Defined Functions: Introduction, Need for User defined FunctionsElements of User defined Functions.Category of Functions, No arguments and No return values, Arguments but No return values, Arguments with return values, No arguments but returns a value, Recursion. COURSE CONTENTS: Unit-4 User Defined Data Types, Pointers and Files User Defined Data Types: Structures and Unions: Introduction, Defining a Structure, Declaring Structure Variables, Accessing Structure Members, Structure Initialization, Copying and Comparing Structure Variables, Operations on Individual Members, Arrays of Structures, Arrays within Structures, Structures within Structures, Unions. Introduction to Pointers: Introduction and Understanding pointers, Accessing the address of a variable, Declaring pointer variables, Initialization of pointer variables, Accessing a variable through its pointer. Dynamic Memory Management Functions,File Management in C: Introduction, Defining and Opening a File, Closing a File, Input/ Output Operations on Files LEARNING RESOURCES: Text Books: 1. R.F Dromey, “How to Solve it by Computer” Pearson, Fourteenth Impression, 2013. (Chapter 1 & 2) 2. E. Balaguruswamy, “Programming In ANSI C”, rd edition, McGraw Hill Education, 2006. (Chapter 1 to 12) LEARNING RESOURCES: Reference Books: 1. Byron S Gottfried ,Programming with C “ 4th Edition (Schaum's Outlines) , 2018YashwantKanetkar, “Let Us C”, 13th Edition, PHP, 2013. 2. Yashwant Kanetkar, “Let Us C”, 13th Edition, PHP, 2013. 3. Anami, Angadi, and Manvi, “Computer Concepts and C Programming – A Holistic approach”, PHI -2008. COURSE OUTCOMES: 1. Formulate algorithms and flow chart and convert it to programs to solve logical and mathematical problems. 2. Decompose a problem into functions and synthesize it to program using divide and conquer approach 3. Use arrays and structures to represent various types of data 4. Memory management and file handling operations COMPUTER BASICS: Instruction: Single operation of a processor defined by the processor instruction set. Program: Sequence of instructions to performs a task. Software, instructions that tell a computer what to do.  Set of programs, procedures, and routines associated with the operation of a Computer System.  Responsible for controlling, integration and managing hardware components and perform specific tasks. Hardware, Computer machinery and equipment Ex: Memory, cabling, power supply, Peripheral devices, and circuit boards. CLASSIFICATION OF SOFTWARE CLASSIFICATION OF SOFTWARE - SYSTEM SOFTWARE  Supports and manages the computer resources and operations of the computer system. Essential to run the computer.  Creates a communication link between the computer and user Functions of system software 1. Monitoring the use of all the hardware components. 2. Providing an easy and efficient interaction between the computer and user. 3. Communication with the peripheral devices such as a scanner, printer, webcam etc. 4. Managing files and folders and Providing security. 5. Provide platform for application software. SYSTEM SOFTWARE: EXAMPLES Example of Operating Systems: 1. Operating System  System software that manages computer resources (hardware as well as applications).  Acts as an intermediary between a user and computer hardware and makes computer system convenient to use. OPERATING SYSTEM CONTD… Tasks of Operating System: SYSTEM SOFTWARE EXAMPLES CONTD… EXAMPLES 2. Utility Software  Used for maintenance of computer system.  Plays a vital role in making the computer function properly. Drivers SYSTEM SOFTWARE EXAMPLES may CONTD… interface Printers with 3. Device driver software: Image Video Computer program that scanners adapters operates or controls a particular type of device that is attached to a Implementing computer support for Network  Provides a software different file cards interface to hardware systems devices.  Controls the devices Computer storage attached to the computer Sound cards devices such as system. hard disk, CD- SYSTEM SOFTWARE EXAMPLES CONTD… 4. Language Processor Software Translates the programming language code into machine code. Three types 1. Assembler 2. Interpreter 3. Compiler TYPES OF LANGUAGE PROCESSORS/TRANSLATORS LANGUAGE PROCESSOR SOFTWARE - COMPILER Used to translate a program written in a high-level language into machine code (object code). Once compiled (all in one go), the translated program file can then be directly used by the computer and is independently executable An error report is often produced after the full program has been translated. LANGUAGE PROCESSOR SOFTWARE - INTERPRETER It read, translate and Stops when a execute one line of code is statement at a reached that time from a contains an high-level error. language program. No executable file is produced. Can be Used The program is during the interpreted development of a again from program. scratch every time you launch it. LANGUAGE PROCESSOR SOFTWARE - ASSEMBLER Translate a program written in a low- level assembly language into a machine code (object code) file so it can be used and executed by the computer. Every assembler has its own assembly language, which is designed for one specific computer architecture. Once assembled, the program file can be used again and again without re-assembly. COMPARISON BETWEEN TRANSLATORS CLASSIFICATION OF SOFTWARE - APPLICATION SOFTWARE Designed to solve a specific problem of the user or to perform the specific task. Two types: 1. Tailored or customized Software: Software to solve specific problems Ex: Payroll system, Result processing, Library management system, Banking system, School management system etc. APPLICATION SOFTWARE CONTD.. 2. General or Packaged software Made by software companies to solve the general problems of people. Examples MS-excel MS-access Photoshop Dreamweaver Notepad etc. SUMMARY Course Introduction to Objectives the Course Course Contents Course outcomes Instruction Program Computer Software Basics: Hardware Types of Software QUIZ 1. The physical devices of a computer : a) Software b) Package c) Hardware d) System Software 2. Which of the following is designed to control the operations of a computer? a) Application Software b) System Software c) Utility Software d) User QUIZ 3. ___________________ is designed to solve a specific problem or to do a specific task. a) Application Software b) System Software c) Utility Software d) User 4. Assembler is used as a translator for? a) Low level language b) High Level Language c) COBOL d) C QUIZ 5. Which of the following is not an example of system software? a) Language Translator b) Utility Software c) Communication Software d) Word Processors 6. ___________ refer to renewing or changing components like increasing the main memory, or hard disk capacities, or adding speakers, or modems, etc. a) Grades b) Prosody c) Synthesis d) Upgrades REFERENCES: 1. E. Balaguruswamy, “Programming In ANSI C”, 3rd edition, McGraw Hill Education, 2006. 2. Yashwant Kanetkar, “Let Us C”, 13th Edition, PHP, 2013. 3. https://www.ictlounge.com/html/operating_systems.htm 4. https://medium.com/@ abeysinghechamath/writing-your-own-operating-system-2e09099 38249. 5. http://www.studyboost.unaux.com/system.html?i=1 6. https://www.techjockey.com/blog/utility-program-and-functions COMPUTER BASICS – PROGRAMMING LANGUAGES PROBLEM SOLVING PROCESS 1. SCHOOL OF COMPUTER SCIENCE AND APPLICATIONS REVIEW OF PREVIOUS LECTURE COURSE INTRODUCTION COMPUTER BASICS TOPIC FOR THE DAY PROGRAMMING LANGUAGES- TYPES PROBLEM SOLVING PROCESS WHAT IS A PROGRAMMING LANGUAGE?  Instruction set: The basic operations of a computer system.  Algorithm: The approach or method that is used to solve the problem.  Programing Language: Set of rules that provides a way of telling the computer what operations to perform.  It provides a linguistic framework for describing computations.  English is a natural language. It has words, symbols and grammatical rules.  A programming language also has words, symbols and rules of grammar.  The grammatical rules are called syntax. TYPES OF PROGRAMING LANGUAGES TYPES OF PROGRAMING LANGUAGES CONTD… 1. Machine language 2. Instructions are directly executed by CPU. 3. Instructions are written in order of 0’s and 1’s and which are known as binary code. 4. Programming was very complex TYPES OF PROGRAMING LANGUAGES CONTD… Second Generation Languages 1. Assembly language 2. Human-readable notation for EXAMPLE: the machine language 3. Instructions are written using symbolic instruction codes that are meaningful abbreviations or mnemonics. 4. Assembler is a program that translates assembly language into machine language. TYPES OF PROGRAMING LANGUAGES CONTD… Third Generation Languages 1. Procedural language uses a series of English-like words, that are closer to human EXAMPLES: language, to write instructions. PASCAL, 2. Make complex programming FORTRAN, simpler, easier to read, write and maintain. BASIC, COBOL, 3. Translated into machine language by a compiler or C and interpreter C++ TYPES OF PROGRAMING LANGUAGES CONTD… Fourth Generation Languages Examples 1. Non-procedural language, often SQL, abbreviated as 4GL. NOMAD and 2. Enables users to access data in a FOCUS database. Perl  Query Languages Python  Report generators Ruby  Form designers MatLab (Matrix  Application generators Laboratory). TYPES OF PROGRAMING LANGUAGES CONTD… Fifth generation languages 4. People can talk to computers and the voice 1. Visual programming language, recognition systems can is also known as Natural convert spoken sounds into language. written word. 2. Provides a visual or graphical interface, called a visual programming environment, for Examples: creating source codes. Prolog 3. Allows people to interact with Mercury computers without needing any specialized knowledge. OPS5 PROBLEM SOLVING Solving problems is the core of computer science. Programmers must first understand how a human solves a problem. Understand how to translate this Algorithm into specific syntax of programming language. Systematic approach to find and implement a solution to a problem. 1. PROBLEM SOLVING PROCESS PROBLE M DEFINITI ON 2. Input PROBLEM Processing ANALYSIS Output 3. Algorithm PROBLEM Flow DESIGN chart 4. Coding COMPUTE Testing Debuggin R g SOLUTIO Document N ation Maintena nce PROBLEM SOLVING PROCESS CONTD.…. 1. PROBLEM DEFINITION State the problem clearly and unambiguously (Doubtless) to understand exactly. 2. What the problem is? 3. What is needed to solve it? 4. What solution should provide? 5. If there are constraints and special conditions. PROBLEM SOLVING PROCESS CONTD…. 2. PROBLEM ANALYSIS Identify the following 1. Inputs: To the problem, their form and the input media to be used. 2. Outputs: Expected from the problem, their form and the output media to be used. 3. Special constraints or (necessity) conditions (if any). 4. Formulas or equations to be used. PROBLEM SOLVING PROCESS CONTD.…. 3. PROBLEM DESIGN  It is done using tools like Algorithms and Flowcharts.  Develop a step by step procedure to solve the problem using the specification given in the previous phase.  Flowchart is a Pictorial representation of an Algorithm. PROBLEM SOLVING PROCESS CONTD.…. 4. Computer Solution 4.1 Coding:  Use a programming language to write or implement the actual programming instructions for the steps defined in the previous phase.  EX: C, C++, Java, python ,.NET etc. 4.2 Testing The program is tested on a number of suitable test cases. The most trivial and the most special cases should be identified and tested. Include the maximum and minimum values of all variables PROBLEM SOLVING PROCESS CONTD.…. Debugging: Errors in the programs are detected and corrected.  Some common errors which might occur in the programs include:  Un initialization of variables.  Reversing of order of operands.  Confusion of numbers and characters.  Inverting of conditions eg jumping on zero instead of on not zero. PROBLEM SOLVING PROCESS CONTD.…. 4.3 Documentation: Essential step in the program development. Help the users and the people who maintain the software. Future modification if required can be done easily. required during redesigning and maintenance. PROBLEM SOLVING PROCESS CONTD.…. Maintenance:  Updating and correction of the program for changed conditions and field experience is accounted for in maintenance.  Maintenance becomes essential in following situations:  Change in specification and equipment,  Errors which are found during the actual execution of the program. TYPES OF ERRORS  Error is an illegal operation performed by the user which results in abnormal working of the program.  Programming errors often remain undetected until the program is compiled or executed.  Some of the errors inhibit the program from getting compiled or executed. Thus errors should be removed before compiling and executing. The most common errors can be broadly classified as follows. TYPES OF ERRORS 1. Syntax errors: Errors that occur when you violate the rules of writing C/C++ syntax are known as syntax errors. This compiler error indicates something that must be fixed before the code can be compiled. All these errors are detected by compiler and thus are known as compile-time errors. Most frequent syntax errors are: Missing Parenthesis (}) 2. Printing the value of variable without declaring it 3. Missing semicolon like this: TYPES OF ERRORS: EXAMPLE: SYNTAX ERROR TYPES OF ERRORS Run-time Errors :  Errors which occur during program execution(run-time) after successful compilation are called run-time errors.  One of the most common run-time error is division by zero also known as Division error.  These types of error are hard to find as the compiler doesn’t point to the line at which the error occurs. TYPES OF ERRORS EXAMPLE: LINKER ERRORS TYPES OF ERRORS 3. Linker Errors:  These error occurs when after compilation we link the different object files with main’s object using Ctrl+F9 key(RUN).  These are errors generated when the executable of the program cannot be generated.  This may be due to wrong function prototyping, incorrect header files. One of the most common linker error is writing Main() instead of main(). TYPES OF ERRORS EXAMPLE: LINKER ERRORS TYPES OF ERRORS 4. Logical Errors :  On compilation and execution of a program, desired output is not obtained when certain input values are given.  These types of errors which provide incorrect output but appears to be error free are called logical errors.  These are one of the most common errors done by beginners of programming. These errors solely depend on the logical thinking of the programmer and are easy to detect if we follow the line of execution and determine why the program takes that path of execution. TYPES OF ERRORS No output TYPES OF ERRORS 5. Semantic errors : This error occurs when the statements written in the program are not meaningful to the compiler. SUMMARY 1. Types of Programming Languages 2. Problem Solving Process QUIZ 1. There are ______steps to solve the problem a) 7 b) 4 c) 6 d) 3 2. ______is the first step in solving the problem e) Understanding the Problem f) Identify the Problem g) Evaluate the Solution h) None QUIZ 3. Following is true for understanding of a problem A. Knowing the knowledgebase B. Understanding the subject on which the problem is based C. Communication with the client D. All of the above 4. Which of the following retains the information it’s storing when the power to the system is turned off? E. CPU F. ROM G. RAM QUIZ 5. The language made up of binary coded instructions. a) Machine b) C c) BASIC d) High level 6. A program that reads each of the instructions in mnemonic form and translates it into the machine-language equivalent. a) Machine language b) Assembler c) Interpreter d) C program QUIZ 7. Prolog comes under ___________ a) Logic Programming b) Procedural Programming c) OOP d) Functional 8. Which of the following isn’t a characteristic of High level languages? a) machine code b) platform independent c) interactive execution d) user-friendly REFERENCES 1. E. Balaguruswamy, “Programming In ANSI C”, 3rd edition, McGraw Hill Education, 2006. 2. V. Raja Raman, Neeharika Adabala, “Fundamentals of Computers”, 6th Edition, PHI, 2015. 3. https://httpadeenrabbani.wordpress.com/2017/05/28/generations- of-programming-languages/ Fundamental Algorithms: Introduction Flow chart Examples REVIEW OF PREVIOUS LECTURE PROGRAMMING LANGUAGES-TYPES PROBLEM SOLVING PROCESS TOPIC FOR THE DAY Fundamental Algorithms: Introduction Flow chart Examples WHAT IS ALGORITHM?  The word Algorithm is derived from the 9th-century mathematician Muhammad ibn Musa al-Khwarizmi,  Latinized Algorithm.  Definition: An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time.  Real life example: Cooking a recipe. Notion of an Algorithm: IMPORTANT POINTS: The non The range Algorithms ambiguity The same There may of inputs for for the Can solve requirement algorithm exist which an same the problem for each can be several algorithm problem can with step of an represented algorithms works has be based on dramatically algorithm in several for solving to be very different cannot be different the same specified different speeds. compromise ways. problem. carefully. ideas and d. ALGORITHM- CHARACTERISTICS Unambiguous − clear and unambiguous. Each of its steps (or phases), and their inputs/outputs should be clear and must lead to only one meaning. Input − should have 0 or more well-defined inputs Output − should have 1 or more well-defined outputs, and should match the desired output. Finiteness − must terminate after a finite number of steps Feasibility − Should be feasible with the available resources. Independent − should have step-by-step directions, which should be independent of any programming code. EXAMPLES OF ALGORITHMS IN PROGRAMMING 1. Write an algorithm to add two numbers entered by the user STEP 1: Start STEP 2: Declare variables num1,num2 and sum STEP 3: Read values num1 and num2 STEP 4: Add num1 and num2 and assign the result to sum sum 0 then increment count by 1 i.e. count++. 5. Divide num by 10 to remove last digit of the given number i.e. num = num / 10. 6. Repeat step 3 to 4 till num > 0 or num != 0. 7. Print digit 1. write a program to count number of digits of an integer in c #include int main() { int n; // variable declaration int count=0; // variable declaration printf("Enter a number"); scanf("%d",&n); 10 0 while(n!=0) { n=n/10; count++; } printf("\nThe number of digits in an integer is : %d",count); return 0; } Output: Enter a number45871 The number of digits in an integer is : 5 10 1 SUMMATION OF NUMBERS EXAMPLE: The Sum of first 10 natural numbers SUMMATION OF NUMBERS Algorithm: 1. Read the value of n. 2. i = 1 , SUM = 0 3. if ( i >= n ) go to step 7 4. SUM = SUM + I 5. i=i+1 6. go to 3 7. Display the value of SUM 8. Stop FLOW CHART TO FIND THE SUM OF FIRST N NATURAL NUMBERS SUMMARY 1. Algorithms for Count Number of Digits in an Integer Summation of n numbers 1. write a program to Summation of a Set of Numbers in c #include #include void main() { int num, i, sum = 0; // declare local variables printf(" Enter a positive number: "); scanf("%d", &num); // take any positive number // executes until the condition remains true. 10 6 for (i = 0; i

Use Quizgecko on...
Browser
Browser