473,398 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

help on project

My project is to make a calander which will print out every month depending
on the year leap year or not) and the first day of the year. this is what i
have so far, but i don't know how to go about making it go to a new line
when the end od the current line is reaxched. Please take a look at my code,
and tell me if you have suggestions. It has no comments, and is pretty raw,
i am to the point of ust printing only 1 month, not all 12 yet. Please help
out, if i don't pass this, I may not pass the class.

#include <iostream>

using namespace std;

void getData (int& year , int& firstDay);
void header (int month);
void goToFirstDay(int firstDay, int& columnCount);
void daysInMonth(int month,int year, int& numDaysInMonth );
bool isLeapYear(int year);
void printOneMonth(int month , int year,int firstDay);
void printNumbers (int numDaysInMonth);

int main ( )
{
int month = 2;
int year; //info given from getData()
int firstDay ; // info from getData()
getData (year , firstDay);
printOneMonth( month, year, firstDay);

return 0;
}

void getData (int& year , int& firstDay)
{
cout << "what year do you want the calander for?" ;
cin >> year;
cout << "what day of the week does january 1 fall on?" << endl;
cout << "(enter 0 for sunday , 1 for monday, etc.)";
cin >> firstDay;
}


void header (int month)
{
switch (month)
{

case 1 : cout << " January" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;

case 2 : cout << " Febuary" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;

case 3 : cout << " March" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;

case 4 : cout << " April" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;

case 5 : cout << " May" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;

case 6 : cout << " June" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;

case 7 : cout << " July" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;

case 8 : cout << " August" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
case 9 : cout << " September" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;

case 10 :cout << " October" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;

case 11: cout << " November" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;

case 12: cout << " December" << endl;
cout << " S M T W T F S " << endl;
cout << "--------------------" << endl;
break;
}
}


void goToFirstDay(int firstDay, int& columnCount )
{
int count = 0;

cout << " ";
if (firstDay > 0)
{
for (count; count < firstDay ;count++)

{
cout << " ";
}
}

columnCount = count + (count*3);

}



void daysInMonth( int month, int year, int& numDaysInMonth )
{

switch (month)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10 :
case 12 : numDaysInMonth = 31;
break;
case 4 :
case 6 :
case 9 :
case 11 : numDaysInMonth = 30;
break;

case 2 : if (isLeapYear(year))
{

numDaysInMonth = 29;

}
else if (!isLeapYear(year))
{
numDaysInMonth = 28;

}
}

}



bool isLeapYear(int year)
{
if (year % 400 == 0){
return true;
}

if (year % 100 == 0){
return false;
}

if (year % 4 == 0){
return true;
}

return false;
}




void printOneMonth(int month,int year,int firstDay)
{
int numDaysInMonth;
int columnCount;

header(month);
daysInMonth( month, year, numDaysInMonth );
goToFirstDay(firstDay,columnCount);
printNumbers (numDaysInMonth);

}
void printNumbers (int numDaysInMonth)
{
int count = 1;

for (count;count<=numDaysInMonth;count++)
{

cout << count << " ";
}
}

Jul 19 '05 #1
4 1902
On 28/7/03 7:27 pm (UK time), Mike Wahler let loose these words:
<snip>
You cause subsequent output to appear on a 'new line' with
the, um, newline character.

std::cout << '\n';

<snip>

std::endl is better in most cases.

Stewart.

--
My e-mail is valid but not my primary mailbox. Please keep replies on
on the 'group where everyone may benefit.

Jul 19 '05 #2
Stewart Gordon wrote:
On 28/7/03 7:27 pm (UK time), Mike Wahler let loose these words:
<snip>
You cause subsequent output to appear on a 'new line' with
the, um, newline character.

std::cout << '\n';


<snip>

std::endl is better in most cases.


Why? Flushing the stream when it's not necessary is wasteful.

-Kevin

Jul 19 '05 #3
On 1/8/03 6:52 pm (UK time), Kevin Goodsell let loose these words:
Stewart Gordon wrote:

<snip>
std::endl is better in most cases.


Why? Flushing the stream when it's not necessary is wasteful.


Mabye "most cases" was a slight exaggeration. But if cout remains
unflushed when the program exits or user input is requested, there's the
odd chance of something getting messed up.

Stewart.

--
My e-mail is valid but not my primary mailbox. Please keep replies on
on the 'group where everyone may benefit.

Jul 19 '05 #4
Stewart Gordon wrote:
On 1/8/03 6:52 pm (UK time), Kevin Goodsell let loose these words:
Stewart Gordon wrote:


<snip>
std::endl is better in most cases.


Why? Flushing the stream when it's not necessary is wasteful.

Mabye "most cases" was a slight exaggeration. But if cout remains
unflushed when the program exits or user input is requested, there's the
odd chance of something getting messed up.


I don't know about that... Unless I'm mistaken, cout will be flushed
when it is destroyed, so the program ending shouldn't be a problem
(although it could be, depending on how the program ends - but as long
as it ends correctly it should be fine).

Also, cout is automatically flushed when cin is used, I think.

In the case of cout you'll probably want it flushed more frequently than
other streams, and it probably will be flushed in some cases where you
don't necessarily want it, but in general streams should only be flushed
when there's a reason.

-Kevin

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: PHPkemon | last post by:
Hi there, A few weeks ago I made a post and got an answer which seemed very logical. Here's part of the post: PHPkemon wrote: > I think I've figured out how to do the main things like...
1
by: dave | last post by:
I first started using HCW.exe to compile .rtf filew created with MS Word a couple of weeks ago. I used the file | new menu then selected New project in the dialog box and everything worked as...
4
by: Iain A. Mcleod | last post by:
Hi I'm stuck with the following schema validation problem in VS.NET 2003: I have two types of xml document and related schema: project and projectCollection. A projectcollection is just a set...
0
by: CM | last post by:
Hi there: I have a web project which can be open and run without problem. I didn't open the web application for a period and during which I didn't modified any IIS items, but now I cannot open any...
4
by: CM | last post by:
Hi there: I have a web project which can be open and run without problem. I didn't open the web application for a period and during which I didn't modified any IIS items, but now I cannot open any...
3
by: alan_coffman2004 | last post by:
Opening an ASP.NET VS2002 project in VS2003, am getting this error: "Unable to open Web project 'MyProject'. The file path 'c:\inetpub\wwwroot\MyProject' does not correspond to the URL...
7
by: Tina | last post by:
I have an asp project that has 144 aspx/ascx pages, most with large code-behind files. Recently my dev box has been straining and taking long times to reneder the pages in the dev environment. ...
4
by: Fred Flintstone | last post by:
This one baffles me. I'm using VS.Net 2005 and write desktop apps that need built in help. So logically, I figure maybe VS has a help system component built in so I search the help. Hey! ...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
16
by: Harry Simpson | last post by:
I've been away from ASPNET - I open up a new Web app in VS2008 and go into properties and select to use IIS instead of the personal web server. Then I run in debug mode and it says I have to set...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.