7.12流插入运算符“<<"和流提取运算符”>>“

本文介绍如何使用C++实现矩阵加法操作,包括构造函数、加法友元函数、输出运算符重载和输入运算符重载,通过实例演示了矩阵加法的基本实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<iostream>
#include<iomanip>
using namespace std;

class Matrix{
private:
	int var[2][4];
public:
	Matrix();                    //构造函数
	friend Matrix operator+(Matrix& a, Matrix& b);            //加法友元函数
	friend ostream& operator<<(ostream&, Matrix&);          //声明运算符“<<”重载为友元函数
	friend istream& operator>>(istream&, Matrix&);          //声明运算符“>>”重载为友元函数
};

Matrix::Matrix()
{
	for (int i=0;i<2;i++)
	for (int j = 0; j < 4; j++)
		var[i][j] = 0;
}

Matrix operator+(Matrix &k, Matrix& p)          //加法函数
{
	Matrix temp;
	for (int i = 0; i < 2;i++)
	for (int j = 0; j < 4; j++)
		temp.var[i][j] = k.var[i][j] + p.var[i][j];
	return temp;
}


ostream& operator<<(ostream& out, Matrix& com)                    //定义运算符“<<”重载函数
{
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 4; j++)
			out <<setw(5)<< com.var[i][j];
		out << endl;
	}
	out << endl;
	return out;
}

istream& operator>>(istream& in, Matrix& com)                 //定义运算符“>>”重载函数
{
	cout << "please input 8 numbers:";
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 4; j++)
			in>>com.var[i][j];
	}
	return in;
}


int main()
{
	Matrix a, b,c;
	cin >> a;
	cin >> b;
	cout << "Matrix a is:" << endl;
	cout << a;
	cout << "Matrix b is:" << endl;
	cout << b;
	c = a + b;
	cout << "Matrix a+b is:" << endl;
	cout << c;
	system("pause");
	return 0;
}

使用Oracle 设计DB存储如下xml 中数据,<msgBody><msgId>AMAT_1A19Y_02829.C00666.UR0ER6.20221020130718</msgId><eqpId>ASSORA-01</eqpId><carrierId>C00666</carrierId><runMode>Y</runMode><batchID>AMAT_1A19Y_02829</batchID><eapUserId>EAPAUTO</eapUserId><fabId>ZH</fabId><function>WAFERSTART</function><sorterAction>WAFERSTART</sorterAction><actionFlag>T</actionFlag><slotMapping>018,UR0ER6.18,C00666,001,ZA0162T.01,C00682;007,UR0ER7.07,C00674,002,ZA0162T.02,C00682;008,UR0ER7.08,C00674,003,ZA0162T.03,C00682;009,UR0ER7.09,C00674,004,ZA0162T.04,C00682;010,UR0ER7.10,C00674,005,ZA0162T.05,C00682</slotMapping><carrierArriveTime>2022-10-20 14:59:50</carrierArriveTime><clampTime>2022-10-20 15:00:32</clampTime><loadStartTime>2022-10-20 15:10:33</loadStartTime><loadCompleteTime>2022-10-20 15:20:33</loadCompleteTime><unloadCompleteTime>2022-10-20 15:40:40</unloadCompleteTime><carrierRemoveTime>2022-10-20 17:00:33</carrierRemoveTime><carrierList><carrierID>C00666</carrierID><carrierType>P</carrierType><lotIDList><lotID>UR0ER6</lotID></lotIDList></carrierList><carrierList><carrierID>C00674</carrierID><carrierType>P</carrierType><lotIDList><lotID>UR0ER7</lotID></lotIDList></carrierList><carrierList><carrierID>C00682</carrierID><carrierType>C</carrierType><lotIDList><lotID>ZA0162T.01</lotID></lotIDList></carrierList><sorterJobList><jobID>WAFERSTART-C00666-C00682</jobID><lotIDList><lotID>UR0ER6</lotID><lotID>ZA0162T.01</lotID></lotIDList><origLP>LP1</origLP><destnLP>LP2</destnLP><transferSlotMap><fromTo>018-001</fromTo></transferSlotMap><origCarrier><carrierID>C00666</carrierID><lotIDList><lotID>UR0ER6</lotID></lotIDList><category>C</category><carrierType>C</carrierType><location/><mesMapping>0000000000000000011110000</mesMapping><pSlotInfo><slotList><slotId>018</slotId><waferId>UR0ER6.18</waferId></slotList></pSlotInfo><cSlotInfo><slotList><slotId>019</slotId><waferId>UR0ER6.19</waferId></slotList><slotList><slotId>020</slotId><waferId>UR0ER6.20</waferId></slotList><slotList><slotId>021</slotId><waferId>UR0ER6.21</waferId></slotList></cSlotInfo></origCarrier><destnCarrier><carrierID>C00682</carrierID><lotIDList><lotID>ZA0162T.01</lotID></lotIDList><category>C</category><carrierType>C</carrierType><location>WS</location><mesMapping>0000000000000000000000000</mesMapping><pSlotInfo/><cSlotInfo><slotList><slotId>001</slotId><waferId>ZA0162T.01</waferId></slotList><slotList><slotId>002</slotId><waferId>ZA0162T.02</waferId></slotList><slotList><slotId>003</slotId><waferId>ZA0162T.03</waferId></slotList><slotList><slotId>004</slotId><waferId>ZA0162T.04</waferId></slotList><slotList><slotId>005</slotId><waferId>ZA0162T.05</waferId></slotList></cSlotInfo></destnCarrier></sorterJobList><sorterJobList><jobID>WAFERSTART-C00674-C00682</jobID><lotIDList><lotID>UR0ER7</lotID><lotID>ZA0162T.01</lotID></lotIDList><origLP>LP1</origLP><destnLP>LP2</destnLP><transferSlotMap><fromTo>007-002</fromTo><fromTo>008-003</fromTo><fromTo>009-004</fromTo><fromTo>010-005</fromTo></transferSlotMap><origCarrier><carrierID>C00674</carrierID><lotIDList><lotID>UR0ER7</lotID></lotIDList><category>C</category><carrierType>C</carrierType><location>RR</location><mesMapping>000000111111111111110000</mesMapping><pSlotInfo><slotList><slotId>007</slotId><waferId>UR0ER7.07</waferId></slotList><slotList><slotId>008</slotId><waferId>UR0ER7.09</waferId></slotList><slotList><slotId>009</slotId><waferId>UR0ER7.09</waferId></slotList><slotList><slotId>010</slotId><waferId>UR0ER7.10</waferId></slotList></pSlotInfo><cSlotInfo><slotList><slotId>011</slotId><waferId>UR0ER7.11</waferId></slotList><slotList><slotId>012</slotId><waferId>UR0ER7.12</waferId></slotList><slotList><slotId>013</slotId><waferId>UR0ER7.13</waferId></slotList><slotList><slotId>014</slotId><waferId>UR0ER7.14</waferId></slotList><slotList><slotId>015</slotId><waferId>UR0ER7.15</waferId></slotList><slotList><slotId>016</slotId><waferId>UR0ER7.16</waferId></slotList><slotList><slotId>017</slotId><waferId>UR0ER7.17</waferId></slotList><slotList><slotId>018</slotId><waferId>UR0ER7.18</waferId></slotList><slotList><slotId>019</slotId><waferId>UR0ER7.19</waferId></slotList><slotList><slotId>020</slotId><waferId>UR0ER7.20</waferId></slotList></cSlotInfo></origCarrier><destnCarrier><carrierID>C00682</carrierID><lotIDList><lotID>ZA0162T.01</lotID></lotIDList><category>C</category><carrierType>C</carrierType><location>WS</location><mesMapping>0000000000000000000000000</mesMapping><pSlotInfo/><cSlotInfo><slotList><slotId>001</slotId><waferId>ZA0162T.01</waferId></slotList><slotList><slotId>002</slotId><waferId>ZA0162T.02</waferId></slotList><slotList><slotId>003</slotId><waferId>ZA0162T.03</waferId></slotList><slotList><slotId>004</slotId><waferId>ZA0162T.04</waferId></slotList><slotList><slotId>005</slotId><waferId>ZA0162T.05</waferId></slotList></cSlotInfo></destnCarrier></sorterJobList><lotInfo><lotId>UR0ER6</lotId><CarrierID>C00666</CarrierID><lotType>Material</lotType><trackingUnit>Lot</trackingUnit><productId>SPAW000001.0</productId><stageId>00146000M1-WAT1</stageId><planId/><planType/><subPlanId/><subPlanType/><stepSeq/><stepId/><stepType/><stepDesc/><slotMap>0000000000000000011110000</slotMap><ppParameter/><isMonitor>N</isMonitor><processState>WaitForConsume</processState><processingStatus>Inventory</processingStatus><isEngJIP>F</isEngJIP><lotPriority>1</lotPriority><lotStartDate>2022-06-01 14:00:00</lotStartDate><lotContaminationLevel>3</lotContaminationLevel><carrierContaminationFlag>C</carrierContaminationFlag><angle/><mesBatchId>MESBatchID1111</mesBatchId><jobPrepOPId>User123</jobPrepOPId><jobPrepType>Auto</jobPrepType><jobInTime>2022-10-20 15:15:30</jobInTime><lotStartTime>2022-10-20 16:30:33</lotStartTime><lotEndTime>2022-10-20 16:50:33</lotEndTime><jobOutTime>2022-10-20 16:57:38</jobOutTime></lotInfo><lotInfo><lotId>UR0ER7</lotId><CarrierID>C00674</CarrierID><lotType>Material</lotType><trackingUnit>Lot</trackingUnit><productId>SPAW000001.0</productId><stageId>00146000M1-WAT1</stageId><planId/><planType/><subPlanId/><subPlanType/><stepSeq/><stepId/><stepType/><stepDesc/><slotMap>0000001111111111111100000</slotMap><ppParameter/><isMonitor>N</isMonitor><processState>WaitForConsume</processState><processingStatus>Inventory</processingStatus><isEngJIP>F</isEngJIP><lotPriority>1</lotPriority><lotStartDate>2022-06-01 14:00:00</lotStartDate><lotContaminationLevel>3</lotContaminationLevel><carrierContaminationFlag>C</carrierContaminationFlag><angle/><mesBatchId>MESBatchID1111</mesBatchId><jobPrepOPId>User123</jobPrepOPId><jobPrepType>Auto</jobPrepType><jobInTime>2022-10-20 15:15:30</jobInTime><lotStartTime>2022-10-20 16:30:33</lotStartTime><lotEndTime>2022-10-20 16:50:33</lotEndTime><jobOutTime>2022-10-20 16:57:38</jobOutTime></lotInfo><lotInfo><lotId>ZA0162T.01</lotId><CarrierID>C00682</CarrierID><lotType>ZL</lotType><trackingUnit>Lot</trackingUnit><productId>EH0650A06B.0</productId><stageId>APSORT11.0</stageId><planId>AEEH0650A02.0</planId><planType>Normal</planType><subPlanId>AEEH0650AGAN03.0</subPlanId><subPlanType>Normal</subPlanType><stepSeq>000100.10.0100</stepSeq><stepId>APSORT11.0</stepId><stepType>ScheduledSorter</stepType><stepDesc/><slotMap>0000001111111111111100000</slotMap><ppParameter/><isMonitor>N</isMonitor><processState>WaitForJobPrep</processState><processingStatus>Active</processingStatus><isEngJIP>F</isEngJIP><lotPriority>1</lotPriority><lotStartDate>2022-06-01 14:00:00</lotStartDate><lotContaminationLevel>3</lotContaminationLevel><carrierContaminationFlag>C</carrierContaminationFlag><angle/><mesBatchId>MESBatchID1111</mesBatchId><jobPrepOPId>User123</jobPrepOPId><jobPrepType>Auto</jobPrepType><jobInTime>2022-10-20 15:15:30</jobInTime><lotStartTime>2022-10-20 16:30:33</lotStartTime><lotEndTime>2022-10-20 16:50:33</lotEndTime><jobOutTime>2022-10-20 16:57:38</jobOutTime></lotInfo></msgBody>
最新发布
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值