1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <cstdlib>
#include <iostream>
#include <conio.h>
using namespace std;
#define QUTY 12
int number_of_days (int);
struct months {
int num_mon;
char name[10];
char abrev[3];
int num_days;
};
struct months month[QUTY];
int main () {
int i, mes;
char *name[] = {"Janeiro", "Fevereiro", "Marco", "Abril", "Maio",
"Junho", "Julho", "Agosto", "Setembro", "Outubro",
"Novembro", "Dezembro"};
char *abrev[] = {"Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul",
"Ago", "Set", "Out", "Nov", "Dez"};
for (i = 0; i < QUTY; i++) {
strcpy (month[i].name, name[i]);
strcpy (month[i].abrev, abrev[i]);
if (i == 3 || i == 5 || i == 8 || i == 10)
month[i].num_days = 30;
else if (i == 1)
month[i].num_days = 28;
else
month[i].num_days = 31;
month[i].num_mon = i + 1;
cout << "Month: " << month[i].name << "(" << month[i].abrev << ")" << " Number: ";
cout << month[i].num_mon << " Days: " << month[i].num_days << endl;
}
cout << "\nEnter the number of one month: ";
cin >> mes;
cout << "\n\nTotal days of the year until " << month[mes - 1].name << ": " << number_of_days(mes);
getch();
}
int number_of_days (int a_month) {
int index, days = 0;
for (index = 0; index < a_month - 1; index++)
days += month[index].num_days;
return days;
}
|