hello all,
i'm a biology student currently taking programming in uni, and i have a homework question to solve.

i have to write a programme to create and print a one-month calendar which can be used as month and year calendars as well.
the programme should be able to;
1. detect the leap years and non-leap years
2. identify the first day (mon, tue, wed, etc)
3. identify the days in a month (number of days)
4. additional features such as help menu and other creative functions

for this assignment, my other group members and i are doing the different parts. i have written the codes for the first part (leap years) but i'm not very sure if it would work.

my greatest concern is whether we would be able to compile all the three different functions into one working programme, since we are all new to C++. i need some advice as to how to compile them

example of a code my instructor printed out for me;

#include <stdio.h>
/* 1' == leap year, 0' != leap year */
int is_leap_year (int year);

int main (void)
{
int years [4] = {2000, 2004, 2008, 2012);
int i = 0;
for (i = 0; i < 4; i++)
{
if (is_leap_year (years[i])==1)
printf ("%d is a leap year\n", years [i]);
else
printf ("%d is not a leap year\n", years [i]);
}
return 0;
}

we are using the C software but saving it under C++ since we don't have C++ in our school lab.
the actual codes i have written is different from this as i use the (year%4), (year%100==0) and (year%400==0) formula. i just need to know if the codes i typed earlier are more appropriate to be used in my assignment, because i do not understand them well

i also hope you can suggest to me some creative features to be added to my calendar to make it more interesting

any help is greatly appreciated, thank you

*added
i'm very sorry if i did not make myself clear, i mean we are using the C software in our school, so i have to use C code, but we are learning C++. i don't really understand this myself, my lecturer explained it to me. and i have solved the first part of the project. i'll be very thankful for everyone's help ^^

The code you written is C not C++. A C++ or C compiler should be able to compile that code.
Here is a link to a page which has some vb code at the end to calcuate leap years. It should be easy to understand, even if you don't know BASIC. Good luck with your calender :)

I wrote a few "Leap Year" programs in school. I always used tests like (year % 4).... which checks if the year is divisible by 4, and considering that leap years occur every 4 years then this is a good starting point. The exact definition that I used was from "Computing Concepts with C++ Essentials" which stated that a leap year is:

a) divisible by 4
b) Not divisible by 100 but divisible by 400
c) no exceptions to the 4 year rule before the introduction of the Gregorian calendar in Oct. 1582

As far as compiling a few separate files into one program you can do something like:

g++ prog1.cpp prog2.cpp prog3.cpp -o calendarProgram

You'll have to modify this to match your compiler and file names but the gist is:

compiler programs.cpp .... -o choseAnOutputName

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.