java - Object Oriented Programming Soheil Hassas Yeganeh...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Object Oriented Programming Soheil Hassas Yeganeh Computer Engineering Department Sharif University of Technology Classifcation (1) 2 Classifcation (2) 3 Classifcation (2) 3 Classifcation (3) 4 ? ? Classifcation (4) 5 Classifcation (4) 5 What is the problem oF this classifcation? What have you used for classiFcation in C? Sample (1) 7 Sample (1) • We want to write a program that will be used for computing area of geometric shapes. • Circle , Triangle , Rectangle , Square , Kite , ... • We want to write it in C. 7 Sample (2) 8 typedef struct { double h; double b; } Triangle; typedef struct { double side; } Square; typedef struct { double w; double h; } Rectangle; typedef struct { double radius; } Circle; Sample (2) We have to create a type for each shape. 8 typedef struct { double h; double b; } Triangle; typedef struct { double side; } Square; typedef struct { double w; double h; } Rectangle; typedef struct { double radius; } Circle; Sample (3) 9 doube getAreaForSquare(Squar e s){ if(s == null){ return -1; } return s.side * s.side; } Sample (3) We have to create a function for computing the area of each shape. 9 doube getAreaForSquare(Squar e s){ if(s == null){ return -1; } return s.side * s.side; } Sample (4) 10 #define SQUARE 1; #define TRIANGLE 2; #define CIRCLE 4; ... doube getArea( void * s, int type){ if(type & SQUARE){ return getAreaForSquare( *((Square*) s)); } ... return -1; } Sample (4) We have to create a selection function . 10 #define SQUARE 1; #define TRIANGLE 2; #define CIRCLE 4; ... doube getArea( void * s, int type){ if(type & SQUARE){ return getAreaForSquare( *((Square*) s)); } ... return -1; } Any idea to make this easier? An idea 12 typedef struct { double h; double b; double getArea(); } Triangle; ......
View Full Document

This note was uploaded on 11/21/2010 for the course COMPUTER S 003 taught by Professor Izadi during the Spring '10 term at Amirkabir University of Technology.

Page1 / 53

java - Object Oriented Programming Soheil Hassas Yeganeh...

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

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