## shahpur2004's Profile User Rating:

Reputation: 0 Apprentice
Group:
Members
Active Posts:
31 (0.05 per day)
Joined:
02-February 12
Profile Views:
677
Last Active:
Apr 30 2012 08:59 PM
Currently:
Offline

### Previous Fields

Dream Kudos:
0
shahpur2004 has not set their status

1. #### In Topic: I have a Date class how can I make two of it's function work prope

Posted 30 Apr 2012

I figured out that function, but do you have any suggestion for this function.
I think my if statements are not coded well that is why it is not working specially for the month of februar and for the leap years.
```[void Date::SetDate(int requestedyear, int month, int day )
{
if (requestedyear < 0)
{
cout<<"Sorry we do not have data for this year.";
return;
}

else
year = requestedyear;

if (month > 12 || month < 0 )
{
cout<<"Invalid month entry."<<endl;

}

numOfmonth = month;

if (month ==2)
{
if(year%400==0&&year%4==0)
{
if (numOfmonth = 2)
{
numOfday = 29;
}

}

else if(year%100)
{
if (numOfmonth == 2 && numOfday == 29)
{
--numOfday;
}

}
else if (day > 28)
cout << " Invalid day entry for month of February.";

}
else if (month == 9 || month == 4 || month == 6 || month == 11 )
{
if (day > 30)
cout << " Invalid day entry.";

}
if ( day > 31 )
cout<<"Invalid day entry."<<endl;

else
numOfday = day;

}
]
```
2. #### In Topic: I have a Date class how can I make two of it's function work prope

Posted 30 Apr 2012

r.stiltskin, on 30 April 2012 - 06:35 PM, said:

shahpur2004, on 30 April 2012 - 09:22 PM, said:

Adanceoneday function does not have argument I could not pass the argument of the AdvanceDays to the Advanceonedays if you have any suggestions I would be very glade.

This should be obvious to you if you think about it.

Suppose you have a button and each time you press the button it rings a bell 1 time. What would you do if you want to ring the bell 3 times?

It is sample I should press it three times but I think it not the case. Do you mean I should call the function three times.
```[void Date::AdvanceDays(int n)
{
Date da;
da.AdvanceOneDay(); //if I pass n in the Advanceongday function it gives me an error.
}
]
```
3. #### In Topic: I have a Date class how can I make two of it's function work prope

Posted 30 Apr 2012

jimblumberg, on 30 April 2012 - 06:29 PM, said:

Post your code in the post body in code tags.

Quote

Right now I am testing my code but two functions are not working properly;

Why are they not working properly? Ask specific questions.

Jim

I think my if statements are not coded well that is why it is not working
```[void Date::SetDate(int requestedyear, int month, int day )
{
if (requestedyear < 0)
{
cout<<"Sorry we do not have data for this year.";
return;
}

else
year = requestedyear;

if (month > 12 || month < 0 )
{
cout<<"Invalid month entry."<<endl;

}

numOfmonth = month;

if (month ==2)
{
if(year%400==0&&year%4==0)
{
if (numOfmonth = 2)
{
numOfday = 29;
}

}

else if(year%100)
{
if (numOfmonth == 2 && numOfday == 29)
{
--numOfday;
}

}
else if (day > 28)
cout << " Invalid day entry for month of February.";

}
else if (month == 9 || month == 4 || month == 6 || month == 11 )
{
if (day > 30)
cout << " Invalid day entry.";

}
if ( day > 31 )
cout<<"Invalid day entry."<<endl;

else
numOfday = day;

}
]

```
4. #### In Topic: how to make these vectors work properly

Posted 16 Apr 2012

David W, on 12 April 2012 - 02:23 PM, said:

Since you know in advance of compile time that all you are 'tracking' is words with length 1 to 10 characters long ...

you could just use an array of 10 int's initialed to 0

int word_len[ 11 ] = { 0 } ; // not going to use index 0

Then all you need is something like this:
```cout << "Enter a word ('END' to end) : " << flush;
while( cin >> word && word != "END" )
{
if( word.size() && word.size() < 11 )
++word_len[ word.size() ];
cout << "Enter a word ('END' to end) : " << flush;
}

```

thank you very much it helped me a lot.
5. #### In Topic: how to make these vectors work properly

Posted 12 Apr 2012

sepp2k, on 12 April 2012 - 01:27 PM, said:

Create a vector containing 10 zeros. Then instead of writing an if for every number between 1 and 10, simply check that the number is between 1 and 10 and then increase the number in the vector at the appropriate index (i.e. if the entered number is 1, increase the_vector[0], if it is 2, increase the_vector[1] etc. - clearly you don't need if statements for that).

this is the mean assignment
Write a program that reads in a list of words from the user until the user enters the word “END”.
Then, display a list of word lengths, from 1 to 10, and how many words of each length were entered.
For instance, after the user had typed 20 words, the output might look something like:
Length 1 words: 2
Length 2 words: 3
Length 3 words: 5
Length 4 words: 6
Length 5 words: 3
Length 6 words: 2

Member Title:
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

E-mail:
Private