首页 > 编程语言 >编程一小时2023.4.14

编程一小时2023.4.14

时间:2023-04-14 20:34:05浏览次数:35  
标签:real return 14 int 编程 number Complex 2023.4 fm

1.

#include <bits/stdc++.h>
using namespace std;
class number
{
  int fz,fm;
  friend number operator+(number &n1,number &n2);
public:
  number(int a=0,int b=1)
  {
    fz=a;
    fm=b;
  }
  friend int gcd(int a,int b);
  friend int min_gb(number &n1,number &n2);
  int show()
  {
    cout<<fz;
    if(fm!=1) cout<<" "<<fm;
  }
};

int gcd(int a,int b)
{
  if(b==0) return a;
  else return gcd(b,a%b);
}

int min_gb(number &n1,number &n2)
{
  return n1.fm*n2.fm/gcd(n1.fm,n2.fm);
}

number operator+(number &n1,number &n2)
{
  number nn;
  int a=min_gb(n1,n2);
  nn.fm=a;
  nn.fz=(a/n1.fm)*n1.fz+(a/n2.fm)*n2.fz;
  int b=gcd(nn.fz,nn.fm);
  if(b!=1)
  {
    nn.fz=nn.fz/b;
    nn.fm=nn.fm/b;
  }
  return nn;
}

int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  number num1(a,b);
  number num2(c,d);
  number num3;
  num3=num1+num2;
  num3.show();
}

2.

#include "iostream"
using namespace std;
class Fu
{
public:
  double shi;
  double xv;
  void set()
  {
    cin>>this->shi;
    cin>>this->xv;
  }
  double fun1()
  {
    return this->shi;
  }
  double fun2()
  {
    return this->xv;
  }
  friend void operator>(Fu x,Fu y)
  {
    if(x.xv*x.xv+x.shi*x.shi>y.xv*y.xv+y.shi*y.shi)
    cout<<"true"<<endl;
    else
    cout<<"false"<<endl;
  }
};
int main()
{
  Fu x[1000];
  int i=0;
  while(1)
  {

    x[i].set();
    x[i+1].set();
    if(x[i].fun1() || x[i].fun2() || x[i+1].fun2() || x[i+1].fun1())
    {
      x[i]>x[i+1];
    }
    else return 0;
    i+=2;
  }
}

3.

#include<iostream>
using namespace std;
class MyTime{
private:
  int hour;
  int minute;
public:
  MyTime(int a=0, int b=0): hour(a), minute(b){};
  int operator-( const MyTime& t){
    int temp;
    temp=(t.hour-hour)*60+t.minute-minute;
    return temp;
  }
};
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(a||b||c||d){
    MyTime t1(a,b),t2(c,d);
    cout<<t1-t2<<endl;
    cin>>a>>b>>c>>d;
  }
return 0;
}

4.

#include <iostream>
using namespace std;
class Complex
{
public:
  Complex(double r=0, double i=0):real(r), imag(i){ }
  Complex operator+(Complex c) const;
  Complex operator-=(Complex c);
  friend Complex operator-(Complex c1,Complex c2) ;
  void Display() const;
private:
  double real;
  double imag;
};
Complex Complex::operator+ (Complex c)const{
c.imag=c.imag+this->imag;
c.real=c.real+this->real;
return c;
}
Complex Complex::operator-=(Complex c){
this->imag=this->imag-c.imag;
this->real=this->real-c.real;
return *this;

}
Complex operator-(Complex c1,Complex c2){
c1.imag=c1.imag-c2.imag;
c1.real=c1.real-c2.real;
return c1;
}

void Complex::Display() const
{
  cout << "(" << real << ", " << imag << ")" << endl;
}

int main()
{
  double r, m;
  cin >> r >> m;
  Complex c1(r, m);
  cin >> r >> m;
  Complex c2(r, m);
  Complex c3 = c1+c2;
  c3.Display();
  c3 = c1-c2;
  c3.Display();
  c3 -= c1;
  c3.Display();
  return 0;
}

标签:real,return,14,int,编程,number,Complex,2023.4,fm
From: https://www.cnblogs.com/zbl040721/p/17319846.html

相关文章

  • 回溯_20230414
    332.重新安排行程给定一个机票的字符串二维数组[from,to],子数组中的两个成员分别表示飞机出发和降落的机场地点,对该行程进行重新规划排序。所有这些机票都属于一个从JFK(肯尼迪国际机场)出发的先生,所以该行程必须从JFK开始。如果存在多种有效的行程,请你按字符自然排序返回最......
  • 2023.4.12拷逝
    #T1seq首先这道题要注意对题意的理解,子序列的意思是子集,而不是子区间。我们可以将序列从小到大排序。排序后,如果一个子序列只有$a[i]$,$a[j]$$(i<j)$和任意多个在$a[i]$和$a[j]$之间的数,那么这个子序列的权值就是$a[i]\timesa[j]$。这样的序列有$2^{j-i-1}$个。由此......
  • 2023.4.14
    1.问题描述:设计一个计算器程序,能够进行基本的加、减、乘、除运算。2.设计思路:程序需要输入两个数和一个运算符,根据运算符对两个数进行对应的运算,并输出结果。3.程序流程图:开始->输入第一个数->输入第二个数->输入运算符->根据运算符进行运算->输出结果->结束4.......
  • 20230414指定IP联网不通日志
    正常情况路由记录1<1毫秒<1毫秒<1毫秒192.168.0.121ms<1毫秒<1毫秒192.168.1.134ms3ms3ms100.69.64.14*3ms3ms211.138.190.1535***请求超时。626ms......
  • 每日编程一小时(第五天)
    一.问题描述输入一个整数,输出每个数字对应的拼音。当整数为负数时,先输出fu字二.设计思路1.创建一个字符数组2.输入一个字符串(数)3.利用switch来输出每一个字符所对应的读音三.流程图  四.代码实现#include<iostream>usingnamespacestd;intmain(){chara[10......
  • Nvidia Tensor Core-MMA PTX编程入门
    1PTX(ParallelThreadExecution)PTX是什么,Nvidia官方描述为alow-levelparallelthreadexecutionvirtualmachineandinstructionsetarchitecture(ISA),直面意思是低级并行线程执行虚拟机和指令集架构。怎么理解其直面意思,有两个方法。一个方法是借鉴LLVM,熟悉LLV......
  • 2023.04.14 定时测试随笔 T1
    T1P2170选学霸传送门:洛谷P2170本题考察的是并查集优化背包DP,所以我们通过并查集将\(n\)个点变成\(group\)个连通块,那么每个连通块里面的点要么都选要么都不选,状态\(dp[i]\)定义为可以选\(i\)个学霸且不会抗议,算出所有可能的结果,再枚举\(1\)~\(n\),求出最接近\(m......
  • 2023年4月14日周五
    计划完成初稿前两部分,学习CRM项目,熟悉项目的代码结构背单词记得执行09点13分  写初稿11点19分  完成论文初稿第一二章11点30分  做页码修改,开始CRM项目学习16点04分  解决新增用户16点13分  解决删除用户记录已解决问题想法GPT学习路线Java基础:......
  • 解决nvm升级node v18.14.0时/lib64/libm.so.6: version 'GLIBC_2.27' not found (requ
    安装v18.14.0时的报错和解决方法1.报错[root@devops03~/.nvm]#nvminstallv18.14.0Downloadingandinstallingnodev18.14.0...Downloadinghttps://npm.taobao.org/mirrors/node/v18.14.0/node-v18.14.0-linux-x64.tar.xz...#######################################......
  • 每日会议20230414
     进度汇报:吕金帅:张博文:自周一起到现在,完成了商品表的数据库的连接,完成了高德地图导航接口的连接,在fragment中嵌入listview展示商品收益和广告收益。遇到的问题是:不知道如何记录数据库记录改变的次数,从而进行商品数量上的变化。赵纪旭: 具体目标:要实现三方数据库的统一,我们......