C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 25th, 2004, 04:15 PM
warp_9 warp_9 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 1 warp_9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
c++ Calendar

Hello all,
Was wondering if u could help me with a c++ calendar

here is the code i got so far
no i need to add the actual days
1 set varieble numblankdays to 0
2 if numblankdays is equal to startday go to step 6
3 print 6 blanks
4 incement numblankdays
5 go to step
6 set variable day = 6
just brain farted after all that code i did



Attached Files
File Type: txt cal.txt (3.8 KB, 3604 views)

Last edited by warp_9 : November 25th, 2004 at 04:18 PM. Reason: added c++ code

Reply With Quote
  #2  
Old November 29th, 2004, 07:33 PM
semanticpolice semanticpolice is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 2 semanticpolice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cal

Here's the code from a C++ assigment i had a few months ago.
PHP Code:
#include <iostream>
#include <iomanip>
using namespace std;
    
bool isLeapYear(int year); // check for leapyears
    
void printCal(int yearint start); // print calendar
    
void monthNums(int countintmonthDaysintspacerDays); //get how many days are in last and current months
    
void monthNames(int count); // get month names
    
void dayNames(); //print day header names
    
void spacer(int startintcolCountint countintprevSpacer); /* makes months line up
     correctly, if jan ends on monday, feb will start on tuesday */
    
void wrapper(int dayCountint monthDays); // initiates line returns
    
bool question(int answer);
 
    
int answer;
    
int prevSpacer;
    
int year;
    
int start;
    
int monthDays;
    
int spacerDays;
    
int dayCount 1;
    
int colCount 0
 
    
int halt// used to stop the damn program so i can copy the output
 
    
int main()
    {
        
question(answer);
        
printCal(yearstart); // print calender
        
cin >> halt// stop program so copy output
    
}
 
    
void question(int answer)
    {
 
        
cout << "What year do you want a calendar for? " << endl;
        
cin >> year;
        
cout << "What day of the week does january 1 fall on?" << endl << "(Enter 0 for sunday, 1 for monday, etc.)" << endl;
        
cin >> start;
 
        if(
start 6
        {
        
cout << "that's too much man";
 
        return 
false;
        }
 
    }    
 
    
void printCal(int yearint start// print calender
    
{
        
int count;
        for (
count 1count <= 12count++){
            
monthNames(count); // print the current month name
            
dayNames(); // print the day identifiers
            
monthNums(countmonthDaysspacerDays); // get the number of days in the current and last month
            
spacer(startcolCountcountprevSpacer); // print spaces to line up days correctly.
            
wrapper(dayCountmonthDays); // initiate line returns on saturday
     
}
    }
    
void wrapper(int dayCountint monthDays// initiate line returns
    
{
        while (
dayCount <= monthDays/// while the day count is less than the number of days in the month
        

            if (
colCount == 7// if column count equals 7 (saturday) print a line return 
            
{
                
cout << endl;
                
colCount 0// reset column count
            
}
            
cout << setw(3); // set width to 3
            
cout << dayCount// print a day number
            
colCount++; 
            
dayCount++;
        }
            
colCount 0;
        
cout << endl << endl// space the months a bit more
    
}
 
 
 
    
bool isLeapYear(int year// check for leap year
    
{
        if (
year 400 == 0){ // if year/400 has no remainders - true
        
return true;
        }
        if (
year 100 == 0){// if year/100 has no remainders - false
        
return false;
        }
        if (
year == 0){// if year/4 has no remainders - true
        
return true;
        }
        return 
false// else false
    
}
 
 
    
void monthNums(int countintmonthDaysintspacerDays// previous and current days in each month
    
{
        switch (
count
        {
            case 
1:
            
monthDays 31// current month days
            
break;
 
            case 
2
            if(
isLeapYear(year)) // check for leap year in feb
            
monthDays 29;
 
            if(!
isLeapYear(year))
            
monthDays 28;
 
            
spacerDays 31// previous month days
            
break;
 
            case 
3
            
monthDays 31;
 
            if(
isLeapYear(year)) //previous month days and leap year
            
spacerDays 29;
            if(!
isLeapYear(year))
            
spacerDays 28;
            break;
 
            case 
4
            
monthDays 30;
            
spacerDays 31;
            break;
 
            case 
5
            
monthDays 31;
            
spacerDays 30;
            break;
 
            case 
6
            
monthDays 30;
            
spacerDays 31;
            break;
 
            case 
7
            
monthDays 31;
            
spacerDays 30;
            break;
 
            case 
8
            
monthDays 31;
            
spacerDays 31;
            break;
 
            case 
9
            
monthDays 30;
            
spacerDays 31;
            break;
 
            case 
10
            
monthDays 31;
            
spacerDays 30;
            break;
 
            case 
11
            
monthDays 30;
            
spacerDays 31;
            break;
 
            case 
12
            
monthDays 31;
            
spacerDays 30;
            break;
        }
    }
 
 
    
void monthNames(int count// print month names
    
{
        switch (
count)
        {
            case 
1:
            
cout << "        January" << endl;
            break;
 
            case 
2:
            
cout << "        February" << endl;
            break;
 
            case 
3:
            
cout << "        March" << endl;
            break;
 
            case 
4:
            
cout << "        April" << endl;
            break;
 
            case 
5:
            
cout << "        May" << endl;
            break;
 
            case 
6:
            
cout << "        June" << endl;
            break;
 
            case 
7:
            
cout << "        July" << endl;
            break;
 
            case 
8:
            
cout << "        August" << endl;
            break;
 
            case 
9:
            
cout << "        September" << endl;
            break;
 
            case 
10:
            
cout << "        October" << endl;
            break;
 
            case 
11:
            
cout << "        November" << endl;
            break;
 
            case 
12:
            
cout << "        December" << endl;
            break;
        }
    }
 
 
 
 
 
    
void dayNames() // print day ident
    
{
    
cout << " S M T W T F S" << endl;
    }
 
 
 
 
    
void spacer(int startintcolCountint countintprevSpacer// print spaces
    
{
 
        if (
count == 1// used for the 1st month
        
{
            
int loopCount;
            for (
loopCount 0loopCount startloopCount++){
            
cout << " "// print space
            
prevSpacer++; // keep track of spaces for next month
            
}
            
colCount =+ start;
 
        } 
        else if (
count != 1//used for all other months
        
{
         
int otherSpacer;
         
int loopCount;
         
int monthCount count;
         
monthNums(monthCountmonthDaysspacerDays);
 
         
/* add previous number of spaces with previous number of days in month
         then devide by seven, use the remainder for the 
         spaces in the current month */
         
otherSpacer = (prevSpacer spacerDays) % 7
         
prevSpacer 0// reset spacer
         
for (loopCount 0loopCount otherSpacerloopCount++){
         
cout << " "// print space
         
prevSpacer++; // keep track of spaces for next month
         
colCount =+ otherSpacer;
         }
     }
    } 

Reply With Quote
  #3  
Old April 7th, 2005, 05:21 PM
WhiteShooZ WhiteShooZ is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 1 WhiteShooZ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 4 sec
Reputation Power: 0
Thought I'd share mine

I had a very simular project and thought I'd share my code with everyone.

Code:
 /**************************************************  **************************
 Description: This program outputs a calendar for the year that the user inputs.
 If no year is given, then it randomly selects one from 1400 and 9999.
 **************************************************  **************************/
 
 
 #include <iostream.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <time.h>
 int getYear();			   // has the user enter a valid year
 bool isLeap(int year);	   // check for leap years
 void dayName();			  // prints the names for the day of the week
 void monthNameHeader(int year);  // puts head for the month name
 int startDay(int year);		  // decides what week day Jan starts on
 int monthCount(int counter);	 // how many days are in each month
 
 void newMonth(int startDOW);  // what day of the week new month starts on
 
 void printAll(int year);		 //  puts everything together, prints to screen
 
 
 int year = 0;				    // uesr inputed year || rand gen per 0
 int counter = 1;				 // counter for month name & # days in month
 int startDOW,				    // day of the week Jan starts on
     wrap,					    // check for if weekday is Saturday
     daysInMonth;				 // total days in each month
 int weekNumber = 0;			  // flag for first week of the month
 
 int main()
 {
 
 
 
 
 	year = getYear();		// has user enter year number
 	printAll(year);
 
 
 
 
 	  return 0;
 }
 
 
 int getYear()	   //prompts the user to enter a valid year
 {
 	char c;
 	srand(time(NULL));
 	cout << "Enter the year, or 0 for and random year: ";
 	do {			  // gets whole number value
 		 cin.get(c);
 		 if(isdigit(c))
 		 {
 		  year=year*10;
 		  year +=(int)(c-'0');
 		 }
 	} while(c!='\n');
 	if (year == 0)			// if no response or 0 are enter, random a year
 	{
 	   year = rand() % 8600 + 1400;
 	   cout << "\nThe random year " << year << " will be evaluated\n\n";
 	}
  return year;
 }
 
 
 bool isLeap(int year) // checking for possible leap year
 {
 	 if (year % 400 == 0)
 	 return true;
 	 if (year % 100 == 0)
 	 return false;
 	 if (year % 4 == 0)
 	 return true;
 	 return false;  // else return false
 }
 
 void dayName()
 {
 	cout << "  S  M  T  W  T  F  S" << endl;
 	cout << "---------------------" << endl;
 }
 
 void monthNameHeader(int year)
 {
 
 		switch (counter)
 		{
 			case 1:
 			cout << "	January " << year << endl;
 			break;
 
 			case 2:
 			cout << "	February " << year << endl;
 			break;
 
 			case 3:
 			cout << "	March" << year << endl;
 			break;
 
 			case 4:
 			cout << "	April " << year << endl;
 			break;
 
 			case 5:
 			cout << "	 May " << year << endl;
 			break;
 
 			case 6:
 			cout << "	 June " << year << endl;
 			break;
 
 			case 7:
 			cout << "	 July " << year << endl;
 			break;
 
 			case 8:
 			cout << "	August " << year << endl;
 			break;
 
 			case 9:
 			cout << "	September " << year << endl;
 			break;
 
 			case 10:
 			cout << "	October " << year << endl;
 			break;
 
 			case 11:
 			cout << "	November " << year << endl;
 			break;
 
 			case 12:
 			cout << "	December " << year << endl;
 			break;
 		}
 }
 
 int monthCount(int counter)	  // how many days are in the month
 {
  switch (counter)
 		{
 			case 1:
 			daysInMonth = 31; // current month days
 			break;
 
 			case 2:					   // checks for possible leap year
 			if(isLeap(year))
 				daysInMonth = 29;
 			if(!isLeap(year))
 				daysInMonth = 28;
 			break;
 
 			case 3:
 			daysInMonth = 31;
 			break;
 
 			case 4:
 			daysInMonth = 30;
 			break;
 
 			case 5:
 			daysInMonth = 31;
 			break;
 
 			case 6:
 			daysInMonth = 30;
 			break;
 
 			case 7:
 			daysInMonth = 31;
 			break;
 
 			case 8:
 			daysInMonth = 31;
 			break;
 
 			case 9:
 			daysInMonth = 30;
 			break;
 
 			case 10:
 			daysInMonth = 31;
 			break;
 
 			case 11:
 			daysInMonth = 30;
 			break;
 
 			case 12:
 			daysInMonth = 31;
 			break;
 		}
 }
 
 
 int startDay(int year)
 {
 
 	startDOW = (year + (year - 1 ) /4 - (year - 1) / 100 + (year - 1) /400) %7;
 	return startDOW;			   // formula for what DoWeek year starts on
 }
 
 
 void printAll(int year)
 {
 
 	 for (counter = 1; counter <= 12; counter++)
 	 {
 
 		  monthNameHeader(year);			   // prints month day
 		  dayName();						   // prints the name of days
 		  if (counter==1)
 			  wrap = startDay(year) ;	// what day Jan starts on
 		  else
 			  startDOW = wrap;			   // what day other months start on
 
 		  cout << " ";
 
 		  for (int loopCount = 0; loopCount < startDOW; loopCount++)
 		  {
 				  cout << "   ";	   // how many space to indent new month
 		  }
 
 
 		  monthCount(counter);			 // how many days in month
 
 		  for (int dayCounter=1;dayCounter<=daysInMonth; dayCounter++)
 		  {
 
 				 if (wrap == 7)	   //if Saturday, carriage return
 				 {
 					 cout << "\n ";
 					 wrap = 0;		   //resets day of week counter
 					 weekNumber++;	   //no longer first week of month
 				 }
 				 if (dayCounter<10)	  //adds space for single digit days
 					 cout << " ";
 				 cout << dayCounter << " ";   //prints the day #
 				 wrap++;
 		  }
 
   //	cout << "\nthis month starts on day number " << startDOW;  *testing*
   //	cout << "\ndays in this month are " << daysInMonth;	    *testing*
 	  cout << "\n\n";
 	  system("PAUSE");
 	  cout << endl;
 	  }  // end BIG for loop
 
 
 }
 

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > c++ Calendar


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap