第一个C++

本文深入探讨了C++面向对象编程的基本原理,并通过实例展示了如何使用C++实现3D图形效果。从对象的概念出发,阐述了对象与类的区别,以及面向对象的四大特性:封装、继承、多态性和抽象。通过具体代码示例,演示了如何在C++中创建和操作对象,以及如何利用类来实现复杂的3D图形功能。
输入: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
继承 
多态性
 
 
 

转载于:https://www.cnblogs.com/da-guang/p/4140628.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值