problem solving through ‘c’ in c... · coding testing maintenance. 5 ... start/stop connector....

23

Upload: others

Post on 05-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages
Page 2: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Problem Solving Through ‘C’ Learning ‘C’ Programming

Syntax – set of rules that defines the grammar of the programming language. (Checking symbolic representation). A x B (language L1: multiplication) [Error in L2] A * B (language L2 : multiplication) [Error in L1]

Semantics – set of rules used to derive the meaning of the statements. In language L3

A x B (multiplication) A * B (power)

Solving

Given to find multiplication of two numbers. If you write A*B then

semantics is not correct.

2

Page 3: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Block Diagram of a Computer

3

Page 4: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Types of Real World Problems In real world applications we come across day to day

problems Going to market for shoping Solving quadratic equations Matrix Operation: Add, Multiply… ATM Grade calculation Railway/Flight Reservation Library Automation Many More.....

4

Page 5: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Approach to Problem Solving Define and Identify the Problem Analyze the Problem Identifying Possible Solutions Selecting the Best Solutions I/O Specifications Algorithm Coding Testing Maintenance

5

Page 6: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Problem?

Analysis

Solutions

BestSolution

I/OSpecifications

Algorithm

Coding

Testing

Maintenance

6

Page 7: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

An Example- Quadratic Equation Problem Definition: A quadratic equation of the form

Analysis: The equations helps to find Two values x1 and x2

Given constants a, b, c Value of a≠ 0

02 =++ cbxax

7

Page 8: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Solutions: Factorization Quadratic Formula

Best Solution Choose a best possible solution

8

Page 9: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

I/O: Input: a, b, c Output: x1 and x2

Algorithm/Flowchart: An algorithm is a sequence of well defined steps often

used for solving problem A flowchart is a schematic representation of an

algorithm

9

Page 10: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Coding Set of instructions for solving a problem

Testing Finding the errors in the code for possible values

Maintenance Modification due to requirements change Scalability

10

Page 11: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Introduction to Algorithms Step by step method to solve a problem Must include ALL required information

11

Page 12: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Flowcharts Graphical Representation of problems Symbols

Process Decision

Input/OutputFlow

Start/Stop

Connector

12

Page 13: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Add Two Numbers start

Input a, b

c=a+b

print c

stop

13

Page 14: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Programming Languages

Low Level High Level

Machine Level Assembly Language

010100100010111001010100101100001

MOV A,5MOV B,2ADD A,B

14

Page 15: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

More About High Level Languages The languages are designed keeping in mind features

of portability

The languages are machine independent

Easy to write and understand

The programmer pays whole attention logic of the program

15

Page 16: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Translators For translating high level and Assembly Language

to machine language Assembler: Assembly Level Machine Level Interpreter

High Level Machine Level Interpreter searches the error statement by statement

Compiler High Level Machine Level Compiler searches all errors in the code and lists them

16

Page 17: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Some High Level Languages BASIC FORTRAN PASCAL COBOL C C++ Java

17

Page 18: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

C Developed at AT&T Laboratory of USA Year: 1970 Created By: Dennis Ritchie

BCPL

B

C

(Basic Combined Programming Language)

18

Page 19: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Why C? A basic foundation for learning programming

language elements

Major parts of popular OS like windows, Linux, Unix are written in C

Embedded System Programs are written in C Microwave Oven Washing machines Digital Cameras

19

Page 20: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

C provides several language elements that makes interaction with hardware

Several Gaming programs are also developed in C

20

Page 21: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Getting StartedCharacter Set

Definition

A, B, C……….Za, b…..z0,1,2………9@,*,&………..

Instructions

ConstantsVariablesKeywords

Syntax

Program#include<stdio.h>main(){printf(“Hello World”)}

21

Page 22: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

Types of C ConstantsC Constants

Primary Secondary

IntegerRealCharacter

ArrayPointerStructureUnion etc.

22

Page 23: Problem Solving Through ‘C’ in C... · Coding Testing Maintenance. 5 ... Start/Stop Connector. 12. Add Two Numbers start. Input a, b c=a+b print c stop 13. Programming Languages

First C Program// single line comment

/* multiple line

comments within code*/

#include<stdio.h>

main()

{

printf(“Hello World\n”);

}

To include information about standard input/output

Body of Function

Function main

23