answersLogoWhite

0


Best Answer

#include<iostream>

#include<iomanip>

#include<string>

#include<sstream>

bool is_leap_year (unsigned year) { return !(year%400) (!(year%4) && (year%100)); };

unsigned count_leap_years (unsigned year) { return year/4-year/100+year/400; };

unsigned day_of_year (unsigned y, unsigned m, unsigned d);

unsigned long long count_days (unsigned y, unsigned m, unsigned d) {

return 365ULL * (y-1) + count_leap_years(y-1) + day_of_year (y, m, d);}

// compute day of year (January 1st == day 1)

unsigned day_of_year (unsigned y, unsigned m, unsigned d) {

static int DayOfMonth[] = {0,31,59,90,120,151,181,212,243,273,304,334};

return DayOfMonth[m-1] + d + ((m>2 && is_leap_year(y))? 1 : 0);

}

std::ostream& centre_text (std::ostream& os, std::string& str, size_t width) {

if (str.size()<width) {

unsigned spaces {(width-str.size())/2};

while (spaces-->0) os << ' ';

}

return os << str;

}

std::ostream& calendar(std::ostream& os, unsigned y, unsigned m)

{

using namespace std;

string Month[] {"January", "February", "March",

"April", "May", "June",

"July", "August", "September",

"October", "November", "December"};

string Week {"Su Mo Tu We Th Fr Sa"};

unsigned DayOfMonth[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

if (is_leap_year (y)) DayOfMonth[1] = 29;

stringstream ss {}; ss << y; // convert year to string

string s {Month[m-1] + ' ' + ss.str()};

os << endl;

centre_text (os, s, Week.size()) << endl;

os << Week << endl;

unsigned first_day {count_days (y, m, 1) % 7};

for(unsigned i {};i<first_day; ++i)

os << " "; // three spaces

for(unsigned i {first_day}, day {1}; day<=DayOfMonth[m-1]; ++i, ++day) {

os << setw(2) << day << ' ';

if(i%7==6) os << endl;

}

return os << std::endl;

}

int main(void){

unsigned year,month;

std::cout << "Enter the month and year: ";

std::cin >> month >> year;

calendar(std::cout, year, month);

}

User Avatar

Wiki User

6y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the program to compute calendar?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What BASIC program can compute and display all prime numbers from 1 to 40?

PRINT 2,3,5,7,11,13,17,19,23,29,31,37


Write a program in c plus plus to compute first of non-terminal?

there is no solution of this problem...........that's it..........


Write a java that computes the value of 2?

Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);


Write algorithm compute sum of square of N numbers?

1. Design an algorithm to compute sum of the squares of n numbers?


Write the full program for the quadratic equation in COBOL?

Identification division. Program-id. Quadratic. Environment division. Data division. Working-storage section. 01 a pic 9(3) value 0. 01 b pic 9(3) value 0. 01 c pic 9(3) value 0. 01 d pic 9(3) value 0. 01 e pic 9(3) value 0. 01 f pic 9(3) value 0. 01 g pic 9(3) value 0. 01 h pic 9(3) value 0. 01 x1 pic 9(3) value 0. 01 x pic z(3).z(2) value 0. 01 x2 pic 9(3) value 0. 01 y pic z(3).z(2) value 0. Procedure division. Display "Written by Martin O. Egua, but not complete". Display "Quadratic equation solver for three values a, b &amp; c" Display "Enter a number: " Accept a. Display "Enter the second number: " Accept b. Display "Enter the last number: " Accept c. compute d = (b * b) compute e = 4 * a * c compute f = 2 * a compute g = d - e compute h = function sqrt (g). compute x1 = (-b) + h compute x = x1 / f Display "X = " x compute x2 = (-b) - h compute y = x2 / f Display "Y = " y Display "Send the accurate program". Stop run.

Related questions

What is the verb for computer?

The verb for computer is compute.Other verbs are computes, computing and computed."I am computing"."We have computed the program""I like to compute".


Write a pascal program that compute an area of a triangle?

{A program to compute the area of a triangle} {by Ogboin W. Meshach} Var; b,h:real; BEGIN Writeln('Triangle'); Write('Base: '); Readln(base); Write('Height: '); Readln(height); area:=0.5*base*height; Writeln('Area: ', area :0:2); End.


Write a c program to find Volume and surface area of cube?

Write a c program to compute the surface area and volume of a cube


Design and develop a simple application program that will compute the sum of two numbers?

This isn't a question!


What BASIC program can compute and display all prime numbers from 1 to 40?

PRINT 2,3,5,7,11,13,17,19,23,29,31,37


What is a highly rated calendar program for my Mac running Snow Leopard?

iCal is a fantastic calendar program, which allows you to set appointments and tasks. It is also free with Snow Leopard!


How do you get a generated date in Excel 2007 to post to calendar?

There is a lifetime calendar program with dates for every month of the year:


Write a program in c plus plus to compute first of non-terminal?

there is no solution of this problem...........that's it..........


What is the assembly program to generate a geometric series and compute its sum The inputs are the base root and the length of the series The outputs are the series elements and their sum?

What is the assembly program to generate a geometric series and compute its sum The inputs are the base root and the length of the series The outputs are the series elements and their sum?


Write a c plus plus program to compute two integers?

int x= 1; int y= 2;


Write a program to compute the sum of first ten integer numbers in PHP?

$n = 10*(1+10)/2;


What program has a modifiable calendar template?

There are many online shops that sell calendar template. Amazon.com is one of online shop that sells calendar template for any kind of models. You can visit www.amazon.com