



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




The abstraction is rectangular arrays
The implementation is one-dimensional array.
S = set of persons. X in S; smallest-age = X; S = S-{X}; While S is not empty do Y in S; S = S-{Y}; If age(Y) < age(X) Then smallest = Y; Endwhile;
o What do you need to implement such a problem?
o For a given implementation,
we need to make the following assumptions:
o (1) & (3) =====> Abstract Data Types ( ADT ). o (2) =====> A way to implement the ADT.
o Simple data types:
Integer, real, character, enumeration types, etc.
o Structured data types:
arrays, records, files, and sets.
o It provides implementation details for the data structure used and operations.
o OOP supports the implementation of an ADT using information hiding.
o Information hiding is used to hide the implementation details Prevent users from directly accessing data members ( private access modifier).
o ADT: Fraction Data type:
o Java Implementation:
//Fraction ADT public class Fraction {
private int numerator; private int denominator; public Fraction(){ numerator = 0; denominator = 1; } public Fraction( int num, int deno){ numerator = num; denominator = deno; if (denominator == 0){ throw new IllegalArgumentException("Denominator cannot be zero"); } } public void reduceF(){ int n = numerator; int d = denominator; while (d != 0) { int t = d; d = n % d; n = t; } numerator /= n; denominator /= n; }