Stroustrup 5.9,练习7 [英] Stroustrup 5.9, exercise 7
问题描述
/ * Stroustrup:5.9运动7
声明:
定义一个名为sof months o fyear和天数的表格。 >每月
。写出那张桌子。这样做两次:
1.)使用ar数组的char表示月份名称和一系列数字
表示天数。
2.)使用一组结构。每个结构都有
月的名称
及其相应的天数。
现在,我只尝试了(1) 。
* /
#include< iostream>
int main()
{
const int months = 12;
int i = 0;
const char * ArrOfMonths [] = {" JAN" ,FEB,MAR,APR,MAY,
JUN,
" JUL"," AUG" ;SEP,OCT,NOV,DEC; };
const int ArrOfDays [] = {31,28,31,30,31,30,31,31,30,31,30,
31};
std :: cout<< \tMONTH \ tDAYS \ n;;
const char ** pmonths = ArrOfMonths;
const int * pdays = ArrOfDays [0] ;
for(int i = 0; * pmonths!=''\'''|| * pdays!=''\ 0''; ++ i)
{
std :: cout<< " \t" << * pmonths
<< " \t" << * pdays
<< std :: endl;
++ pmonths;
++ pdays;
}
返回0;
}
----------------- OUTPUT ---------------- -
[arch @ voodo tc ++ pl] $ g ++ 5.9_ex-07.cpp
5.9_ex-07.cpp:在函数''int main()' ':
5.9_ex-07.cpp:31:错误:从''const int''无效转换为''const
int *''
[arch @ voodo tc ++ pl] $
/* Stroustrup: 5.9 exercise 7
STATEMENTS:
Define a table of the name sof months o fyear and the number of days
in each month. write out that table. Do this twice:
1.) using ar array of char for names of months and an array of numbers
for number of days.
2.) using an array of structures. each structure holds the name of the
month
and its corresponding number of days.
for now, i have tried the (1) only.
*/
#include<iostream>
int main()
{
const int months = 12;
int i = 0;
const char* ArrOfMonths[] = { "JAN", "FEB", "MAR", "APR", "MAY",
"JUN",
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC" };
const int ArrOfDays[] = {31, 28, 31, 30, 31,30, 31, 31, 30, 31, 30,
31};
std::cout << "\tMONTH\tDAYS\n";
const char** pmonths = ArrOfMonths;
const int* pdays = ArrOfDays[0];
for(int i = 0; *pmonths != ''\0'' || *pdays != ''\0''; ++i)
{
std::cout << "\t" << *pmonths
<< "\t" << *pdays
<< std::endl;
++pmonths;
++pdays;
}
return 0;
}
----------------- OUTPUT -----------------
[arch@voodo tc++pl]$ g++ 5.9_ex-07.cpp
5.9_ex-07.cpp: In function ''int main()'':
5.9_ex-07.cpp:31: error: invalid conversion from ''const int'' to ''const
int*''
[arch@voodo tc++pl]$
推荐答案
g ++ 5.9_ex-07.cpp
5.9_ex-07.cpp:在函数''int main()''中:
5.9_ex-07.cpp:31:错误:从''const int'转换无效' to''const
int *''
[arch @ voodo tc ++ pl]
g++ 5.9_ex-07.cpp
5.9_ex-07.cpp: In function ''int main()'':
5.9_ex-07.cpp:31: error: invalid conversion from ''const int'' to ''const
int*''
[arch@voodo tc++pl]
arnuld写道:
arnuld wrote:
/ * Stroustrup:5.9运动7
声明:
定义一个名为sof months o fyear和天数的表格
in e一个月。写出那张桌子。这样做两次:
1.)使用ar数组的char表示月份名称和一系列数字
表示天数。
2.)使用一组结构。每个结构都有
月的名称
及其相应的天数。
现在,我试过了(1)仅限。
* /
#include< iostream>
int main()
{
const int months = 12;
int i = 0;
const char * ArrOfMonths [] = {" JAN"," FEB"," MAR"," APR"," MAY",
" JUN",
JUL,AUG,SEP,OCT,NOV,DEC等。 };
const int ArrOfDays [] = {31,28,31,30,31,30,31,31,30,31,30,
31};
std :: cout<< \tMONTH \ tDAYS \ n;;
const char ** pmonths = ArrOfMonths;
const int * pdays = ArrOfDays [0] ;
for(int i = 0; * pmonths!=''\'''|| * pdays!=''\ 0''; ++ i)
{
std :: cout<< " \t" << * pmonths
<< " \t" << * pdays
<< std :: endl;
++ pmonths;
++ pdays;
}
返回0;
}
----------------- OUTPUT ------------ -----
[arch @ voodo tc ++ pl]
/* Stroustrup: 5.9 exercise 7
STATEMENTS:
Define a table of the name sof months o fyear and the number of days
in each month. write out that table. Do this twice:
1.) using ar array of char for names of months and an array of numbers
for number of days.
2.) using an array of structures. each structure holds the name of the
month
and its corresponding number of days.
for now, i have tried the (1) only.
*/
#include<iostream>
int main()
{
const int months = 12;
int i = 0;
const char* ArrOfMonths[] = { "JAN", "FEB", "MAR", "APR", "MAY",
"JUN",
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC" };
const int ArrOfDays[] = {31, 28, 31, 30, 31,30, 31, 31, 30, 31, 30,
31};
std::cout << "\tMONTH\tDAYS\n";
const char** pmonths = ArrOfMonths;
const int* pdays = ArrOfDays[0];
for(int i = 0; *pmonths != ''\0'' || *pdays != ''\0''; ++i)
{
std::cout << "\t" << *pmonths
<< "\t" << *pdays
<< std::endl;
++pmonths;
++pdays;
}
return 0;
}
----------------- OUTPUT -----------------
[arch@voodo tc++pl]
这篇关于Stroustrup 5.9,练习7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!