| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2188 人关注过本帖
标题:[求助]又麻烦一下大家,一个小问题
只看楼主 加入收藏
a8451727
Rank: 1
等 级:新手上路
帖 子:238
专家分:5
注 册:2007-5-22
结帖率:86.67%
收藏
 问题点数:0 回复次数:20 
[求助]又麻烦一下大家,一个小问题
我想定义一个年份:int year;
然后:cin>>year;//1998
最后我想抽取世纪数以及年份数,该怎样做?
例如:在上面分别提取19世纪和98年。
搜索更多相关主题的帖子: 年份 麻烦 year 定义 
2007-06-07 21:00
knm110
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-6-7
收藏
得分:0 
int year,shiji,nianfen;
cin>>year;
shiji=year/100;
nianfen=year-shiji*100;
我也不知道对不对 我是这么想的 希望可以帮到你
2007-06-07 21:38
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 
LS okok!^_^

Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2007-06-07 22:09
a8451727
Rank: 1
等 级:新手上路
帖 子:238
专家分:5
注 册:2007-5-22
收藏
得分:0 
学着学着就糊涂了,原来这样```。
年份那也可以year%100;晕死。

2007-06-07 22:29
a8451727
Rank: 1
等 级:新手上路
帖 子:238
专家分:5
注 册:2007-5-22
收藏
得分:0 

还请教一下,下面错在哪?

#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


2007-06-07 22:32
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
收藏
得分:0 
返回类型啊

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

Fight  to win  or  die...
2007-06-07 22:43
a8451727
Rank: 1
等 级:新手上路
帖 子:238
专家分:5
注 册:2007-5-22
收藏
得分:0 

郁闷死了。太粗心了。
谢谢啦


2007-06-07 22:55
a8451727
Rank: 1
等 级:新手上路
帖 子:238
专家分:5
注 册:2007-5-22
收藏
得分:0 

很郁闷,又有点小问题了,帮忙找下 呵呵。
类文件:
#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


2007-06-07 23:30
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 
价格括号。。。year.YearMonthDay()

[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2007-06-07 23:58
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 
Month::getMonth()
最后加一个else return 0;

[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2007-06-08 00:00
快速回复:[求助]又麻烦一下大家,一个小问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017070 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved