A
arnuld
this one was much easier and works fine. as usual, i put code here for
any further comments/views/advice:
--------- PROGRAMME ------------
/* 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.
here i used (2) option
*/
#include<iostream>
int main()
{
struct duo {
const char* month;
int days;
};
duo JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC;
JAN.month = "JAN";
FEB.month = "FEB";
MAR.month = "MAR";
APR.month = "APR";
MAY.month = "MAY";
JUN.month = "JUN";
JUL.month = "JUL";
AUG.month = "AUG";
SEP.month = "SEP";
OCT.month = "OCT";
NOV.month = "NOV";
DEC.month = "DEC";
JAN.days = 31;
FEB.days = 28;
MAR.days = 31;
APR.days = 30;
MAY.days = 31;
JUN.days = 30;
JUL.days = 31;
AUG.days = 31;
SEP.days = 30;
OCT.days = 31;
NOV.days = 30;
DEC.days = 31;
const int arr_size = 12;
duo arr[] = {JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP};
duo* pduo = arr;
std::cout << "\tMONTH\tDays\n";
for(int i = 0; i < arr_size; ++i)
{
std::cout << '\t'
<< pduo->month
<< '\t'
<< pduo->days
<< std::endl;
++pduo;
}
return 0;
}
--------- OUTPUT -------------
[arch@voodo tc++pl]$ g++ -ansi -pedantic -Wall -Wextra 5.9_ex-07-
struct.cpp
[arch@voodo tc++pl]$ ./a.out
MONTH Days
JAN 31
FEB 28
MAR 31
APR 30
MAY 31
JUN 30
JUL 31
AUG 31
SEP 30
DEC 31
NOV 30
OCT 31
[arch@voodo tc++pl]$
any further comments/views/advice:
--------- PROGRAMME ------------
/* 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.
here i used (2) option
*/
#include<iostream>
int main()
{
struct duo {
const char* month;
int days;
};
duo JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC;
JAN.month = "JAN";
FEB.month = "FEB";
MAR.month = "MAR";
APR.month = "APR";
MAY.month = "MAY";
JUN.month = "JUN";
JUL.month = "JUL";
AUG.month = "AUG";
SEP.month = "SEP";
OCT.month = "OCT";
NOV.month = "NOV";
DEC.month = "DEC";
JAN.days = 31;
FEB.days = 28;
MAR.days = 31;
APR.days = 30;
MAY.days = 31;
JUN.days = 30;
JUL.days = 31;
AUG.days = 31;
SEP.days = 30;
OCT.days = 31;
NOV.days = 30;
DEC.days = 31;
const int arr_size = 12;
duo arr[] = {JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP};
duo* pduo = arr;
std::cout << "\tMONTH\tDays\n";
for(int i = 0; i < arr_size; ++i)
{
std::cout << '\t'
<< pduo->month
<< '\t'
<< pduo->days
<< std::endl;
++pduo;
}
return 0;
}
--------- OUTPUT -------------
[arch@voodo tc++pl]$ g++ -ansi -pedantic -Wall -Wextra 5.9_ex-07-
struct.cpp
[arch@voodo tc++pl]$ ./a.out
MONTH Days
JAN 31
FEB 28
MAR 31
APR 30
MAY 31
JUN 30
JUL 31
AUG 31
SEP 30
DEC 31
NOV 30
OCT 31
[arch@voodo tc++pl]$