473,800 Members | 2,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(in t firstDay, int& columnCount);
void daysInMonth(int month,int year, int& numDaysInMonth );
bool isLeapYear(int year);
void printOneMonth(i nt 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(in t 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(yea r))
{

numDaysInMonth = 29;

}
else if (!isLeapYear(ye ar))
{
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(i nt month,int year,int firstDay)
{
int numDaysInMonth;
int columnCount;

header(month);
daysInMonth( month, year, numDaysInMonth );
goToFirstDay(fi rstDay,columnCo unt);
printNumbers (numDaysInMonth );

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

for (count;count<=n umDaysInMonth;c ount++)
{

cout << count << " ";
}
}

Jul 19 '05 #1
4 1915
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
2758
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 storing products in
1
8009
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 expected. After this I decided to TRY to start a new project, so I repeated the File | New menu but for some reason HCW.exe wouldn't allow me to create a new project. After repeating the aforementioned process the filename plus the ..hpj extension...
4
2508
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 of projects. Therefore, I wish to include the project customType in the projectCollection namespace. I therefore have declared two xsd documents: project.xsd and projectcollection.xsd
0
1775
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 web project even cannot create a new one. The message for create a new web project is: (Open an oldASP project got similar error.) My system is Windows 2000 Server ---------------------- The default web access mode for this project is set to...
4
3258
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 web project even cannot create a new one. The message for create a new web project is: (Open an oldASP project got similar error.) My system is Windows 2000 Server ---------------------- The default web access mode for this project is set to...
3
2259
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 'http://Localhost:/MyProject'. The two need to map to the same server location. HTTP Error 404: Not Found." I have tried fixing this using both of these KB articles and usenet advises, still problem not solved:
7
1763
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. After addding another Crystal report, vs.net will no longer build the project - it just goes away - no message no nothing. My other dev box will build it but won't run it in debug. I ran a vs.net repair but it still does the same thing. vs.net...
4
2257
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! Apparently, all I have to do is create a "Help Project"! There's my starting point. So the VS help says: "To create a Help project, click on the File menu, choose New and follow the wizard's instructions"
16
2821
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 efficient navigating within Visual Studio 2005. Let's say your project (or solution) has dozens of forms and hundreds or even thousands of routines. Two Questions: 1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
16
2330
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 the Debug= True in the Web.config which I do. Then try to run it again and it says I must enable integrated security which I do. I then try to run it again and get the HTTP 403 error - " This error (HTTP 403 Forbidden) means that Internet...
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9550
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10032
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7574
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.