Skip to main content
Code Review

Return to Question

Notice removed Content dispute by Community Bot
Post Unlocked by Community Bot
Post Locked by Mast
Notice added Content dispute by Mast
Rollback to Revision 5
Source Link
Mast
  • 13.8k
  • 12
  • 57
  • 127
#include <cmath>
#include <iostream>
using namespace std;
int month, day, year, start;
#define MONTHS_PER_YEAR 12 // Cannot change.
const unsigned short DAYS_PER_MONTH[MONTHS_PER_YEAR] =
 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // Cannot change.
const char MONTH_NAMES[MONTHS_PER_YEAR][10] =
 {"January", "February", "March", "April",
 "May", "June", "July", "August",
 "September", "October", "November", "December"}; // Cannot change.
bool leapYear()
{
 if (((year % 4 == 0) && year % 100 != 0) || year % 400 == 0)
 {
 return false;
 }
 else
 {
 return true;
 }
}
//I actually do not think I am supposed to use static.

int day_of()
{
 
 static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
 year = year - month < 3;
 return ( year + year /4 - year /calculates100 first+ year /400 + t[month-1] + day) % 7;
}
void printMonth()
{
 start = day_of();
 int count, days_in_month = DAYS_PER_MONTH[month - 1];
 if (leapYear() && month == 2)
 {
 days_in_month = DAYS_PER_MONTH[month - 1] + 1;
 }
 if (start == 6)
 {
 start = -1;
 cout << " ";
 } 
 for (count = 0; count <= start; count++)
 {
 cout << (count > 0? " ": " ");
 }
 for (day = 1; day <= days_in_month; day++)
 {
 if (++count > 6)
 {
 count = 0;
 if (day > 9)
 {
 cout << endl;day << '\n';
 }
 else
 {
 cout << day << '\n' << " ";
 }
}
 else
 {
 if (day >= 9)
 {
 cout << day;
 }
 else
 {
 cout << day << " ";
 }
 cout << " ";
 }
 }
 cout << endl;
}
// Controls operation of the program.
int main()
{
 cout << "Enter the month: ";
 cin >> month;
 cout << "Enter the year: ";
 cin >> year;
 cout << MONTH_NAMES[month - 1] << " " << year << std::endl;
 cout << "Su" << " "<< "M" << " "<< "T"<< " " << "W" << " " << "Th" << " " << "F" << " " << "Sa\n";
 printMonth();
 cout << endl;
 return 0;
}
#include <cmath>
#include <iostream>
using namespace std;
int month, day, year, start;
const char MONTH_NAMES[MONTHS_PER_YEAR][10] =
 {"January", "February", "March", "April",
 "May", "June", "July", "August",
 "September", "October", "November", "December"}; // Cannot change.
bool leapYear()
{
 if (((year % 4 == 0) && year % 100 != 0) || year % 400 == 0)
 {
 return false;
 }
 else
 {
 return true;
 }
}
int day_of()
{ //calculates first day
}
void printMonth()
{
 start = day_of();
 int count, days_in_month = DAYS_PER_MONTH[month - 1];
 if (leapYear() && month == 2)
 {
 days_in_month = DAYS_PER_MONTH[month - 1] + 1;
 }
 if (start == 6)
 {
 start = -1;
 cout << " ";
 } 
 for (count = 0; count <= start; count++)
 {
 cout << (count > 0? " ": " ");
 }
 for (day = 1; day <= days_in_month; day++)
 {
 cout << endl;
 }
}
// Controls operation of the program.
int main()
{
 printMonth();
 cout << endl;
 return 0;
}
#include <cmath>
#include <iostream>
using namespace std;
int month, day, year, start;
#define MONTHS_PER_YEAR 12 // Cannot change.
const unsigned short DAYS_PER_MONTH[MONTHS_PER_YEAR] =
 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // Cannot change.
const char MONTH_NAMES[MONTHS_PER_YEAR][10] =
 {"January", "February", "March", "April",
 "May", "June", "July", "August",
 "September", "October", "November", "December"}; // Cannot change.
bool leapYear()
{
 if (((year % 4 == 0) && year % 100 != 0) || year % 400 == 0)
 {
 return false;
 }
 else
 {
 return true;
 }
}
//I actually do not think I am supposed to use static.

int day_of()
{
 
 static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
 year = year - month < 3;
 return ( year + year /4 - year /100 + year /400 + t[month-1] + day) % 7;
}
void printMonth()
{
 start = day_of();
 int count, days_in_month = DAYS_PER_MONTH[month - 1];
 if (leapYear() && month == 2)
 {
 days_in_month = DAYS_PER_MONTH[month - 1] + 1;
 }
 if (start == 6)
 {
 start = -1;
 cout << " ";
 } 
 for (count = 0; count <= start; count++)
 {
 cout << (count > 0? " ": " ");
 }
 for (day = 1; day <= days_in_month; day++)
 {
 if (++count > 6)
 {
 count = 0;
 if (day > 9)
 {
 cout << day << '\n';
 }
 else
 {
 cout << day << '\n' << " ";
 }
}
 else
 {
 if (day >= 9)
 {
 cout << day;
 }
 else
 {
 cout << day << " ";
 }
 cout << " ";
 }
 }
 cout << endl;
}
// Controls operation of the program.
int main()
{
 cout << "Enter the month: ";
 cin >> month;
 cout << "Enter the year: ";
 cin >> year;
 cout << MONTH_NAMES[month - 1] << " " << year << std::endl;
 cout << "Su" << " "<< "M" << " "<< "T"<< " " << "W" << " " << "Th" << " " << "F" << " " << "Sa\n";
 printMonth();
 cout << endl;
 return 0;
}
simplified
Source Link
#include <cmath>
#include <iostream>
using namespace std;
int month, day, year, start;
#define MONTHS_PER_YEAR 12 // Cannot change.
const unsigned short DAYS_PER_MONTH[MONTHS_PER_YEAR] =
 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // Cannot change.
const char MONTH_NAMES[MONTHS_PER_YEAR][10] =
 {"January", "February", "March", "April",
 "May", "June", "July", "August",
 "September", "October", "November", "December"}; // Cannot change.
bool leapYear()
{
 if (((year % 4 == 0) && year % 100 != 0) || year % 400 == 0)
 {
 return false;
 }
 else
 {
 return true;
 }
}
//I actually do not think I am supposed to use static.

int day_of()
{
 
 static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
 year = year - month < 3;
 return ( year + year /4 - year /100 + year /400 + t[month-1]calculates +first day) % 7;
}
void printMonth()
{
 start = day_of();
 int count, days_in_month = DAYS_PER_MONTH[month - 1];
 if (leapYear() && month == 2)
 {
 days_in_month = DAYS_PER_MONTH[month - 1] + 1;
 }
 if (start == 6)
 {
 start = -1;
 cout << " ";
 } 
 for (count = 0; count <= start; count++)
 {
 cout << (count > 0? " ": " ");
 }
 for (day = 1; day <= days_in_month; day++)
 {
 if (++count > 6)
 {
 count = 0;
 if (day > 9)
 {
 cout << day << '\n';
 }
 else
 {
 cout << day << '\n' << " ";
 }
 }
 else
 {
 if (day >= 9)
 {
 cout << day;
 }
 else
 {
 cout << day << " ";
  }
 cout << " ";endl;
 }
  }
 cout << endl;
}
// Controls operation of the program.
int main()
{
 cout << "Enter the month: ";
 cin >> month;
 cout << "Enter the year: ";
 cin >> year;
 cout << MONTH_NAMES[month - 1] << " " << year << std::endl;
 cout << "Su" << " "<< "M" << " "<< "T"<< " " << "W" << " " << "Th" << " " << "F" << " " << "Sa\n";
 printMonth();
 cout << endl;
 return 0;
}
#include <cmath>
#include <iostream>
using namespace std;
int month, day, year, start;
#define MONTHS_PER_YEAR 12 // Cannot change.
const unsigned short DAYS_PER_MONTH[MONTHS_PER_YEAR] =
 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // Cannot change.
const char MONTH_NAMES[MONTHS_PER_YEAR][10] =
 {"January", "February", "March", "April",
 "May", "June", "July", "August",
 "September", "October", "November", "December"}; // Cannot change.
bool leapYear()
{
 if (((year % 4 == 0) && year % 100 != 0) || year % 400 == 0)
 {
 return false;
 }
 else
 {
 return true;
 }
}
//I actually do not think I am supposed to use static.

int day_of()
{
 
 static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
 year = year - month < 3;
 return ( year + year /4 - year /100 + year /400 + t[month-1] + day) % 7;
}
void printMonth()
{
 start = day_of();
 int count, days_in_month = DAYS_PER_MONTH[month - 1];
 if (leapYear() && month == 2)
 {
 days_in_month = DAYS_PER_MONTH[month - 1] + 1;
 }
 if (start == 6)
 {
 start = -1;
 cout << " ";
 } 
 for (count = 0; count <= start; count++)
 {
 cout << (count > 0? " ": " ");
 }
 for (day = 1; day <= days_in_month; day++)
 {
 if (++count > 6)
 {
 count = 0;
 if (day > 9)
 {
 cout << day << '\n';
 }
 else
 {
 cout << day << '\n' << " ";
 }
 }
 else
 {
 if (day >= 9)
 {
 cout << day;
 }
 else
 {
 cout << day << " ";
  }
 cout << " ";
 }
  }
 cout << endl;
}
// Controls operation of the program.
int main()
{
 cout << "Enter the month: ";
 cin >> month;
 cout << "Enter the year: ";
 cin >> year;
 cout << MONTH_NAMES[month - 1] << " " << year << std::endl;
 cout << "Su" << " "<< "M" << " "<< "T"<< " " << "W" << " " << "Th" << " " << "F" << " " << "Sa\n";
 printMonth();
 cout << endl;
 return 0;
}
#include <cmath>
#include <iostream>
using namespace std;
int month, day, year, start;
const char MONTH_NAMES[MONTHS_PER_YEAR][10] =
 {"January", "February", "March", "April",
 "May", "June", "July", "August",
 "September", "October", "November", "December"}; // Cannot change.
bool leapYear()
{
 if (((year % 4 == 0) && year % 100 != 0) || year % 400 == 0)
 {
 return false;
 }
 else
 {
 return true;
 }
}
int day_of()
{ //calculates first day
}
void printMonth()
{
 start = day_of();
 int count, days_in_month = DAYS_PER_MONTH[month - 1];
 if (leapYear() && month == 2)
 {
 days_in_month = DAYS_PER_MONTH[month - 1] + 1;
 }
 if (start == 6)
 {
 start = -1;
 cout << " ";
 } 
 for (count = 0; count <= start; count++)
 {
 cout << (count > 0? " ": " ");
 }
 for (day = 1; day <= days_in_month; day++)
 {
 cout << endl;
 }
}
// Controls operation of the program.
int main()
{
 printMonth();
 cout << endl;
 return 0;
}
Rollback to Revision 5
Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 479
#include <cmath>
#include <iostream>
using namespace std;
int month, day, year, start;
#define MONTHS_PER_YEAR 12 // Cannot change.
const unsigned short DAYS_PER_MONTH[MONTHS_PER_YEAR] =
 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; /extracted/ Cannot change.
const char MONTH_NAMES[MONTHS_PER_YEAR][10] =
 {"January", "February", "March", "April",
 "May", "June", "July", "August",
 "September", "October", "November", "December"}; // Cannot change.
bool leapYear()
{
 if (((year % 4 == 0) && year % 100 != 0) || year % 400 == 0)
 {
 return false;
 }
 else
 {
 return true;
 }
}
//I actually do not think I am supposed to use static.
int day_of()
{
 
 static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
 year = year - month < 3;
 return ( year + year /4 - year /100 + year /400 + t[month-1] + day) % 7;
}
void printMonth()
{
 start = day_of();
 int count, days_in_month = DAYS_PER_MONTH[month - 1];
 if (leapYear() && month == 2)
 {
 days_in_month = DAYS_PER_MONTH[month - 1] + 1;
 }
 if (start == 6)
 {
 start = -1;
 cout << " ";
 } 
 for (count = 0; count <= start; count++)
 {
 cout << (count > 0? " ": " ");
 }
 for (day = 1; day <= days_in_month; day++)
 {
 if (++count > 6)
 {
 count = 0;
 if (day > 9)
 {
 cout << day << '\n';
 }
 else
 {
 cout << day << '\n' << " ";
 }
 }
 else
 {
 if (day >= 9)
 {
 cout << day;
 }
 else
 {
 cout << day << " ";
 }
 cout << " ";
 }
 }
 cout << endl;
}
// Controls operation of the program.
int main()
{
 cout << "Enter the month: ";
 cin >> month;
 cout << "Enter the year: ";
 cin >> year;
 cout << MONTH_NAMES[month - 1] << " " << year << std::endl;
 cout << "Su" << " "<< "M" << " "<< "T"<< " " << "W" << " " << "Th" << " " << "F" << " " << "Sa\n";
 printMonth();
 cout << endl;
 return 0;
}
#include <cmath>
#include <iostream>
using namespace std;
///extracted
// Controls operation of the program.
int main()
{
 cout << "Enter the month: ";
 cin >> month;
 cout << "Enter the year: ";
 cin >> year;
 cout << MONTH_NAMES[month - 1] << " " << year << std::endl;
 cout << "Su" << " "<< "M" << " "<< "T"<< " " << "W" << " " << "Th" << " " << "F" << " " << "Sa\n";
 printMonth();
 cout << endl;
 return 0;
}
#include <cmath>
#include <iostream>
using namespace std;
int month, day, year, start;
#define MONTHS_PER_YEAR 12 // Cannot change.
const unsigned short DAYS_PER_MONTH[MONTHS_PER_YEAR] =
 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // Cannot change.
const char MONTH_NAMES[MONTHS_PER_YEAR][10] =
 {"January", "February", "March", "April",
 "May", "June", "July", "August",
 "September", "October", "November", "December"}; // Cannot change.
bool leapYear()
{
 if (((year % 4 == 0) && year % 100 != 0) || year % 400 == 0)
 {
 return false;
 }
 else
 {
 return true;
 }
}
//I actually do not think I am supposed to use static.
int day_of()
{
 
 static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
 year = year - month < 3;
 return ( year + year /4 - year /100 + year /400 + t[month-1] + day) % 7;
}
void printMonth()
{
 start = day_of();
 int count, days_in_month = DAYS_PER_MONTH[month - 1];
 if (leapYear() && month == 2)
 {
 days_in_month = DAYS_PER_MONTH[month - 1] + 1;
 }
 if (start == 6)
 {
 start = -1;
 cout << " ";
 } 
 for (count = 0; count <= start; count++)
 {
 cout << (count > 0? " ": " ");
 }
 for (day = 1; day <= days_in_month; day++)
 {
 if (++count > 6)
 {
 count = 0;
 if (day > 9)
 {
 cout << day << '\n';
 }
 else
 {
 cout << day << '\n' << " ";
 }
 }
 else
 {
 if (day >= 9)
 {
 cout << day;
 }
 else
 {
 cout << day << " ";
 }
 cout << " ";
 }
 }
 cout << endl;
}
// Controls operation of the program.
int main()
{
 cout << "Enter the month: ";
 cin >> month;
 cout << "Enter the year: ";
 cin >> year;
 cout << MONTH_NAMES[month - 1] << " " << year << std::endl;
 cout << "Su" << " "<< "M" << " "<< "T"<< " " << "W" << " " << "Th" << " " << "F" << " " << "Sa\n";
 printMonth();
 cout << endl;
 return 0;
}
deleted 1825 characters in body
Source Link
Loading
added 4 characters in body
Source Link
Loading
edited tags
Link
Toby Speight
  • 87.8k
  • 14
  • 104
  • 325
Loading
added 2 characters in body
Source Link
Loading
Describe the code, not the concerns, in the title
Source Link
Toby Speight
  • 87.8k
  • 14
  • 104
  • 325
Loading
Source Link
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /