L
Luis
My project is to make a calander which will print out every month depending
on the year leap year or not) and the first day of the year. this is what i
have so far, but i don't know how to go about making it go to a new line
when the end od the current line is reaxched. Please take a look at my code,
and tell me if you have suggestions. It has no comments, and is pretty raw,
i am to the point of ust printing only 1 month, not all 12 yet. Please help
out, if i don't pass this, I may not pass the class.
#include <iostream>
using namespace std;
void getData (int& year , int& firstDay);
void header (int month);
void goToFirstDay(int firstDay, int& columnCount);
void daysInMonth(int month,int year, int& numDaysInMonth );
bool isLeapYear(int year);
void printOneMonth(int month , int year,int firstDay);
void printNumbers (int numDaysInMonth);
int main ( )
{
int month = 2;
int year; //info given from getData()
int firstDay ; // info from getData()
getData (year , firstDay);
printOneMonth( month, year, firstDay);
return 0;
}
void getData (int& year , int& firstDay)
{
cout << "what year do you want the calander for?" ;
cin >> year;
cout << "what day of the week does january 1 fall on?" << endl;
cout << "(enter 0 for sunday , 1 for monday, etc.)";
cin >> firstDay;
}
void header (int month)
{
switch (month)
{
case 1 : cout << " January" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 2 : cout << " Febuary" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 3 : cout << " March" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 4 : cout << " April" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 5 : cout << " May" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 6 : cout << " June" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 7 : cout << " July" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 8 : cout << " August" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 9 : cout << " September" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 10 :cout << " October" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 11: cout << " November" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 12: cout << " December" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
}
}
void goToFirstDay(int firstDay, int& columnCount )
{
int count = 0;
cout << " ";
if (firstDay > 0)
{
for (count; count < firstDay ;count++)
{
cout << " ";
}
}
columnCount = count + (count*3);
}
void daysInMonth( int month, int year, int& numDaysInMonth )
{
switch (month)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10 :
case 12 : numDaysInMonth = 31;
break;
case 4 :
case 6 :
case 9 :
case 11 : numDaysInMonth = 30;
break;
case 2 : if (isLeapYear(year))
{
numDaysInMonth = 29;
}
else if (!isLeapYear(year))
{
numDaysInMonth = 28;
}
}
}
bool isLeapYear(int year)
{
if (year % 400 == 0){
return true;
}
if (year % 100 == 0){
return false;
}
if (year % 4 == 0){
return true;
}
return false;
}
void printOneMonth(int month,int year,int firstDay)
{
int numDaysInMonth;
int columnCount;
header(month);
daysInMonth( month, year, numDaysInMonth );
goToFirstDay(firstDay,columnCount);
printNumbers (numDaysInMonth);
}
void printNumbers (int numDaysInMonth)
{
int count = 1;
for (count;count<=numDaysInMonth;count++)
{
cout << count << " ";
}
}
on the year leap year or not) and the first day of the year. this is what i
have so far, but i don't know how to go about making it go to a new line
when the end od the current line is reaxched. Please take a look at my code,
and tell me if you have suggestions. It has no comments, and is pretty raw,
i am to the point of ust printing only 1 month, not all 12 yet. Please help
out, if i don't pass this, I may not pass the class.
#include <iostream>
using namespace std;
void getData (int& year , int& firstDay);
void header (int month);
void goToFirstDay(int firstDay, int& columnCount);
void daysInMonth(int month,int year, int& numDaysInMonth );
bool isLeapYear(int year);
void printOneMonth(int month , int year,int firstDay);
void printNumbers (int numDaysInMonth);
int main ( )
{
int month = 2;
int year; //info given from getData()
int firstDay ; // info from getData()
getData (year , firstDay);
printOneMonth( month, year, firstDay);
return 0;
}
void getData (int& year , int& firstDay)
{
cout << "what year do you want the calander for?" ;
cin >> year;
cout << "what day of the week does january 1 fall on?" << endl;
cout << "(enter 0 for sunday , 1 for monday, etc.)";
cin >> firstDay;
}
void header (int month)
{
switch (month)
{
case 1 : cout << " January" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 2 : cout << " Febuary" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 3 : cout << " March" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 4 : cout << " April" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 5 : cout << " May" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 6 : cout << " June" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 7 : cout << " July" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 8 : cout << " August" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 9 : cout << " September" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 10 :cout << " October" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 11: cout << " November" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 12: cout << " December" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
}
}
void goToFirstDay(int firstDay, int& columnCount )
{
int count = 0;
cout << " ";
if (firstDay > 0)
{
for (count; count < firstDay ;count++)
{
cout << " ";
}
}
columnCount = count + (count*3);
}
void daysInMonth( int month, int year, int& numDaysInMonth )
{
switch (month)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10 :
case 12 : numDaysInMonth = 31;
break;
case 4 :
case 6 :
case 9 :
case 11 : numDaysInMonth = 30;
break;
case 2 : if (isLeapYear(year))
{
numDaysInMonth = 29;
}
else if (!isLeapYear(year))
{
numDaysInMonth = 28;
}
}
}
bool isLeapYear(int year)
{
if (year % 400 == 0){
return true;
}
if (year % 100 == 0){
return false;
}
if (year % 4 == 0){
return true;
}
return false;
}
void printOneMonth(int month,int year,int firstDay)
{
int numDaysInMonth;
int columnCount;
header(month);
daysInMonth( month, year, numDaysInMonth );
goToFirstDay(firstDay,columnCount);
printNumbers (numDaysInMonth);
}
void printNumbers (int numDaysInMonth)
{
int count = 1;
for (count;count<=numDaysInMonth;count++)
{
cout << count << " ";
}
}