A
arnuld
/* 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]$
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]$