Assignment due for Campus

Hello everyone.

My name is Chris and I have a project due for my C++ class, which is ending in 2 weeks. Uptil now, I've been able to complete every project with no assistance what so ever, but this project baffled me completely and I honestly don't even know where to start or what to do. The assignment reads as follows:

Write a function named NEWDAY which accepts three reference parameters for month, day and year. NEWDAY increments the date represented by month, day and year. For example, 11, 30 and 2003 would be incremented to 12 1 and 2003. NEWDAY does not display the date.

Also write a main program which inputs a date (month, day and year) from the keyboard and calls NEWDAY in a loop in order to display the next ten dates following the input date. The main program handles all input and output.

Sample program output:

Enter month: 11
Enter day: 25
Enter year: 2003

The next ten dates are:
11 26 2003
...
...
12 5 2003

Note that leap years are generally those divisible by 4, but not if they are divisible by 100 unless they are also devisible by 400.

testing your program across both month and year boundaries.

Hand in the program listing, sample program output.


Now I want to get this out there upfront and firstly...

I DO NOT want someone to type up this program and give it to me. I simply want a push in the right direction and guidance towards the write setup.

I would submit my code that I'm currently at, but its simply this:

1
2
3
4
5
6
7
#include <iomanip>
#include <iostream>
#include <cmath>
//Chris
//NEWDAY Program

using namesapce std;


should I use switch case? if else... I'm honestly completely clueless as to how to start something like this.

Sorry for the /noob question, hope someone is willing to tackle such a pee-on request.

Thanks for all your time,

Chris
I DO NOT want someone to type up this program and give it to me. I simply want a push in the right direction and guidance towards the write setup.


:)

Well, they basically told you what you need to know, create a function called NEWDAY that will increment 3 variables passed as parameters (I'm assuming they are being passed by reference though). Then you basically get the data from the user, then run that 30 times, displaying the date each time. The only special handling you would have to do is on Feburary, otherwise it is all very generic programming.
I'm still struggling with this.. I mean I know i could write:

1
2
3
4
5
6
int NEWDAY (int month, int day, int year)
{
month +1;
day +1;
year +1;
}


But how do I make it reconize the months that have 30 days and the months that have 31. What do I do with feb that changes every 4 years, except by 100's unless its in sets of 4 100s... I guess I can hope that eventually this will click in my head. My class is over in a week from this thursday, and currently I stand with a B in the class. I just can't grasp this, I think I'm thinking too hard on it... Thanks for the support firedraco.

Chris
Last edited on
I would create a static array containing the list of number of days in each month:
int dm[]={31,28,31,/*...*/};
Then you just need to check the month.
Your assignment says NEWDAY should take three reference parameters. The parameters to your function are not references.

Then do as helios suggested: increment the day by one. Check to see if the given month has at least that many days. If it does, you're done. If not, then you have to set the day to the first of the month and increment the month. Then you have to check to see if the month is beyond 12. If it isn't, you're done. If it is, ...

if current month is Feb and if current date >= 28
{
if current year is a leap year and if date is 28
{
Increment date by one
}
else
{
Set date =1 month = 3 // 1st March
}
}

else if current month is December and date is 31
{
set date = 1 and month = 1 and increment year //Happy New Year :)
}

else
{
a generic code for the rest of the months. You may use a static array like the one mentioned by Helios and incrementing just date if it is not the last day and incrementing the month as well if it is.
}



This is just a quick algorithm. I may not have considered some conditions or some thing else may be wrong. So do your testing as well. Anyway I hope this will help as a skeleton for your code.

Note: By current I have meant the date being passed to your function.
Last edited on
Ok, so far from what I've gathered through all of your comments, I'm forming an idea of what the assignment is looking for. I'm under good grounds to assume that what all you are telling me to do, goes into the main function correct? and the NEWDAY function that the assignment is requesting only askes for the 3 reference int's and returns them to main for main to function out and call.... Right?

can anyone link me to an article on here about static array's? I've searched but failed to find an article pretaining to how a static array works, sorry but my class hasn't actually covered arrays.

Thanks for all of your help too guys, I really do appreciate it.
Last edited on
Am I close with this piece of code?
Any suggestions and/or comments are greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//NEWDAY
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()

if month=2 && if day >= 28
{
if year=(year/2) && year!(year/100) && year=(year/400) && if day=28
{
day=day+1
}
else 
{
day =1 month = 3 // 1st March
}
}

else if month = 12 && day=31
{
day = 1 && month = 1 && year=year+1//Happy New Year :)
}


btw to any of those wondering, I'm using bloodshed Dev-C++ as my program source writer, its the one my school works with.

Thanks guys.
Last edited on
Well, you have a LOT of syntactical errors in that code along with a few semantic ones.

= is the assignment operator. == is comparison.
You are missing some semicolons.
&& if is not legal syntax.

Please correct the compile errors first.

Also, what happened to NEWDAY? You had a declaration of the NEWDAY function in your 1st reply that was close to correct, it's just the parameters were not references. In the code you just posted, I don't see the function any more.

hello all. I've been working on this for a week, and I realized I was looking at this from the extremely wrong side of the field. so I wrote this following code in like, 20 seconds. now I'm stuck again, but on the NEWDAY function, I can't figure out the mathematics behind it. heres my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iomanip>
#include <iostream>
#include <cmath>

using namespace std;

void NEWDAY(int, int, int);

int main()
{
    int month, day, year;
    
    cout << "Please enter your month: ";
    cin >> month;
    
    cout << "Great now enter the day of the month: ";
    cin >> day;
    
    cout << "Excellent, almost finished. Now lets enter the year: ";
    cin >> year;
    
    NEWDAY(month, day, year);
    
    return 0;
}
//The following function is NEWDAY.

void NEWDAY(int month, int day, int year)
{


the only error generated from this code is that theres no } closing off the NEWDAY function.
Last edited on
ok, I tried to dupicate the static array that was given to me as an example from helios and I recieved errors, I'm not exactly sure if I'm grasping the concept behind a static array. Heres my code and following is the error recieved.

1
2
int day[]={31,28,31,30,31,30,31,31,30,31,30,31};
     int month[]={1,2,3,4,5,6,7,8,9,10,11,12};



30 - declaration of 'int day[]' shadows a parameter

31 -declaration of 'int month[]' shadows a parameter
It is as it says:
You arrays are called day and month - your function also have parameters called day and month
Here are some comments on what you have so far:

1. I don't see a need to include iomanip or cmath.
2. To pass parameters to the NEWDAY function by reference, you need to add a "&" between the type and the variable name of each parameter.
3. You will need to output month, day, and year to see the results multiple times. You could make a function to do this if you like.
4. You will need to call NEWDAY multiple (10?) times and output month, day, year each time. You'll need a loop for that.
Topic archived. No new replies allowed.