找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 813|回复: 9

[求助]又麻烦一下大家,一个小问题

[复制链接]
发表于 2009-11-6 01:55:09 | 显示全部楼层 |阅读模式 IP:江苏扬州
我想定义一个年份:int year;
然后:cin>>year;//1998
最后我想抽取世纪数以及年份数,该怎样做?
例如:在上面分别提取19世纪和98年。
发表于 2009-11-6 01:55:10 | 显示全部楼层 IP:江苏扬州
int year,shiji,nianfen;
cin>>year;
shiji=year/100;
nianfen=year-shiji*100;
我也不知道对不对 我是这么想的 希望可以帮到你
回复

使用道具 举报

发表于 2009-11-6 01:55:11 | 显示全部楼层 IP:江苏扬州
LS okok!^_^
回复

使用道具 举报

发表于 2009-11-6 01:55:12 | 显示全部楼层 IP:江苏扬州
学着学着就糊涂了,原来这样```。
年份那也可以year%100;晕死。
回复

使用道具 举报

发表于 2009-11-6 01:55:13 | 显示全部楼层 IP:江苏扬州
还请教一下,下面错在哪?

#include <iostream>
#include <string>
using namespace std;
class Month
{
public:
Month(){};
Month(string month,int day,int year);
string getMonth()const;
int getDay()const;
int getYear()const;
private:
string TheMonth;
int TheDay,
TheYear;
};
Month::Month(string month,int day,int year)
{
string TheMonth=month;
int TheDay=day,
TheYear=year;
}
inline string Month::getMonth()const
{
if (TheMonth=="March")
return 1;
else if(TheMonth=="April")
return 2;
else if(TheMonth=="May")
return 3;
else if(TheMonth=="June")
return 4;
else if(TheMonth=="July")
return 5;
else if(TheMonth=="August")
return 6;
else if(TheMonth=="September")
return 7;
else if(TheMonth=="October")
return 8;
else if(TheMonth=="November")
return 9;
else if(TheMonth=="DeceMber")
return 10;
else if(TheMonth=="January")
return 11;
else if(TheMonth=="February")
return 12;
}

错误信息:error C2664: '__thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(co
nst class std::allocator<char> &)' : cannot convert parameter 1 from 'const int' to 'const class std::allocator<char> &'
Reason: cannot convert from 'const int' to 'const class std::allocator<char>'
No constructor could take the source type, or constructor overload resolution was ambiguous
回复

使用道具 举报

发表于 2009-11-6 01:55:14 | 显示全部楼层 IP:江苏扬州
返回类型啊

return的int,怎么又string?
呵呵~
回复

使用道具 举报

发表于 2009-11-6 01:55:16 | 显示全部楼层 IP:江苏扬州
郁闷死了。太粗心了。
谢谢啦
回复

使用道具 举报

发表于 2009-11-6 01:55:18 | 显示全部楼层 IP:江苏扬州
很郁闷,又有点小问题了,帮忙找下 呵呵。
类文件:
#include <iostream>
#include <string>
using namespace std;
class Month
{
public:
Month(){};
Month(string month,int day,int year);
int getMonth()const;
int getDay()const;
int getYear()const;
int YearMonthDay()const;
void print(ostream& out)const;
private:
string TheMonth;
int TheDay,
TheYear;
};
Month::Month(string month,int day,int year)
{
string TheMonth=month;
int TheDay=day,
TheYear=year;
}
inline int Month::getMonth()const
{
if (TheMonth=="March")
return 1;
else if(TheMonth=="April")
return 2;
else if(TheMonth=="May")
return 3;
else if(TheMonth=="June")
return 4;
else if(TheMonth=="July")
return 5;
else if(TheMonth=="August")
return 6;
else if(TheMonth=="September")
return 7;
else if(TheMonth=="October")
return 8;
else if(TheMonth=="November")
return 9;
else if(TheMonth=="DeceMber")
return 10;
else if(TheMonth=="January")
return 11;
else if(TheMonth=="February")
return 12;
}
inline int Month::getDay()const
{
return TheDay;
}
inline int Month::getYear()const
{
return TheYear;
}
inline int Month::YearMonthDay()const
{
return getYear()+' '
+getMonth()+' '
+getDay();
}
inline void Month::print(ostream& out)const
{
cout<< getYear()+' '
+getMonth()+' '
+getDay();
}

/*****************************/
驱动程序:
#include<iostream>
#include<string>
#include"Month.h"
using namespace std;
void main()
{
Month year("May",23,1998);
cout <<year.YearMonthDay <<endl;
}

/**************************/
警告信息:
D:\学习软件\c++1\MSDev98\MyProjects\类深入\类.cpp(8) : warning C4761: integral size mismatch in argument; conversion supplied
d:\学习软件\c++1\msdev98\myprojects\类深入\month.h(54) : warning C4715: 'Month::getMonth' : not all control paths return a value
Linking...
/********************************/
为什么我的驱动程序怎样改,最后结果都是:1
回复

使用道具 举报

发表于 2009-11-6 01:55:19 | 显示全部楼层 IP:江苏扬州
价格括号。。。year.YearMonthDay()
回复

使用道具 举报

发表于 2009-11-6 01:55:20 | 显示全部楼层 IP:江苏扬州
Month::getMonth()
最后加一个else return 0;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-10-1 19:37 , Processed in 0.202777 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表