Vous êtes sur la page 1sur 10

Programming Concepts

By Ramanamurthy
Agenda

• Need For Structured programming


• Structured programming constructs
• Program specifications
• Structured flow charts
• Modular programming
• Exercise on program specifications &
Structured flow charts

PECMCRL / Programming Concepts 2


Solutions

• Various Solutions
– Unstructured
– Structured
• It Works
– If a program works isn’t that all that matters?
– Aren’t all programs that solve the same
problem equivalent? Isn’t one just as good as
another?
PECMCRL / Programming Concepts 3
Bad Solutions

• No, all working solutions are NOT equal


• Some solutions are poor:
– hard to change
– hard for someone else to understand
– brittle, easily broken
• Problem Statement:
– Create a device to sharpen pencils

PECMCRL / Programming Concepts 4


Open window (A) and fly kite (B). String (C) lifts small door (D) allowing moths (E) to escape and eat
red flannel shirt (F). As weight of shirt becomes less, shoe (G) steps on switch (H) which heats electric iron
(I) and burns hole in pants (J). Smoke (K) enters hole in tree (L), smoking out opossum (M) which jumps
into basket (N), pulling rope (O) and lifting cage (P), allowing woodpecker (Q) to chew wood from pencil
(R), exposing lead. Emergency knife (S) is always handy in case opossum or the woodpecker gets sick and can’t
work
PECMCRL / Programming Concepts 5
Structured Solution

PECMCRL / Programming Concepts 6


Can u Understand this program?
#include <stdio.h>
int main()
{ float a; int c,g,t; t=0;c=0;
printf(“Enter data, -1 to end;”);
scanf(“%d”,&g);
loop1:
if (g=-1) goto loop;
{ t=t+g;c++;
printf(“Enter data, -1 to end;”);
scanf(“%d”,&g); goto loop1;}
loop:
if (c!=0){a=(float) t/c; printf(“%.2f”,a)}
else {printf(“No Data Entered\n”);
return 0;}

PECMCRL / Programming Concepts 7


/* class Average with Sentinel controlled repetetion /*
#include <stdio.h>
Int main()
{
float average;
int counter, grade, total;
/* Initialization phase*/
total =0;
counter=0;

/* processing phase */
printf(“Enter Grade, -1 to End: “);
scanf( “%d”, &grade);

while (grade!=-1) {
total = total + grade;
counter = counter+1;
printf(“Enter Grade, -1 to End: “);
scanf( “%d”, &grade);
}

PECMCRL / Programming Concepts 58


/* termination phase */

if (counter!=0) {
average = (float) total/counter;
printf( “Class Average is %.2f”, average);
}
else
printf(“No Grades were Entered\n”);

return 0 /* indicate program ended successfully */


}

PECMCRL / Programming Concepts 59


PECMCRL / Programming Concepts 60

Vous aimerez peut-être aussi