Lecture4hu - Introduction to Computers II Lecture 4 Dr Ali...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Introduction to Computers II Lecture 4 Dr Ali Ziya Alkar Dr Mehmet Demirer
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 • Contents: ± Utilizing the existing information ± Top-down design – Start with the broadest statement of the problem – Works down to more detailed sub-problems. ± Modular programming
Background image of page 2
3 Existing Information • Programmers seldom start from scratch when writing a program. • Typically, you will reuse work that has been done by yourself or others ± For example, using printf and scanf • You start with your algorithm, and then implement it piece by piece ± When implementing these pieces, you can save effort by reusing functionality.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Utilizing existing information • Generated system documents ± Problem description (data requirement) ± Solution algorithm • Strategy ± Editing the data requirements to conform constant and variable definitions ± Using initial algorithm and its refinements (formulas) as the program comments.
Background image of page 4
5 Case Study • Problem: get the radius of a circle, compute and display the circle’s area and circumference.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Analysis • Data requirements: ± Constant PI = 3.14159 ± Input radius ± Output area circumference ± Relevant formulas area of a circle = PI * radius 2 circumference = 2 * PI * radius
Background image of page 6
7 Design • Algorithm ± Get the circle radius ± Calculate the area and circumference ± Display the results • Refinements: ± Assign PI * radius * radius to area ± Assign 2 * PI * radius to circumference
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 /* * Calculate and display the area and circumference of a circle */ #include <stdio.h> #define PI 3.14159 /* constant PI */ int main(void) { double radius; /* input – radius of a circle */ double area; /* output – area of a circle */ double circum; /* output – circumference */ /* Get the radius */ /* Calculate the area */ /* Assign PI * radius * radius to area */ /* Calculate the circumference */ /* Assign 2 * PI * radius to circumference */ /* Display the area and circumference */ return (0); }
Background image of page 8
9 /* * Calculate and display the area and circumference of a circle */ #include <stdio.h> #define PI 3.14159 /* constant PI */ int main(void) { double radius; /* input – radius of a circle */ double area; /* output – area of a circle */ double circum; /* output – circumference */ /* Get the radius */ printf(“Enter radius> “); scanf(“lf”, &radius); /* Calculate the area */ area = PI*radius*radius; /* Calculate the circumference */ circum = 2*PI*radius; /* Display the area and circumference */ printf(“The area is %.4f\n”, area); printf(“The circumference is %.4f\n”, circum); return (0); }
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Solution reuse • Use existing information (the solution for one problem) to solve another.
Background image of page 10
Case Study • Problem: computes the weight of a specified quantity of flat washers. Rim area = PI(d2/2)
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 50

Lecture4hu - Introduction to Computers II Lecture 4 Dr Ali...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online