需要程序帮助 [英] need help with program

查看:68
本文介绍了需要程序帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力编写一个小时的程序。

要求是:"""您将编写一个程序,它将确定日期是否有效

那个月的日期。我们假设年份将是

有效的4位整数。

所以你不必考虑那个(在验证方面)

除了月份
2月份的b $ b。如果月份是2月,那么你必须在检查日期之前检查那一年是否是闰$

年。

创建一个类叫Date。包括三个私有变量:date,

month and year

(声明为int类型)。包括以下成员函数:

1.构造函数日期(月份,日期,年份),它将初始化日期,

month和

year具有用户指定值的对象。

2. valid_Date():它将确定日期是有效还是

not。""

那我们必须使用switch语句进行月份验证。

我有以下内容:


" Date.h"

#include< iostream>


班级日期

{

public:

Date(int,int,int);

void valid_Date();


private:

int month ,日期,年份;

};



" Date.cpp"


#include< iostream>

#include< string>

使用命名空间std;



#include" Date.h"


Date :: Date(int n1,int n2,int n3)


{

if(n1> ; 0&& n1< = 12)

month = n1;

else {

month = 1;

cout< ;< 月 << n1<< "无效。;

}


date = n2;

year = n3;


cout<<结束;

}


无效日期:: valid_Date()

{



if(month = 02)

{

if(year%2 == 0)

cout << 你的约会对象是什么时候 <<月<<日期<<年<<结束;

}

其他

cout<< 你的约会对象无效! <<结束;


}


int main(无效)

{

int m,d,y;

char ch;


cout<< 输入日期为dd / mm / yy:" ;;

cin>> d>> ch>> m>> ch>> y;


开关(月){

案例1:cout<< " 1英寸;休息;

案例2:cout<< "二月英寸;休息;

案例3:cout<< "三月英寸;休息;

案例4:cout<< " 4月英寸;休息;

案例5:cout<< "五月英寸;休息;

案例6:cout<< " 6月英寸;休息;

案例7:cout<< " 7月英寸;休息;

案例8:cout<< " 8月英寸;休息;

案例9:cout<< 九月;休息;

案例10:cout<< " 10月英寸;休息;

案例11:cout<< "十一月英寸;休息;

案例12:cout<< "腊英寸;休息;

}

返回0;

}


我的思绪徘徊,尝试了多种不同的接近......然后我结束了这个废话...
可以帮助我让程序正常工作

放在上面......谢谢!

Hi, I have been struggling with writing a program for a few hours. The
requirements are that: """You will be writing a program which will
determine whether a date is valid in
terms of days in that month. We are assuming that the year will be
valid 4 digit integer.
So you don''t have to think much about that(in terms of validation)
except for the month
of February. If the month is February, then you have to check whether
that year is Leap
year or not before checking the date.
Create a class called Date. Include three private variables : date,
month and year
(declare as int type). Include following member functions:
1. A constructor Date(month. date, year)which will initialize the date,
month and
year of the object with user specified values.
2. valid_Date(): which will determine whether the date is valid or
not."""
That and we have to use a switch statement for the month validation.
I have the following:

"Date.h"
#include<iostream>

class Date
{
public:
Date(int,int,int);
void valid_Date();

private:
int month,date,year;
};



"Date.cpp"

#include <iostream>
#include<string>
using namespace std;


#include "Date.h"

Date::Date(int n1,int n2, int n3)

{
if ( n1 > 0 && n1 <= 12 )
month = n1;
else {
month = 1;
cout << "Month " << n1 << " invalid.";
}

date = n2;
year = n3;

cout << endl;
}

void Date::valid_Date()
{



if (month = 02)
{
if (year%2 == 0)
cout << "Your date is " << month << date << year << endl;
}
else
cout << "Your date is invalid!" << endl;

}

int main(void)
{
int m, d, y;
char ch;

cout << "Input a date as dd/mm/yy: ";
cin >> d >> ch >> m >> ch >> y;

switch (month) {
case 1: cout << "January"; break;
case 2: cout << "February"; break;
case 3: cout << "March"; break;
case 4: cout << "April"; break;
case 5: cout << "May"; break;
case 6: cout << "June"; break;
case 7: cout << "July"; break;
case 8: cout << "August"; break;
case 9: cout << "September";break;
case 10: cout << "October"; break;
case 11: cout << "November"; break;
case 12: cout << "December"; break;
}
return 0;
}

My mind wandered and tried multiple different approaches..and I ended
up with that crap...can some1 help me make the program work to the reqs
placed above..thanks!

推荐答案

< vg ***** @ gmail.com>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com
<vg*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com
我一直在努力编写一个程序几个小时。
要求是:"您将编写一个程序,用于确定日期是否在该月的日期有效。我们假设年份将是有效的4位整数。
所以你不必考虑那个(在验证方面)
除了月份二月如果月份是2月份,那么在检查日期之前你必须检查那年是否是Leap
年份。
创建一个名为Date的类。包括三个私有变量:date,
month和year
(声明为int类型)。包括以下成员函数:
1.构造函数日期(月份,日期,年份),它将使用用户指定的值初始化对象的日期,月份和年份。
2. valid_Date():它将确定日期是有效还是
不是。""
那我们必须使用switch语句进行月份验证。

我有以下内容:

" Date.h"
#include< iostream>

班级日期
{
public:
Date(int,int,int);
void valid_Date();

private:
int month,date,year;
} ;


" Date.cpp"

#include< iostream>
#include< string>
using namespace std;

#include" Date.h"

Date :: Date(int n1,int n2,int n3)

{
if(n1> 0&& n1< = 12)
month = n1;
else {
month = 1 ;
cout<< 月 << n1<< "无效。  

无效日期::

= 02)


您已完成作业,未检查是否相等。

{
if(year%2 == 0)


这只是检查一年。没有必要这样做。

cout<< 你的约会对象是什么时候 <<月<<日期<<年<< endl;
}
其他
cout<< 你的约会对象无效! << endl;

}
int main(无效)
{m / d,y;

char ch ;

cout<< 输入日期为dd / mm / yy:";
cin>> d>> ch>> m>> ch>> y;

开关(月){
案例1:cout<< " 1英寸;休息;
案例2:cout<< "二月英寸;休息;
案例3:cout<< "三月英寸;休息;
案例4:cout<< " 4月英寸;休息;
案例5:cout<< "五月英寸;休息;
案例6:cout<< " 6月英寸;休息;
案例7:cout<< " 7月英寸;休息;
案例8:cout<< " 8月英寸;休息;
案例9:cout<< 九月;休息;
案例10:cout<< " 10月英寸;休息;
案例11:cout<< "十一月英寸;破裂;
案例12:cout<< "腊英寸;休息;
}

返回0;
}

我的思绪徘徊,尝试了多种不同的方法......我结束了
那个废话...可以帮助我让程序工作到上面的
请求...谢谢!
Hi, I have been struggling with writing a program for a few hours. The
requirements are that: """You will be writing a program which will
determine whether a date is valid in
terms of days in that month. We are assuming that the year will be
valid 4 digit integer.
So you don''t have to think much about that(in terms of validation)
except for the month
of February. If the month is February, then you have to check whether
that year is Leap
year or not before checking the date.
Create a class called Date. Include three private variables : date,
month and year
(declare as int type). Include following member functions:
1. A constructor Date(month. date, year)which will initialize the
date, month and
year of the object with user specified values.
2. valid_Date(): which will determine whether the date is valid or
not."""
That and we have to use a switch statement for the month validation.
I have the following:

"Date.h"
#include<iostream>

class Date
{
public:
Date(int,int,int);
void valid_Date();

private:
int month,date,year;
};



"Date.cpp"

#include <iostream>
#include<string>
using namespace std;


#include "Date.h"

Date::Date(int n1,int n2, int n3)

{
if ( n1 > 0 && n1 <= 12 )
month = n1;
else {
month = 1;
cout << "Month " << n1 << " invalid.";
}

date = n2;
year = n3;

cout << endl;
}

void Date::valid_Date()
{



if (month = 02)
You have made an assignment, not checked for equality.
{
if (year%2 == 0)
This just checks for an even year. No point in doing that.
cout << "Your date is " << month << date << year << endl;
}
else
cout << "Your date is invalid!" << endl;

}

int main(void)
{
int m, d, y;
char ch;

cout << "Input a date as dd/mm/yy: ";
cin >> d >> ch >> m >> ch >> y;

switch (month) {
case 1: cout << "January"; break;
case 2: cout << "February"; break;
case 3: cout << "March"; break;
case 4: cout << "April"; break;
case 5: cout << "May"; break;
case 6: cout << "June"; break;
case 7: cout << "July"; break;
case 8: cout << "August"; break;
case 9: cout << "September";break;
case 10: cout << "October"; break;
case 11: cout << "November"; break;
case 12: cout << "December"; break;
}
return 0;
}

My mind wandered and tried multiple different approaches..and I ended
up with that crap...can some1 help me make the program work to the
reqs placed above..thanks!




你完成了大部分的工作。两个建议。


1.而不是


月,日,年;


制作


int月,日,年;


ie,按日替换日期,这样就不会在两个不同的日期中使用日期

感觉。


2.您需要验证提供的日期是< =

月的天数。因此你的switch语句应该设置一个maxDays变量。

-

John Carson



You have done most of the work. Two suggestions.

1. Instead of

int month,date,year;

make it

int month,day,year;

i.e., replace date by day so that you are not using date in two different
senses.

2. You need to verify that the day supplied is <= the number of days in the
month. Thus your switch statement should be setting a maxDays variable.
--
John Carson


2。您需要验证提供的日期是< =

月的天数。因此你的switch语句应该设置一个maxDays变量。

我很抱歉,如果这很明显......但是我的大脑在这个时候已经死了......怎么回事
我这样做了吗?


非常感谢你的帮助

2. You need to verify that the day supplied is <= the number of days in
the
month. Thus your switch statement should be setting a maxDays variable.
I am sorry if this is obvious...but my brain is dead at this hour...how
do I go about doing that?

Thanks so much for the help


哦,一旦我这样做了。 ......它会识别我所拥有的条件

陈述......因为现在,当我运行程序时......它问我

输入数据......然后结束...... ^ _~

Oh and once I do this....will it recognize the conditions i have
stated...because as of right now, when I run the program....It asks me
to input the data...and then it ends...^_~


这篇关于需要程序帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆