2021-07-09

一.数组,地址应用
int a=10 把10给a,a存放10
int b=20
int*p=&a p为变量,类型不同,a为整型可存放a的地址,一级指针存放整型变量地址,二级存放一级地址
s=&p 二级指针存放p地址
**s=&a p为a=100
s=&b本身存放b的地址
二.引用的概念
不能空引用,初始化,不存在二级引用
三.现实世界到计算机世界的映射
把实体分析和抽象为抽象类型后设计为类之后实例化为对象
对象的属性:无法改变,对象所存在的状态,对象内部各种变量的数值。
四.栈的应用代码
#include<string.h>
#include
using namespace std;
template“
SeqStack(int sz = 10) :maxsize(sz), top(-1)
{
data = (Type
)malloc(sizeof(Type) * maxsize);
if (data == NULL)exit(1);
}
~SeqStack()
{
free(data);
data = NULL;
maxsize = 10;
top = -1;
}
int GetSize()const { return top + 1; }
bool Is_Empty()const { return GetSize()==0; }
bool Is_Full()const { return GetSize() == maxsize; }
bool Push(const Type& x)
{
if (Is_Full())return false;
data[++top] = x;
return true;
}
Type& GetTop()
{
return data[top];
}
const Type& GetTop()const
{
return data[top];
}
void Pop()
{
–top;
}
void Clear()
{
top = -1;
}
};
int main()
{
SeqStackist= SeqStack();
ist.Push(12);
ist.Push(23);
ist.Push(34);
ist.Push(45);
while (!ist.Is_Empty())
{
int x = ist.GetTop();
ist.Pop();
cout << x << endl;
}
return 0;
}
五.商品描述代码
商品名称用字符串
商品数量用整型数
商品单价用浮点数
商品总价用浮点数
#include<string.h>
#include
using namespace std;
class CGoods
{
private:
char Name[20];
char Amount;
float Price;
float Total_value;
public:
void RegisterGoods(const char
,int,float);
// void RegisterGoods(CGoods this,const char,int,float)
void CountTotal()
// void CountTotal(CGoods this);
{
Total_value=Amount
Price;
}
void GetName(char name[])//读取商品名称
// void GetName(CGoods *this,char name[])
{
strcpy(name,Name);
}
// int GetAmount(CGoods *this)
int GetAmount()//读取商品数量
{
return Amount;
}
// float GetPrice(CGoods *this)
float GetPrice()//读取商品单价
{
return Price;
}
// float GetToatl_value(CGoods *this)
float GetToatl_value()//读取商品价值
{
return Total_value;
}

};

//void CGoods::RegisterGoods(const char *name,int amount,float price)
void CGoods::RegisterGoods(const char *name,int amount,float price)
{
strcpy(Name,name);
this->Amount=amount;
this->Price=price;
}
int main()
{

CGoods c1,c2;
c1.RegisterGoods("iphone",10,6800);

// RegisterGoods(&c1,“iphone”,10,6800);
c1.CountTotal();
c2.RegisterGoods(“huawei”,12,7800);
// c2.RegisterGoods(“huawei”,12,7800);
c2.CountTotal();
return 0;
}
六.一个类中有哪些缺省函数?
构造函数 拷贝构造函数 析构函数 赋值运算符 取地址运算符的重载 移动构造函数 移动赋值
七.this指针
编译器针对程序员自己设计的类型分为三次编译
第一:识别和记录类体中的属性的名称,类型和访问限定,与属性在类体中的位置无关
第二:识别和记录类体中函数原型(返回类型+函数名+参数列表)形参的默认值,访问限定,不识别函数体
第三:改写在类中定义函数的参数列表和函数体
第四:改写对象调用成员函数的形式

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值