Lec4a OOP Function Overview
Lec4a OOP Function Overview
Hung-Yu Wei
Department of Electrical Engineering
National Taiwan University
10/18/2006
Overview: function
What is a function?
A “black box” that does operations with
input values and then returns the output
value.
Type_Out FunctionName (Type_In
InputVariable)
{
operations of the function;
}
function
Function_Name
return Y;
InputVariable
Type_In
Type_Out
setCourseName void;
Name_X
String type
funcSquare
z
x
int int
}
Object Oriented Programming
OOP
以物件為主的 programming
Object
物件
白話翻譯: 1 個東西
Class
類別
白話翻譯: 1 類東西
1 data member
3 member functions
可魯 .age_ 年齡 =x;
小花 .age_ 年齡 = 可魯 .age_ 年齡 +1;
可魯 . 吠叫 ;
cout << “Spot walks ” << 小花 . 散步 (“ 新生南路” ) << “meters
today”;
小花 . 吃 _function(lunch);
return 0;
}
More examples: class and object
Define a class 長方形
class C_Rectangle {
int x, y; // 長,寬
public:
void set_values (int,int);
int area (void);
};
#include <iostream>
using std::cout;
class C_Rectangle {
public:
int x, y; Data member
void C_Rectangle::set_values (int a, int b) {
x = a;
y = b;
} Member function
int area(void) {
return (x*y);
}
};