2021-07-08

Int  **s   //二级指针

& 与,地址,引用

int main()
{char a=10,b=20;
char c=a&b;
char* cp=&a;
char& x=a;  //引用:不存在空引用,必须给予初始化;不存在引用的引用(没有二级引用);
x=’a’;
a=’z’;
}

类型是设计的产物

编译器针对程序员自己设计的类型分三次编译:

  • 识别和记录类体中属性的名称,类型和访问限定,与属性在类体中的位置无关。
  • 识别和记录类体重函数原型(返回类型+函数名+参数列表),形参的默认值,访问限定。不识别函数体。
  • 改写在类中定义函数的参数列表和函数体,改写对象调用成员函数的形式。

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>

class CGoods
{
private:
	char Name[20];
	int Amount;
	float Price;
	float Total_value;
public:
	//void RegisterGoods(CGoods *this,const char*,int,float);//输入数据
	void RegisterGoods(const char*, int, float);
	//void CountTotal(CGoods *this)
	void CountTotal()//计算商品总价值
	{
		Total_value = Amount * Price;
	}
	//void GetName(CGoods *this,char name[])
	void GetName(char name[])//读取商品名
	{
		strcpy_s(name, 20, Name);
	}
	int GetAmount()//读取商品数量
	{
		return Amount;
	}
	//float GetPrint(CGoods *this)
	float GetPrice()//读数商品单价
	{
		return Price;
	}
	//float GetTotal_value(CGoods *this)
	float GetTotal_value()//读取商品总价值
	{
		return Total_value;
	}
};//最后的分号不能少,这是一条说明语句

//void CGoods::RgisterGoods(CGoods *this,const char* name,int amount,float price)
void CGoods::RegisterGoods(const char* name, int amount, float price)
{
	strcpy_s(this->Name, 20, name);
	this->Amount = amount;
	this->Price = price;
}
int main()
{
	CGoods c1, c2;
	c1.RegisterGoods("iphone", 10,6800);
	//RgisterGoods(&c1,"iphone",10,6800);
	c1.CountTotal();
	c2.RegisterGoods("huawei", 12, 7800);
	//RgisterGoods(&c1,"huawei",12,7800);
	c2.CountTotal();

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值