Ada I';我正在编写一个程序,检查给定日期的;正确性”;。我哪里出错了?
这是我的程序,但我觉得我的语法只有一个主要问题,我想不出来Ada I';我正在编写一个程序,检查给定日期的;正确性”;。我哪里出错了?,ada,Ada,这是我的程序,但我觉得我的语法只有一个主要问题,我想不出来 with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Float_Text_IO; use Ada.Float_Text_IO; procedure Project_3 is -----------------------------------------------------------
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;
with Ada.Float_Text_IO;
use Ada.Float_Text_IO;
procedure Project_3 is
-------------------------------------------------------------------------
-- Haleigh Graham
-- 02/26/2015
--
--
--
--
--
--
-------------------------------------------------------------------------
type Day_28 is array (1..28) of Natural;
type Day_29 is array (1..29) of Natural;
type Day_30 is array (1..30) of Natural;
type Day_31 is array (1..31) of Natural;
Date_Input : String (1 .. 10);
Month : constant String := Date_Input (1 .. 2);
Day : constant String := Date_Input (4 .. 5);
Year : constant String := Date_Input (7 .. 10);
Valid_Date : Boolean := False;
Valid_Month : Boolean :=False;
type Long_Month is array (1..31) of Natural;
type Short_Month is array (1..30) of Natural;
Index : Positive;
-- Is_February function
function Is_February (Month : in integer) return Boolean is
begin
if Month = 2 then
return True;
else
return False;
end if;
end Is_February;
-- Is_Leap_Year function
function Is_Leap_Year (Year : in integer) return boolean is
begin -- Is_Leap_Year
if Year rem 100 = 0 then
if Year rem 400 = 0 then
return true;
else
return false;
end if;
else
if Year rem 4 = 0 then
return true;
else
return false;
end if;
end if;
end Is_Leap_Year;
-- Is_Valid_Day_31 function
function Is_Valid_Day_31 (Day : in Integer) return Boolean is
begin -- Is_Valid_Day_31
if Day = Day_31 then
return true;
else
return False;
end if;
end Is_Valid_Day_31;
-- Is_Valid_Day_30 function
function Is_Valid_Day_30 (Day : in Integer) return Boolean is
begin -- Is_Valid_Day_30
if Day = Day_30 then
return true;
else
return False;
end if;
end Is_Valid_Day_30;
-- Is_Valid_Day_29 function
function Is_Valid_Day_29 (Day : in Integer) return Boolean is
begin -- Is_Valid_Day_29
if Day = Day_29 then
return true;
else
return False;
end if;
end Is_Valid_Day_29;
-- Is_Valid_Day_28 function
function Is_Valid_Day_28 (Day : in Integer) return Boolean is
begin -- Is_Valid_Day_28
if Day = Day_28 then
return true;
else
return False;
end if;
end Is_Valid_Day_28;
-- Is_Valid_Year function
function Is_Valid_Year (Year : in Integer) return Boolean is
begin -- Is_Valid_Year
if Year > 1700 and Year < 2300 then
return true;
else
return False;
end if;
end Is_Valid_Year;
-- Is_Long_Month function
function Is_Long_Month (Month : in Integer) return Boolean is
begin -- Is_Long_Month function
if Month = Long_Month(Integer) then
return True;
else
return False;
end if;
end Is_Long_Month;
-- Is_Short_Month function
function Is_Short_Month (Month : in Integer) return Boolean is
begin -- Is_Short_Month function
if Month = Short_Month(Integer) then
return True;
else
return False;
end if;
end Is_Short_Month;
-- Main Program
begin
Ada.Text_IO.Put ( "Enter the date you wish to check (MM/DD/YYYY): ");
Ada.Integer_Text_IO.Get (Item => Date_Input);
Ada.Text_IO.New_Line;
if Is_Valid_Year = True then
if Is_February = True then
if Is_Leap_Year = True then
if Is_Valid_Day_28 = True then
Valid_Date := True;
else
Valid_Date := False;
end if;
else
if Is_Valid_Day_29 = True then
Valid_Date := True;
else
Valid_Date := False;
end if;
end if;
elsif Is_Long_Month = True then
if Is_Valid_Day_31 = True then
Valid_Date := True;
else
Valid_Date := False;
end if;
elsif Is_Short_Month = True then
if Is_Valid_Day_30 = True then
Valid_Date := True;
else
Valid_Date := False;
end if;
end if;
end if;
end Project_3;
带有Ada.Text\u IO;
使用Ada.Text\u IO;
使用Ada.Integer\u Text\u IO;
使用Ada.Integer\u Text\u IO;
使用Ada.Float_Text_IO;
使用Ada.Float\u Text\u IO;
程序项目3是
-------------------------------------------------------------------------
--哈利格·格雷厄姆
-- 02/26/2015
--
--
--
--
--
--
-------------------------------------------------------------------------
类型Day_28是自然的数组(1..28);
类型Day_29是自然的数组(1..29);
类型Day_30是自然的数组(1..30);
类型Day_31是自然的数组(1..31);
日期输入:字符串(1..10);
月份:常量字符串:=日期\输入(1..2);
日期:常量字符串:=日期输入(4..5);
年份:常量字符串:=日期输入(7..10);
有效日期:布尔值:=False;
有效月份:布尔值:=False;
类型Long_Month是自然的数组(1..31);
类型短_月为自然数组(1..30);
指数:阳性;
--你有什么功能吗
函数Is_二月(月份:整数)返回布尔值为
开始
如果月份=2,则
返回True;
其他的
返回False;
如果结束;
2月底;
--是闰年函数吗
函数为闰年(年:整数形式)返回布尔值为
开始——是闰年吗
如果年份rem 100=0,则
如果年份rem 400=0,则
返回true;
其他的
返回false;
如果结束;
其他的
如果年份rem 4=0,则
返回true;
其他的
返回false;
如果结束;
如果结束;
终点是闰年;
--_Day_31函数有效吗
函数为\u有效\u天\u 31(天:整数形式)返回布尔值为
开始——第31天有效吗
如果Day=Day_31,则
返回true;
其他的
返回False;
如果结束;
结束日期为第31天;
--_有效_Day_30功能吗
函数为\u有效\u天\u 30(天:整数形式)返回布尔值为
开始——第30天有效吗
如果天=第30天,则
返回true;
其他的
返回False;
如果结束;
结束是有效的第30天;
--_有效_Day_29功能吗
函数为\u有效\u天\u 29(天:整数形式)返回布尔值为
开始——第29天有效吗
如果Day=Day_29,则
返回true;
其他的
返回False;
如果结束;
结束是有效的第29天;
--_Day_28功能有效吗
函数为\u有效\u天\u 28(天:整数形式)返回布尔值为
开始——第28天有效吗
如果Day=Day_28,则
返回true;
其他的
返回False;
如果结束;
结束是有效的第28天;
--年函数有效吗
函数为有效年(年:整数形式)返回布尔值为
开始——有效期是一年吗
如果年份>1700且年份<2300,则
返回true;
其他的
返回False;
如果结束;
结束是有效的一年;
--是长月函数吗
函数为长月份(月份:整数)返回布尔值为
begin——是长月函数吗
如果月份=长月份(整数),则
返回True;
其他的
返回False;
如果结束;
月底是长月;
--是短月函数吗
函数Is_Short_Month(月份:整数)返回布尔值为
begin——是短月函数吗
如果月份=短月(整数),则
返回True;
其他的
返回False;
如果结束;
月底是短月;
--主程序
开始
Ada.Text_IO.Put(“输入您希望检查的日期(MM/DD/YYYY):”;
Ada.Integer\u Text\u IO.Get(项=>Date\u输入);
Ada.Text\u IO.New\u行;
如果有效,则年=真
如果这是真的,那么
如果“闰年”为真,则
如果是有效日,则为真
有效日期:=真;
其他的
有效日期:=假;
如果结束;
其他的
如果是有效日,则为真
有效日期:=真;
其他的
有效日期:=假;
如果结束;
如果结束;
elsif_Long_Month=True则
如果是有效日,则为真
有效日期:=真;
其他的
有效日期:=假;
如果结束;
elsif是_Short_Month=True那么
如果有效日为真,则
有效日期:=真;
其他的
有效日期:=假;
如果结束;
如果结束;
如果结束;
结束项目3;
我做错了什么?我有很多错误消息,但我觉得它们源自一个问题。当我试图编译您的示例时,我收到的每个错误消息都来自源文本中的一个唯一错误 编译时,考虑将这些参数用于
gnatmake
:
gnatmake -gnata -gnato -fstack-check -gnat12 -gnatyO -gnatv -gnati1 -gnatf -gnatn
我建议使用
-gnatl
进行编译-它会在代码列表中散布错误消息
您的许多错误消息如下
71. function Is_Valid_Day_31 (Day : in Integer) return Boolean is
72.
73. begin -- Is_Valid_Day_31
74. if Day = Day_31 then
|
>>> subtype name cannot be used as operand
你在哪里
25. type Day_31 is array (1..31) of Natural;
我不知道你为什么把Day\u 31
编码为一个数组;例如,您希望在第31(13)
天存储什么?这将是更正常的申报
subtype Day_31 is Natural range 1 .. 31;
然后你就可以写了
function Is_Valid_Day_31 (Day : in Integer) return Boolean is
begin -- Is_Valid_Day_31
return Day in Day_31;
end Is_Valid_Day_31;
function Is_Valid_Day_31 (Day : in Integer) return Boolean is
begin -- Is_Valid_Day_31
return Day in Day_31'Range;
end Is_Valid_Day_31;
另一方面,如果您真的需要这些数组,您可以编写
function Is_Valid_Day_31 (Day : in Integer) return Boolean is
begin -- Is_Valid_Day_31
return Day in Day_31;
end Is_Valid_Day_31;
function Is_Valid_Day_31 (Day : in Integer) return Boolean is
begin -- Is_Valid_Day_31
return Day in Day_31'Range;
end Is_Valid_Day_31;
然后,您在文本IO
方面遇到了问题,我将不讨论这个问题,还有一系列问题,如
155. if Is_Valid_Year = True then
|
>>> missing argument for parameter "Year" in call to "Is_Valid_Year" declared at line 110
这应该是显而易见的。为什么要编写像
Is\u Short\u Month=True这样的表达式?它们相当于可读性更强的Is\u Short\u Month
。也许您应该尝试减少示例,一次解决一个问题?