i do not have any problem here. i solved the problem but i wanted to
know the views of you. please look at it from a newbie's perspective:
problem: define a table with names of months of the year & the number
of days in each month. write out that table. do this using: "a struct &
an array of that struct"
this is the solution i have created:
#include <iostream>
#include <string>
struct month_day {
std::string month;
int days;
};
// creating 12 structures
month_day md0 = {"Jan", 31};
month_day md1 = {"Feb", 28};
............... ............... ............... ....
month_day md11 = {"Dec", 31};
month_day arr_struct[arr_size] =
{md0, md1, md2, md3, md4, md5, md6, md7, md8, md9, md10, md11};
void print_struct_ar r(month_day as[])
{
for(int i=0; i < arr_size; ++i)
std::cout << as[i].month << "\t" << as[i].days << "\n";
}
int main() {
print_struct_ar r(arr_struct);
}
know the views of you. please look at it from a newbie's perspective:
problem: define a table with names of months of the year & the number
of days in each month. write out that table. do this using: "a struct &
an array of that struct"
this is the solution i have created:
#include <iostream>
#include <string>
struct month_day {
std::string month;
int days;
};
// creating 12 structures
month_day md0 = {"Jan", 31};
month_day md1 = {"Feb", 28};
............... ............... ............... ....
month_day md11 = {"Dec", 31};
month_day arr_struct[arr_size] =
{md0, md1, md2, md3, md4, md5, md6, md7, md8, md9, md10, md11};
void print_struct_ar r(month_day as[])
{
for(int i=0; i < arr_size; ++i)
std::cout << as[i].month << "\t" << as[i].days << "\n";
}
int main() {
print_struct_ar r(arr_struct);
}
Comment