Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to make this program that does the following:
implements the class Day that implements the day of the week in a program. The class day should store the day, such as Sun for Sunday. The program should be able to perform the following operations on an object of the type Day:
a. Set the day
b. Print the day
c. Return the day
d. Return the next day
e. Return the previous day
f. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add 4 days, the day to be returned is Friday, Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.
g. Add the appropriate constructors.
h. Write the definition of the methods to implement the operations for the class Day as defined in a-g.
i. Write a program to test various operations on the class Day.
Here is what i have so far, i can't get any further i need help.
public class Day
{
private String sun, mon, tue, wed, thur, fri, sat;public void Day(String s, String m, String t, String w, String x, String f, String a)
{
sun = s;
mon = m;
tue = t;
wed = w;
thur = x;
fri = f;
sat = a;
}public void Day()
{
String s, m, t, w, x, f, a;
s = "sunday";
m = "monday";
t = "tuesday";
w = "wednesday";
x = "thursday";
f = "friday";
a = "saturday";
}public String printDay(String s, String m, String t, String w, String x, String f, String a)
{
print.Day();
}public String ToDay(String day)
{
String day;
day = Day();
return day;
}public String nextDay(String day)
{
return day++;
}
public String previousDay(String day)
{
return day--;
}
}"you can't implement me, i'm outside your scope!"

well that's all kinds of messed up, isn't it?
you cannot return from a void.
let me help you out.
#include <string>
using namespace std;class Day
{
private:
string Days[7];
int TodayIndex;
public:
Day();
Day(string WeekDays[]);
~Day();
void SetDay(string WeekDay);
void SetDay(int DayOfWeek);
string Today(void);
string Yesterday(void);
string Tomorrow(void);
string operator +(int Number);
string operator -(int Number);
} ;Day::Day()
{
TodayIndex = 0;
}
Day::Day(string WeekDays[])
{
TodayIndex = 0;
for(int d=0;d<WeekDays->length();d++)
Days[d] = WeekDays[d];
}
Day::~Day()
{
}
void Day::SetDay(string WeekDay)
{
for(int d=0;d<7;d++)
{
if(Days[d] == WeekDay)
TodayIndex = d;
}
}
void Day::SetDay(int DayOfWeek)
{
if(DayOfWeek > -1 || DayOfWeek < 7)
TodayIndex = DayOfWeek;
}
string Day::Today(void)
{
return Days[TodayIndex];
}string Day::Yesterday(void)
{
int y = (TodayIndex-1)%7;
return Days[y];
}string Day::Tomorrow(void)
{
int t = (TodayIndex+1)%7;
return Days[t];
}
string Day::operator+ (int Number)
{
TodayIndex += Number%7;
return Days[TodayIndex];}
string Day::operator- (int Number)
{
TodayIndex -= Number%7;
return Days[TodayIndex];}
-------------------
Hope this helps some,
ChiThey mostly come at night...mostly

ok mine has problems too. i guess i should have tested first. i forgot a few things:
try this:
-------------------
#include <string>
#include <iostream>using namespace std;
class Day
{
private:
string Days[7];
int TodayIndex;
public:
Day();
Day(string WeekDays[]);
~Day();
void SetDay(string WeekDay);
void SetDay(int DayOfWeek);
string Today(void);
string Yesterday(void);
string Tomorrow(void);
Day operator +(int Number);
Day operator -(int Number);
} ;Day::Day()
{
Days[0] = "MON";
Days[1] = "TUE";
Days[2] = "WED";
Days[3] = "THU";
Days[4] = "FRI";
Days[5] = "SAT";
Days[6] = "SUN";
TodayIndex = 0;
}
Day::Day(string WeekDays[])
{
TodayIndex = 0;
for(int d=0;d<WeekDays->length();d++)
Days[d] = WeekDays[d];
}
Day::~Day()
{
}
void Day::SetDay(string WeekDay)
{
for(int d=0;d<7;d++)
{
if(Days[d] == WeekDay)
TodayIndex = d;
}
}
void Day::SetDay(int DayOfWeek)
{
if(DayOfWeek > -1 || DayOfWeek < 7)
TodayIndex = DayOfWeek;
}
string Day::Today(void)
{
return Days[TodayIndex];
}string Day::Yesterday(void)
{
int y = (TodayIndex-1)%7;
return Days[y];
}string Day::Tomorrow(void)
{
int t = (TodayIndex+1)%7;
return Days[t];
}
Day Day::operator+ (int Number)
{
Day temp;
temp.SetDay(TodayIndex);
temp.TodayIndex += Number%7;
return temp;}
Day Day::operator- (int Number)
{
Day temp;
temp.SetDay(TodayIndex);
temp.TodayIndex -= Number%7;
return temp;}
-------------------
#pragma argsused
int main(int argc, char* argv[])
{
Day mDay;
cout << mDay.Today() << endl;
mDay = mDay + 1;
cout << mDay.Today() << endl;
char dummy;
cin >> dummy;
return 0;
}
-------------------
ChiThey mostly come at night...mostly

haha yeah i know it was messed up. thanks but i dont want to use arrays i just want to use maybe an if else loop or for loops. i know you can't return in a void method, i wrote that about a month ago and havent modified it just thought i would get some input. maybe you can take my program and just add and change a few things? thank you so much.
"you can't implement me, i'm outside your scope!"

"maybe you can take my program and just add and change a few things?"
nah, thanks for the offer, but mine works well.
Chi
They mostly come at night...mostly

![]() |
java ide
|
jsp front end creation
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |