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

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

1 Introduction to Computers II Lecture 4 Dr Ali Ziya Alkar Dr Mehmet Demirer

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

View Full Document
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
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.

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

View Full Document
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.
5 Case Study • Problem: get the radius of a circle, compute and display the circle’s area and circumference.

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

View Full Document
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
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

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

View Full Document
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); }
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); }

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

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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online