Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Data Abstraction and Complex Number ADT in C and C++, Slides of Computer Engineering and Programming

An overview of data abstraction, explaining it as a concept of abstract data types (adts) with their type implementation and operations hidden from the user. The document also covers the benefits of adts for both manufacturers and clients. A complex number adt example is given, including how to declare, create, add, and use complex numbers in c. The document also discusses the support of adts in c and the introduction of classes in c++ as a more object-oriented alternative.

Typology: Slides

2012/2013

Uploaded on 04/25/2013

obesix
obesix 🇺🇸

4.2

(18)

239 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Programming Techniques
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Data Abstraction and Complex Number ADT in C and C++ and more Slides Computer Engineering and Programming in PDF only on Docsity!

Computer Programming Techniques

Overview:

1. What is Data Abstraction?

2. Clients and Manufacturers

3. Complex Number ADT Example

4. How Well are ADTs Supported in C?

5. C++

2. Clients and Manufacturers

implementation interface

ADT

manufacturer’s responsibility client client client use

Benefits

 Manufacturer Benefits:

  • easy to modify, maintain
  • profitable
  • reusable

 Client Benefits:

  • simple to use, understand
  • familiar
  • cheap
  • component-based

Declare a complex number

 Interface:

Complex c1, c2, c3;

 Possible Implementation:

struct complex { double real, imag; } typedef struct complex Complex;

Create a complex number

 Interface:

c1 = create_complex(2, 3); /* conceptually, c1 = 2+3i */

Add two complex numbers

 Interface:

c3 = add_complex(c1, c2); /* conceptually, c3 = c1 + c2 */

Implementation:

Complex add_complex(Complex c1, Complex c2); { Complex csum; csum.real = c1.real + c2.real; csum.imag = c1.imag + c2.imag; return csum; }

int main() { Complex c1, c2, c3; c1 = create_complex(2, -3); c2 = create_complex(2, 9); c3 = add_complex(c1, c2); print_complex(c3); return 0; } /* Implementation of Complex functions */ :

How Well are ADTs Supported in C?

 Does C enforce the use of the ADTs interface

and the hiding of its implementation?

 No