首页 > 其他分享 >每日打卡一小时

每日打卡一小时

时间:2023-04-12 20:46:35浏览次数:32  
标签:return cout int fenshu 每日 ++ operator 小时 打卡

//#include<iostream>
//#include<cmath>
//using namespace std;
//class fenshu
//{
//private:
// int x, y;
//public:
// fenshu(int x=1 , int y=1 )
// {
// this->x = x, this->y = y;
// if (x == 0 && y != 0)
// {
// cout << "0";
// }
// if (y == 0)
// {
// cout << "错误";
// }
// }
// void huajian()
// {
// int m, n; int z; int count=0;
// m = fabs(x), n = fabs(y); z = m < n ? m : n; int q = 0;
// if (x == 0 && y != 0)
// {
// cout << "0";
// }
// if (y == 0)
// {
// cout << "错误";
// }
// else
// {
// while (count != 1)
// {
// count = 0;
// for (int i = 1; i <= z; i++)
// {
// if (m % i == 0 && n % i == 0)
// {
// count++;
//
// q = i;
//
// }
// }
// m = m / q;
// n = n / q;
// z = m < n ? m : n;
// }
// }
// if (x * y > 0)
// {
// if (n == 1)
// {
// cout << m<<endl;
// }
// else
// {
// cout << m << "/" << n << endl;
// }
// }
// if (x * y < 0)
// {
// if (n == 1)
// {
// cout << -m<<endl;
// }
// else
// {
// cout << -m << "/" << n << endl;
// }
// }
//
// }
// void display()
// {
// cout << x << "/" << y << endl;
// }
// friend istream& operator>>(istream&, fenshu&);
// friend ostream& operator<<(ostream&, fenshu&);
// fenshu operator+(fenshu A);
// fenshu operator-(fenshu A);
// fenshu operator*(fenshu A);
// bool operator==(fenshu A);
// bool operator!=(fenshu A );
// bool operator>=(fenshu A);
// bool operator<=(fenshu A);
//};
//istream& operator>>(istream& input, fenshu& A)
//{
// input >> A.x >> A.y;
// return input;
//}
//ostream& operator<<(ostream& output, fenshu& A)
//{
// output << A.x << A.y;
// return output;
//}
//fenshu fenshu::operator+(fenshu A)
//{
// return fenshu(this->x * A.y + A.x * this->y, this->y * A.y);
//}
//fenshu fenshu::operator-(fenshu A)
//{
// return fenshu((this->x * A.y - A.x * this->y), this->y * A.y);
//}
//fenshu fenshu::operator*(fenshu A)
//{
// return fenshu(this->x * A.x, this->y * A.y);
//}
//bool fenshu::operator==(fenshu A)
//{
// if (A.x* this->y == A.y *this->x)
// {
// return true;
// }
// else
// {
// return false;
// }
//}
//bool fenshu::operator!=(fenshu A)
//{
// if (A.x*this->y!= A.y* this->x)
// {
// return true;
// }
// else
// {
// return false;
// }
//}
//bool fenshu::operator>=(fenshu A)
//{
// if (A.x * this->y == A.y * this->x||A.x*this->y> A.y * this->x)
// {
// return true;
// }
// else
// {
// return false;
// }
//}
//bool fenshu::operator<=(fenshu A)
//{
// if (A.x *this->y == A.y * this->x|| A.x * this->y < A.y * this->x)
// {
// return true;
// }
// else
// {
// return false;
// }
//}
//int main()
//{
// fenshu a1, a2, a3, a4, a5; int a, b, c, d;
// cin >> a1>>a2;
// a1.huajian();
// a3 = a1 + a2;
// a3.huajian();
// a5 = a1 * a2;
// a5.huajian();;
// a4 = a1 - a2;
// a4.huajian();
// cout<<(a1 == a2);
// cout << endl;
// cout<<(a1 != a2);
// cout << endl;
// cout<<(a1 <= a2);
// cout << endl;
// cout<<(a1 >= a2);
// return 0;
//}
#include<iostream>
using namespace std;
class Clock
{
private:
int h, m, s;
public:
Clock(int h = 0, int m = 0, int s = 0)
{
if (0 <= h&& h< 24 && 0 <= m &&m< 60 && 0 <= s &&s< 60)
{
this->h = h, this->m = m, this->s = s;
}
else
{
cout << "Time Error";
}
}
void display()
{
cout << h << ":" << m << ":" << s<<endl;
}
Clock operator++();
Clock operator++(int);
};
Clock Clock::operator++()
{
s++;
if (s >= 60)
{
s -= 60;
m++;
if (m >= 60)
{
m -= 60;
h = (h + 1) % 24;
}
}
return *this;
}
Clock Clock::operator++(int)
{
Clock old = *this;
++(*this);
return old;
}
int main()
{
Clock myclock(23, 59, 59);
myclock.display();
(myclock++).display();
(++myclock).display();

return 0;
}

总结:<<>>需用友元&istream&ostream&

+,-,*类内,友元都可

++,++(int)都可

==,<=,>=,!=要用bool,retuen true,fasle

标签:return,cout,int,fenshu,每日,++,operator,小时,打卡
From: https://www.cnblogs.com/zhaoqianwan/p/17311153.html

相关文章

  • 打卡第一天
    百钱百鸡问题:#include<iostream>usingnamespacestd;intmain(){ intx,y,z; for(intx=0;x<21;x++){ for(inty=0;y<34;y++){ for(intz=0;z<101;z++){ if(x*5+y*3+z/3.0==100&&x+y+z==100) printf("%d%d%d\n",x,y,z); } } } ......
  • 英语每日(4.12)
    commissondiscriminationarchitectchancellorpromptdiscardtuitionverbalsubscribeprescribeascribereluctantsolecomplycoordinateaccommodateobligecommoditygarmentconstarinconvictthesisunchartedcharteressenceanti......
  • c++基础 打卡1
    一、面向对象的编程语言有的特点。    ①面向对象的编程语言最大的特点是结构化程序,二结构化程序的设计思路是自顶向下、逐步求精;其程序化结构是按功能划分为若干个基本模块,这些模块形成一个树状结构;各模块之间的关系尽可能简单,在功能上相对独立;每个模块内部均是由顺序、......
  • c++ 打卡第三天
    2023-04-12百钱百鸡问题一、问题描述。    一只公鸡值五钱,一只母鸡值三钱,三只小鸡值一钱,我可以通过三种鸡各买多少实现100钱买一百只鸡。二、设计思路。    ①通过以上题我们可以确定两个方程式      公鸡数量+母鸡数量+小鸡数量=100。   ......
  • 每日总结-23.4.12
    <%@pageimport="zhengcechaxun.Pd_zhengce"%><%@pageimport="zhengcechaxun.Thesql"%><%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%>&......
  • 第一天打卡第三个问题
    问题描述:第一个人用10%的单利投资了100美元。第二个人用5%复利投资了100美元。请编写一个程序,计算多少年后第二个人的投资价值会超过第一个人的投资价值,并显示此时两个人的投资价值。解决思路:1.先建立两个变量用于存储第一个人和第二个人的投资价值2.建立一个循环体,在循环体......
  • 第一天打卡的第一个问题
    问题描述:编写一个程序计算两个整数之间所有整数(包含这两个整数)的和。假设先输入较小的整数,假设整数都是不超过int。解决思路:1.先定义两个变量,存储输入的上限和下限。2.循环从下限到上限加和3.输出。代码:#include<iostream>usingnamespacestd;intmain(){intmin,m......
  • 天天打卡一小时第一天
    1.问题描述实验1-1用天平找小球三个球A、B、C,大小形状相同且其中有一个球与其他球重量不同。要求找出这个不一样的球。输入格式:输入在一行中给出3个正整数,顺序对应球A、B、C的重量。输出格式:在一行中输出唯一的那个不一样的球。输入样例:112输出样例:C2.设计思路代码......
  • 每日一练 | 华为认证真题练习Day6
    1.以下关于静态路由说法错误的是?A.通过网络管理员手动配置B.路由器之间需要交互路由信息C.不能自动适应网络拓扑的变化D.对系统性能要求低2.以下哪个命令可以查看OSPF是否已经正确建立邻居关系?A.displayospfneighborB.displayospfbriefC.displayospfpeerD.displayo......
  • 每日一练 | 华为认证真题练习Day7
    1.下列描述正确的是()。A.路由表中下一跳是多余的,有出接口就可以指导报文转发B.通过不同路由协议获得的路由,其优先级也不相同C.不同路由协议所定义的度量值不具有可比性D.不同路由协议所定义的度量值具有可比性2.iproute-static10.0.2.2255.255.255.25510.0.12.2preference......