第一個C++,習進平的第一個妻子
輸入:cin>>(相當於scanf)
#include <iostream>
using namespace std;
int main()
{ int number;
cout<<"hello!world!"<<endl; //printf "hello!world"
cout<<"請輸入數字:";
cin>>number; //輸入數字
cout<<"hello"<<number<<"lll"<<endl; //輸出hello+number裡面的東西
return 0;
}
面向對象:what is an object?
object=entity
#可見的(visible)
對象就是變量(object is variable in programming languges)
另一個角度:對象=結構;+服務(objects=attributes+services)
from the problem space to the solution
C語言板的3d 圖形效果
typedef struct point3d
{
float x;
float y;
float z;
} point3d;
void point3d_printf(const Point3d*pd);
point3d a;
a.x=1;a.y=2;a.z=3;
point3d_printf(&a);
C++板的
class point3d //class=struct
{
public:
Point3d(float x,float y,float z);
print(); //調用print函數
private:
float x;
float y;
float z; //私有數據
};
point3d a(1,2,3);
a.print(); //a是一個對象 讓a去做print函數功能
區別:
C語言的struct裡不能做操作
C++的類裡面可以做數據的操作
what is object)-oriented //導向
1.it is a way
2.designs //設計 算法
3.implementations //實現 寫代碼
4. object 主要用是設計與實現
面向對象的基本原理
object send messages
messages are
-composed by the sender //有發送z
-interpreted by the receiver //服務器快來解讀
-implemented by methods //y以函數的方式來傳遞
messges
may cause receiver to change state
may return results
object vs.class
類是一個概念
對象是一個實體
{class define object
object is a class}
object (cat)
represent things events,or concepts
respond to messages at run-time
類定義了對象章什麼樣
對象是一個那樣的東西
oop characteristics
1 everything is an obect .
2 a program is a bouch of objects telling eachoather what to do by sending messages.
3 each oject has its own memory made up of other objects.
4 every object has a type . //每一個對象都是一個類
5 all object of a particular type can recieve the same messages . //所有可以接受相同消息的對象可以被認為是同一個類
an object has an interface
the interface is the way it recevies messages.
it is
functions of the interface //接口的功能
caommunication //用於通信 裡面的東西和外界的通信
protection // 接口可以保護裡面的東西
the hidden implementation //隱藏 封裝的
oop的三特性
encapsulation //封裝 包裝
bundle data and methods dealoing with thses data together in an object //把數據和對數據的操作捆綁在一個對象裡
hide the details of the data the action //裡面的細節部分是隱藏的
restrict(限制 約束) only access to the publicized //只能看到公開的部分
bun
繼承
多態性