当前位置: 首页 > news >正文

记事本做网站文字居中北京有限公司

记事本做网站文字居中,北京有限公司,宝安网站建设定制,做网站在哪找靠谱🎃个人专栏: 🐬 算法设计与分析:算法设计与分析_IT闫的博客-CSDN博客 🐳Java基础:Java基础_IT闫的博客-CSDN博客 🐋c语言:c语言_IT闫的博客-CSDN博客 🐟MySQL&#xff1a…

 🎃个人专栏:

🐬 算法设计与分析:算法设计与分析_IT闫的博客-CSDN博客

🐳Java基础:Java基础_IT闫的博客-CSDN博客

🐋c语言:c语言_IT闫的博客-CSDN博客

🐟MySQL:数据结构_IT闫的博客-CSDN博客

🐠数据结构:​​​​​​数据结构_IT闫的博客-CSDN博客

💎C++:C++_IT闫的博客-CSDN博客

🥽C51单片机:C51单片机(STC89C516)_IT闫的博客-CSDN博客

💻基于HTML5的网页设计及应用:基于HTML5的网页设计及应用_IT闫的博客-CSDN博客​​​​​​

🥏python:python_IT闫的博客-CSDN博客

欢迎收看,希望对大家有用!

目录

🎯第一题:

🎯 第二题:

🎯 第三题:

🎯 答案:

💻第一题:

💻第二题:

💻第三题:

🎯第一题:

设计一个复数类Complex,包含成员变量实部real和虚部imag;运算符重载+/-实现两个复数加、减的功能。在主函数里创建两个复数对象,分别求两个复数的和与差,在主函数里显示运算结果。效果如图:

🎯 第二题:

现有一学生类定义:

   class Student{

         ……..

      private:

int _id;

         string _name;

         char *_addr;

    };

实现学生类的赋值运算符=重载,主函数调用赋值运算符并输出对象信息。

🎯 第三题:

编写一个程序,声明一个2行2列矩阵类Matrix,重载运算符“+”,使之能用于矩阵的加法运算。重载流插入运算符“<<”和流提取运算符“>>”,使之能用于该矩阵的输入与输出。从键盘输入两个矩阵a和b,求两个矩阵之和并输出。效果如图:

 

🎯 答案:

💻第一题:

#include <iostream>using namespace std;class Complex {private:double real;double imag;public:Complex(double x=0,double y=0):real(x),imag(y) {}void show() const; //输出数据friend Complex operator+(const Complex& a1, const Complex& a2) ; //重载为类的友元函数friend Complex operator-(const Complex& a1, const Complex& a2);//重载为类的友元函数};/******************************************************************/void Complex::show() const {if(imag>=0)cout<<real<<"+"<<imag<<"i"<<endl;elsecout<<real<<imag<<"i"<<endl;}Complex operator+(const Complex& a1,const Complex& a2) {return Complex(a1.real+a2.real,a1.imag+a2.imag);}Complex operator-(const Complex& a1,const Complex& a2) {return Complex(a1.real-a2.real,a1.imag-a2.imag);}/******************************************************************/int main() {Complex c1(5.1,3.4);Complex c2(3.6,5.3);Complex c;cout<<"c1:";c1.show();cout<<"c2:";c2.show();c=c1+c2;cout<< "c1+c2:";c.show();c=c1-c2;cout<<"c1-c2:";c.show();return 0;}

💻第二题:

#include <iostream>#include <cstring>using namespace std;class Student {private:int _id;string _name;char *_addr;public:Student(int id,string name,const char *addr);Student();Student& operator=(Student& stu);void show();};Student::Student() {}Student::Student(int id,string name,const char *addr) {/******************************************/ _id=id;_name=name;this->_addr=new char[strlen(addr)+1];if(_addr)     strcpy(_addr,addr);/******************************************/ }Student& Student::operator=(Student& stu) {//注意深拷贝/******************************************/ _id=stu._id;_name=stu._name;_addr=new char[strlen(stu._addr)+1];if(_addr)     strcpy(_addr,stu._addr);return *this;/******************************************/ }void Student::show() {cout<<"学号:"<<_id<<endl;cout<<"姓名:"<<_name<<endl;cout<<"住址:"<<_addr<<endl;}int main() {Student stu2,stu1(10001,"zhangsan","luoyang");stu1.show();stu2=stu1;stu2.show();return 0;}

💻第三题:

#include <iostream>#include <iomanip>using namespace std;class Matrix {private:int a[2][2];friend istream& operator>>(istream& is,Matrix& _m);friend ostream& operator<<(ostream& os,Matrix& _m);friend Matrix  operator+(const Matrix& mat1,const Matrix& mat2);};ostream& operator<<(ostream& os,Matrix& _m) {//每个数4列 setw(4)for(int i=0; i<2; i++) {for(int j=0; j<2; j++)os<<setw(4)<<_m.a[i][j];os<<endl;}return os;}/****************************************************/istream& operator>>(istream& is,Matrix& _m) {for(int i=0; i<2; i++)for(int j=0; j<2; j++)is>>_m.a[i][j];return is;}Matrix  operator+(const Matrix& mat1,const Matrix& mat2) {Matrix mat;for(int i=0; i<2; i++)for(int j=0; j<2; j++) {mat.a[i][j]=mat1.a[i][j]+mat2.a[i][j];}return mat;}/****************************************************/int main() {Matrix m1,m2,m;cout<<"input matrix m1:"<<endl;cin>>m1;cout<<"input matrix m2:"<<endl;cin>>m2;m=m1+m2;cout<<"output matrix m:"<<endl;cout<<m;return 0;}
http://www.hkea.cn/news/122265/

相关文章:

  • 黑龙江企业信息系统seo推广优化外包公司
  • wordpress+增加域名赣州网站seo
  • 政府门户网站建设思路怎样优化网络
  • 厦门个人网站建设百度账户代运营
  • 企业网站开发注意什么企业网站官网
  • 网站建设开发合同书关键词怎么找出来
  • 常州微信网站建设附子seo
  • 上海网站seo招聘十种营销方式
  • 农产品网络营销模式百度推广怎么优化
  • 公司网站维护如何做分录自己搭建一个网站
  • 做期货浏览哪些网站网络优化工程师前景如何
  • 垂直b2b电子商务网站有哪些google搜索排名优化
  • 建设中网站源码网络推广工具和方法
  • 厦门做点击付费网站培训教育
  • 常州网站建设案例网站制作建设公司
  • 外国人做家具的网站一站传媒seo优化
  • 佛山h5建站模板怎样优化网站
  • 第三方做公司网站谷歌搜索广告优化
  • 网站风格模板快速排名精灵
  • 做网站横幅 的网站推荐几个公司推广
  • html5国内网站建设客户管理软件
  • 网站建设报价单站长工具 seo查询
  • 日本电商网站贵州快速整站优化
  • 物业服务网站建设建立网站要多少钱一年
  • 中铁建设门户加长版廊坊百度提升优化
  • 最便宜的外贸网站建设电商平台运营方案
  • 做网站应该会什么问题网络营销软文范例500字
  • 摄影网课百度关键词优化查询
  • 打广告型的营销网站西安百度推广外包
  • 乌鲁木齐招聘网站建设一站式网络营销