I've been programming since the early 80s. Done various languages, FORTRAN, BASIC, C, JAVA and others. Both in college and on the job, electrical engineer. So, I don't have a problem with logistical flow and algorithms. But I am new to C++.

20 years ago I had developed an algorithm in c to build a 1 page yearly calendar. The concept is to build up strings and print them out and when printed on paper or screen it represents a 3 column, 4 row accurate calendar of any year you input. After I developed this in 1990 in c, I adapted it to JAVA in 1999. Now I am trying to do it with C++. My problem is I cannot even get it compiled so I can run and troubleshoot my algorithm.

I'm not using classes for what C++ is known for, but if you can help put my functions into classes
please show me.

Below is my source code, I'm having problems with function calls mainly. If I can get some assistance with getting this off the ground and get my algorithm running in C++, I'd like to make it into a simple windows application, I have never done any windows GUI programming. If I can get a running program with screen output, I would be able to troubleshoot the flow. This is a cool little application, anyone like to work with me on this?

About me, Kerry Newman, electrical engineering UC Berkeley 1984, Living in Houston Texas.

Here is my JAVA version on Java Boutique: http://javaboutique.internet.com/KNCalendar/

My JAVA source code: http://javaboutique.internet.com/KNCalendar/source.html

I'm using VC++ 5.1.

Thanks
Kerry

Compile Errors:

--------------------Configuration: calendar - Win32 Debug--------------------
Compiling...
calendar.cpp
C:\Program Files\DevStudio\MyProjects\calendar\calendar.cpp(41) : error C2065: 'firstweek' : undeclared identifier
C:\Program Files\DevStudio\MyProjects\calendar\calendar.cpp(43) : error C2065: 'otherweek' : undeclared identifier
C:\Program Files\DevStudio\MyProjects\calendar\calendar.cpp(60) : error C2371: 'firstweek' : redefinition; different basic types
C:\Program Files\DevStudio\MyProjects\calendar\calendar.cpp(61) : error C2064: term does not evaluate to a function
C:\Program Files\DevStudio\MyProjects\calendar\calendar.cpp(63) : error C2065: 'strcat' : undeclared identifier
C:\Program Files\DevStudio\MyProjects\calendar\calendar.cpp(82) : error C2040: 'otherweek' : 'int (int)' differs in levels of indirection from 'int'
C:\Program Files\DevStudio\MyProjects\calendar\calendar.cpp(120) : error C2040: 'firstday' : 'int (int,int)' differs in levels of indirection from 'int'
Error executing cl.exe.

calendar.exe - 7 error(s), 0 warning(s)



/////////////////////////////////////////////////////////////////
////////////////// Main program flow ////////////////////////////
/////////////////////////////////////////////////////////////////

#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>

int row, col, year, month, week, i, dayofweek, firstday;
int day[3];
char line[80];

int main ( )
{
cout << "Please Enter the Year)";
year: cin >> year;

for ( row= 0 ; row <= 3 ; ++row ) // 4 rows of Months 0-1-2 3-4-5 6-7-8 9-10-11 //
{
if ( row != 0 )

switch (row) // Draw Month names //
{
case 0: cout << " ***** JANUARY ****** ***** FEBRUARY ***** ******* MARCH ******"; break;
case 1: cout << " ****** APRIL ******* ******* MAY ******** ******* JUNE *******"; break;
case 2: cout << " ******* JULY ******* ****** AUGUST ****** ***** SEPTEMBER ****"; break;
case 3: cout << " ***** OCTOBER ****** ***** NOVEMBER ***** ***** DECEMBER *****";
}

cout << " Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa";

for ( int week = 0 ; week <= 5 ; ++week ) //week loops. one line includes one week for 3 Months. //
{
cout << " ";
for ( int col = 0 ; col <= 2 ; ++col ) //3 Months in a row //
{

if (week == 0) // 1st week needs to know what day to start. //
firstday = firstweek( row*3 + col, year );
else
otherweek( row*3 + col );
} // Column end //

cout << itoa ( dayofweek, line, 10 ); // done with line, print it out.
cout << " ";

}
}
return 0;
}


/////////////////////////////////////////////////////////////////
/////////////////// first week of the Month /////////////////////
/////////////////////////////////////////////////////////////////

char firstweek( int Month, int year )
{
dayofweek = firstday ( Month, year ); //get starting day of week.
for ( int i = 0 ; i < dayofweek ; i++ ) //print blanks until 1st.
strcat(line, " ");

do
{
strcat( line, " " ); //( day[Month] ) ); //print day of Month with leading blanks.
++day[Month];
++dayofweek;
}
while (dayofweek <= 6 );

if ( ((Month + 1) % 3) != 0 ) // if last day of week, print spaces between Month. //
cout << " ";
}

/////////////////////////////////////////////////////
/////////////////// weeks 2 - 6 /////////////////////
/////////////////////////////////////////////////////

otherweek( int Month )
{
dayofweek = 0; // initialize day of week to 0. Sunday //
int daysinMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

if (((year % 4) == 0) && (((year % 100) != 0) || ((year % 400) == 0)))
daysinMonth[1] = 29;

do
{
if ( day[Month] <= daysinMonth[ Month ] ) // check to see if days still left. //
{
if ( day[Month] < 10 ) // if 1-9, 2 leading spaces needed. //
strcat( line, " ", itoa( day[Month],line, 10 ) );
else // if 10-31, 1 leading space needed. //
strcat( line, " ", itoa( day[Month],line, 10 ) );
++day[Month];
++dayofweek;
}
else
{
strcat( line, " "); // if after last day of Month, print blanks. //
++dayofweek;
}
}
while ( dayofweek <= 6 );

if ( ((Month + 1) % 3) != 0 ) //if last day of week, print spaces between Month. //
strcat( line, " ");
return line;
} //end of otherweek


/////////////////////////////////////////////////////
///////////////// first day of Month ////////////////
/////////////////////////////////////////////////////


firstday( int Month, int year )
{
int yeardiff, days_since, dayofyear[]={ 0,31,59,90,120,151,181,212,243,273,304,334 };
yeardiff = year - 1;
days_since = yeardiff * 365;
days_since += ( ( yeardiff/4 ) - ( yeardiff/100 ) + ((yeardiff)/400) ) + dayofyear[ Month ];
if (((((year % 4) == 0) && (((year % 100) != 0) || ((year % 400) == 0)))) && ( Month > 1 ))
days_since++;
return ( ( days_since + 1 ) % 7 );
}




//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//
// Calendar Generator. Original program in C, 05/01/90
// v1.0 Converted to Java code. 09/23/99
// Modified from spaghetti code to structured code
// v1.1 Added button to inc/dec years. 09/27/99
// v1.2 Made Month and day names bold. 09/29/99
// v1.3 Added 'about' and 'now, buttons. 10/02/99
// v1.4 Added Font and Background color buttons. 10/03/99
// v1.5 Added frames (lines) around Months. 10/08/99
// v2.0 Pop-up window for individual Months 10/10/99 - 10/12/99
// v2.01 Some mouse event changes. Update month in
// window each time a month is clicked. 10/13/99
// v2.02 Adjusted lines on month window. 10/14/99
// v2.03 Month windows no longer show empty weeks 10/20/99
// v2.1 Used date class to set year from clock 10/22/99
// v2.2 Made separate applet for printing 05/14/00
// v2.21 Removed monthframe for now 05/16/00
// v2.3 Made Background & Font Colors user selectable 12/31/00
// v3.0 Adapting it to make it easy for laser 10/05/10
// Downloaded VC++ to work on program. 10/08/10
// Started serious programming C++ 10/13/10
//
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////
//
// This program works by building text lines and printing them out.
//
// for row = 0 to 3 - 4 rows by 3 columns of months
// for week = 0 to 5 - each week is a line and has to include the same week for all 3 months
// for column = 0 to 2 - each line includes 3 months
//
// This is the basic structure of the program. For the 1st week the
// start of the week has to be found and blanks inserted before the 1st.
// For the remaining weeks, the last day of the month needs to be found

// and blanks are inserted prior to the next month. After the 6 weeks are
// built for 3 months (1 row) the next row is then worked on the same way.
//
//////////////////////////////////////////////////////////////////

// Kerry Newman - [ 1999/2000
// http://web.wt.net/~newman/

2010
Edit by admin: no contact info permitted on the forum, thank you