我是一个小雪糕啊小雪...:泰剧:花戒指(是推哥和吉妹拍的!!!!!简直帅到不要~美到不行~)强推!!!!!!!
查看图片
查看图片0 点赞 评论 收藏
分享
全能:买车前不跑一圈?
0 点赞 评论 收藏
分享
0 点赞 评论 收藏
分享
0 点赞 评论 收藏
分享
0 点赞 评论 收藏
分享
菜鸟中的菜鸟:詹姆斯
0 点赞 评论 收藏
分享
呵呵呵哒2:个人觉得还是按比例,收入高的承担多一点。。。咦,我女朋友呢?
0 点赞 评论 收藏
分享
Booooring:勇士
0 点赞 评论 收藏
分享
牛妹备胎:建议头像换照片,顶帖的人估计就多啦,哈哈😄
0 点赞 评论 收藏
分享
0 点赞 评论 收藏
分享
全能:三观相似 性格相补
0 点赞 评论 收藏
分享
0 点赞 评论 收藏
分享
0 点赞 评论 收藏
分享
温柔小猪:import java.util.Scanner;
public class Main
{
public static boolean isLeapYear(int year)
{
return year % 100 == 0 ? year % 400 == 0 : year % 4 == 0;
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int year = 0;
while (in.hasNext())
{
year = in.nextInt();
System.out.println("请输入任意一个年份:");
if (year < 0)
{
System.out.println("输入为错误的年份");
}
else
{
if (isLeapYear(year))
System.out.println(year + "是闰年!");
else
System.out.println(year + "是平年");
}
}
in.close();
}
}
0 点赞 评论 收藏
分享
温柔小猪:/*
Problem:编写MyString的构造函数、拷贝构造函数、析构函数和赋值函数
Author:QiZhao
Data:2018-02-04
Description:
Copyright 2018 QiZhao. All rights reserved.
*/
#include<cstring>
#include<iostream>
#include<cstdlib>
using namespace std;
class MyString
{
public:
MyString (const char *str = NULL);
MyString (const MyString &other);
~ MyString(void);
MyString & operator = (const MyString & other);
friend ostream& operator<<(ostream &os, MyString &str);
private:
char *m_data;
};
//构造函数
MyString::MyString(const char *str)
{
if(str == NULL)
{
m_data = new char[1];
*m_data = '\0';
}
else
{
int len = strlen(str);
m_data = new char[len + 1];
if(m_data = NULL)
{
cout << "内存分配失败" << endl;
exit(-1);
}
strcpy(m_data, str);
}
cout << "调用构造函数" << endl;
}
//拷贝构造函数
MyString::MyString(const MyString &other)
{
int len = strlen(other.m_data);
m_data = new char[len + 1];
if(m_data = NULL)
{
cout << "内存分配失败" << endl;
exit(-1);
}
strcpy(m_data, other.m_data);
cout << "调用拷贝构造函数" << endl;
}
//析构函数
MyString::~MyString(void)
{
delete[]m_data;
m_data = NULL;
cout << "调用析构函数" << endl;
}
//赋值函数
MyString& MyString::operator= (const MyString & other)
{
if(this != &other)
{
delete[]m_data;
int len = strlen(other.m_data);
m_data = new char[len + 1];
if(m_data = NULL)
{
cout << "内存分配失败" << endl;
exit(-1);
}
strcpy(m_data, other.m_data);
}
return *this;
}
//输出
ostream& operator<<(ostream &os, MyString &str)
{
os << str.m_data;
return os;
}
int main()
{
char str[] = "abcdef";
char *p = NULL;
cout << "**********************构造函数测试**********************" << endl;
MyString test1(str);
MyString test2(p);
cout << "**********************拷贝构造函数测试**********************" << endl;
MyString test(test1);
cout << "**********************赋值函数测试**********************" << endl;
cout << "调用前:" << endl;
cout << test1 << endl;
cout << test2 << endl;
cout << "调用后:" << endl;
test2 = test1;
cout << test1 << endl;
cout << test2 << endl;
cout << "**********************析构函数测试**********************" << endl;
return 0;
}
0 点赞 评论 收藏
分享
创作者周榜
更多
关注他的用户也关注了: