From 23228108dfc3bd93dd9304111916fc165fce641e Mon Sep 17 00:00:00 2001 From: Francis <455954986@qq.com> Date: Sun, 10 Apr 2022 17:39:19 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E8=BE=93=E5=85=A5=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E8=BF=90=E7=AE=97=E7=AC=A6=E9=87=8D=E8=BD=BD.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../key_exercises/输入输出运算符重载.cpp | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/practical_exercises/key_exercises/输入输出运算符重载.cpp b/practical_exercises/key_exercises/输入输出运算符重载.cpp index e44834d..e901654 100644 --- a/practical_exercises/key_exercises/输入输出运算符重载.cpp +++ b/practical_exercises/key_exercises/输入输出运算符重载.cpp @@ -1,39 +1,41 @@ /* - һԱSalesݳԱname֤idage - /ʵֶSalesݳԱ -*/ -#include -#include + 有一销售人员类Sales,其数据成员有姓名name,身份证号id,年龄age。 + 重载输入/输出运算符实现对Sales类数据成员的输入和输出。 + */ +#include +#include +using namespace std; class Sales{ -private: - char name[10]; - char id[18]; - int age; -public: - Sales(char *Name,char *ID,int Age); + private: + char name[10]; + char id[18]; + int age; + public: + Sales(char *Name,char *ID,int Age); - friend Sales &operator<<(ostream &os,Sales &s); // - friend Sales &operator>>(istream &is,Sales &s); // + friend Sales &operator<<(ostream &os,Sales &s); //重载输出运算符 + friend Sales &operator>>(istream &is,Sales &s); //重载输入运算符 }; Sales::Sales(char *Name,char *ID,int Age) { - strcpy(name,Name); - strcpy(id,ID); - age=Age; + strcpy(name,Name); + strcpy(id,ID); + age=Age; } Sales& operator<<(ostream &os,Sales &s) { - os<>(istream &is,Sales &s) { - cout<<"Ա֤ţ"<>s.name>>s.id>>s.age; - return s; + cout<<"输入雇员的姓名,身份证号,年龄"<>s.name>>s.id>>s.age; + return s; } -void main(){ - Sales s1("ſ","214198012111711",40); //L1 - cout<>s1; //L4 - cout<>s1; //L4 + cout<