Go Back   Naruto & Bleach Mania Forums > General Discussion > General Discussion & News
User CP Rules & Info Arcade Gallery

http://www.narutomania.com/forums/New Month, New Problems
For these forums to remain up we need $480 within 7 days. Please donate HERE We need this amount no matter what to keep this website up. Thank you for your support.

Reply
 
Thread Tools
Old 01-02-2008, 01:42 AM   #1041
Akatsuki
 
Ice(v)an's Avatar


Join Date: Nov 2004
Location: Urahara Store
Posts: 9,394
My Mood:
Rep Power: 36
Ice(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant future

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

Is token a string that you made up?

and what exactly is the sstream library?
__________________



thanks to Tom, ~Mrge and Simonarturo, EE
Ice(v)an is offline   Reply With Quote
Old 01-02-2008, 02:00 AM   #1042
Donator
 
MuKen's Avatar


Join Date: May 2006
Location: New York City
Posts: 2,649
My Mood:
Rep Power: 21
MuKen has a brilliant futureMuKen has a brilliant futureMuKen has a brilliant future

Basic Gold Basic Bronze Basic Silver 
Total Awards: 3

Default Re: Homework Help v1.3

Quote:
Originally Posted by Ice(v)an View Post
Is token a string that you made up?
It's just a name, you could use any name for that string. It gets filled in at the line "tokenizer >> token" to contain one word from the input line at a time.

Quote:
and what exactly is the sstream library?
It contains the stringstream class, which allows you to break up a line by spaces.
MuKen is offline   Reply With Quote
Old 01-02-2008, 05:33 AM   #1043
Akatsuki
 
Ice(v)an's Avatar


Join Date: Nov 2004
Location: Urahara Store
Posts: 9,394
My Mood:
Rep Power: 36
Ice(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant future

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

I think my program should start out with 52 cards and just randomly evaluate bridge hands, like 3C or 5D, etc.

The code you gave me what I type is what I see on the screen.
__________________



thanks to Tom, ~Mrge and Simonarturo, EE
Ice(v)an is offline   Reply With Quote
Old 01-02-2008, 03:29 PM   #1044
Donator
 
MuKen's Avatar


Join Date: May 2006
Location: New York City
Posts: 2,649
My Mood:
Rep Power: 21
MuKen has a brilliant futureMuKen has a brilliant futureMuKen has a brilliant future

Basic Gold Basic Bronze Basic Silver 
Total Awards: 3

Default Re: Homework Help v1.3

Quote:
Originally Posted by Ice(v)an View Post
I think my program should start out with 52 cards and just randomly evaluate bridge hands, like 3C or 5D, etc.
Ah, well if you are supposed to randomly generate the hands, then you don't need getline after all.

Quote:
The code you gave me what I type is what I see on the screen.
Did what you type have any spaces? The purpose of the code is to split things up by spaces.

You entire a line and press "enter", then it prints back what you wrote with each word on a separate line.

Last edited by MuKen; 01-02-2008 at 04:44 PM.
MuKen is offline   Reply With Quote
Old 01-02-2008, 05:07 PM   #1045
Akatsuki
 
Ice(v)an's Avatar


Join Date: Nov 2004
Location: Urahara Store
Posts: 9,394
My Mood:
Rep Power: 36
Ice(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant future

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

Cards aCards;
cout<<endl;
if(aCards >10)
{
//blah blah blah
}

how come if(aCards >10)
doesn't work?
__________________



thanks to Tom, ~Mrge and Simonarturo, EE
Ice(v)an is offline   Reply With Quote
Old 01-02-2008, 05:44 PM   #1046
Donator
 
MuKen's Avatar


Join Date: May 2006
Location: New York City
Posts: 2,649
My Mood:
Rep Power: 21
MuKen has a brilliant futureMuKen has a brilliant futureMuKen has a brilliant future

Basic Gold Basic Bronze Basic Silver 
Total Awards: 3

Default Re: Homework Help v1.3

What is "Cards", is that a class you defined? If so, unless you wrote a ">" operator function for it, you won't be able to do aCards > anything.

Post up the code for the class and I can help you make the comparison work (although for an assignment like this writing a class for cards really isn't necessary).

Last edited by MuKen; 01-02-2008 at 05:49 PM.
MuKen is offline   Reply With Quote
Old 01-02-2008, 05:58 PM   #1047
Akatsuki
 
Ice(v)an's Avatar


Join Date: Nov 2004
Location: Urahara Store
Posts: 9,394
My Mood:
Rep Power: 36
Ice(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant future

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>

using namespace std;

class Cards
{
public:
Cards();
//int getFunction();
//void setRank(int highCards);

private:
int rank;
};

int main()
{
Cards aCards; // creates a cards object and generates 13 numbers.
cout<<endl;
int x;


char J,Q,K,A;

//how to turn numbers higher than ten to Aces, Kings, Queens and Jack.
/*if(x ==11)
{
x = J;

if(x ==12)
{
x = Q;

if(x==13)
{
x =K;

if (x==14)
{
x = A;
}
}
}
} */



system("PAUSE");
return 0;
}


Cards :: Cards()//default constructor
{
srand((unsigned)time(0));
int rank;
int lowest =1, highest=14;
int range=(highest-lowest)+1;

for(int index=0; index != 13; index++)
{
rank =lowest+int(range*rand()/(RAND_MAX + 1.0));
cout<<rank<<", ";
}
} // the code above will generate a random rank(integer) from 1 to 14

/*int Cards :: getFunction()
{
return rank ;
}

void Cards :: setRank(int highCards)
{
rank = highCards;
}
*/
//possibility don't need get or set.


This is what I have for now.
I'm using a class because that's what i'm familiar with.
I don't really understand the getline/stream stuff
__________________



thanks to Tom, ~Mrge and Simonarturo, EE
Ice(v)an is offline   Reply With Quote
Old 01-02-2008, 06:16 PM   #1048
Donator
 
MuKen's Avatar


Join Date: May 2006
Location: New York City
Posts: 2,649
My Mood:
Rep Power: 21
MuKen has a brilliant futureMuKen has a brilliant futureMuKen has a brilliant future

Basic Gold Basic Bronze Basic Silver 
Total Awards: 3

Default Re: Homework Help v1.3

Ok, so what you are trying to do is compare the rank of the "Cards" (you should really name this "Card" since each object corresponds to a single card).

To do this, you either need to add a

Code:
int Card::getRank() {
  return rank;
}
so you can do

Code:
if (aCard.getRank() > 10)
---------

Alternatively, you can add a

Code:
bool Card::operator>(int tocompare) {
  return (rank > tocompare);
}
and that will allow your

Code:
if (aCard > 10)
to work.

Last edited by MuKen; 01-02-2008 at 06:25 PM. Reason: Code tags are handy!
MuKen is offline   Reply With Quote
Old 01-02-2008, 06:27 PM   #1049
Akatsuki
 
Ice(v)an's Avatar


Join Date: Nov 2004
Location: Urahara Store
Posts: 9,394
My Mood:
Rep Power: 36
Ice(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant future

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

if(aCard.getRank() ==11)
{


if(aCard.getRank() ==12)
{


if(aCard.getRank()==13)
{


if (aCard.getRank()==14)
{

}
}
}
}

how do I change rank to those cards? Aces, Kings, Queens.

If the random generate a 13, i want to change it to K, how can I do that?

I can't do aCard = k right?

I was thinking of doing a set function, but you can't set a int = char
__________________



thanks to Tom, ~Mrge and Simonarturo, EE

Last edited by Ice(v)an; 01-02-2008 at 06:31 PM.
Ice(v)an is offline   Reply With Quote
Old 01-02-2008, 06:42 PM   #1050
Donator
 
MuKen's Avatar


Join Date: May 2006
Location: New York City
Posts: 2,649
My Mood:
Rep Power: 21
MuKen has a brilliant futureMuKen has a brilliant futureMuKen has a brilliant future

Basic Gold Basic Bronze Basic Silver 
Total Awards: 3

Default Re: Homework Help v1.3

You should keep storing the ranks as ints (K as 13), so that you can do comparisons.

Only later when you print out the cards do you need to convert that to letters as appropriate. You can have a function like

Code:
void Card::printName() {
  if (rank <= 10) {
    cout << rank;
  } else {
    if (rank == 11) {
      cout << "J";

....etc...
or use a switch statement if you are familiar with those.
MuKen is offline   Reply With Quote
Old 01-02-2008, 06:47 PM   #1051
Akatsuki
 
Ice(v)an's Avatar


Join Date: Nov 2004
Location: Urahara Store
Posts: 9,394
My Mood:
Rep Power: 36
Ice(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant future

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

it's not showing up as K, Q
__________________



thanks to Tom, ~Mrge and Simonarturo, EE
Ice(v)an is offline   Reply With Quote
Old 01-02-2008, 06:57 PM   #1052
Donator
 
MuKen's Avatar


Join Date: May 2006
Location: New York City
Posts: 2,649
My Mood:
Rep Power: 21
MuKen has a brilliant futureMuKen has a brilliant futureMuKen has a brilliant future

Basic Gold Basic Bronze Basic Silver 
Total Awards: 3

Default Re: Homework Help v1.3

I mean you should keep it as 13, 12, etc. and write your own function to print those as K,Q when you need to.
MuKen is offline   Reply With Quote
Old 01-02-2008, 09:11 PM   #1053
Akatsuki
 
Ice(v)an's Avatar


Join Date: Nov 2004
Location: Urahara Store
Posts: 9,394
My Mood:
Rep Power: 36
Ice(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant future

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

Yeah I'm trying to print it out but it's not showing it up as K etc
__________________



thanks to Tom, ~Mrge and Simonarturo, EE
Ice(v)an is offline   Reply With Quote
Old 01-02-2008, 11:53 PM   #1054
Donator
 
MuKen's Avatar


Join Date: May 2006
Location: New York City
Posts: 2,649
My Mood:
Rep Power: 21
MuKen has a brilliant futureMuKen has a brilliant futureMuKen has a brilliant future

Basic Gold Basic Bronze Basic Silver 
Total Awards: 3

Default Re: Homework Help v1.3

Here's an easy hack you can do for this sort of thing

Code:
const string CardNamer[] = {
  "<dummy>", "A", "2", "3", "4", "5",
  "6", "7", "8", "9", "10",
  "J", "Q", "K"};

void Card::PrintName() {
  cout << CardNamer[rank];
}
CardNamer is a global array of card names, and when you index it with a card's rank you get the appropriate letter/number.

The "<dummy>" is because you have no rank 0 card.

Last edited by MuKen; 01-02-2008 at 11:55 PM.
MuKen is offline   Reply With Quote
Old 02-02-2008, 12:02 AM   #1055
SOL
Special Jounin
 
SOL's Avatar


Join Date: May 2007
Location: サンタテレサ
Posts: 3,645
My Mood:
Rep Power: 14
SOL is a name known to allSOL is a name known to all
Send a message via MSN to SOL
Default Re: Homework Help v1.3

i need help on some simple extra credit geometry questions.

k. heres 1. A 5-inch by 8 inch photo was enlarged to make a poster. If the dimensions of the poster are (x2-6)inches by (x2+12)inches, what is the area of the poster?

anyone help me? there are more but they have diagrams and i cant put them on here
__________________
YL

---------------------
---------------------
Brawl:
5241-1958-3155

Mario Kart:
3695-0615-8035
SOL is offline   Reply With Quote
Old 02-02-2008, 12:29 AM   #1056
Kazekage
 
batman555's Avatar


Join Date: Jan 2005
Posts: 12,554
My Mood:
Rep Power: 666
batman555 has a reputation beyond reputebatman555 has a reputation beyond reputebatman555 has a reputation beyond reputebatman555 has a reputation beyond reputebatman555 has a reputation beyond reputebatman555 has a reputation beyond reputebatman555 has a reputation beyond reputebatman555 has a reputation beyond reputebatman555 has a reputation beyond reputebatman555 has a reputation beyond repute

Basic Gold Basic Silver Lions Heart Superior Green Award High Bronze Award Intermediate Silver Award Intermediate Gold Award Intermediate Silver Award 
Total Awards: 8

Default Re: Homework Help v1.3

Quote:
Originally Posted by cass View Post
i need help on some simple extra credit geometry questions.

k. heres 1. A 5-inch by 8 inch photo was enlarged to make a poster. If the dimensions of the poster are (x2-6)inches by (x2+12)inches, what is the area of the poster?

anyone help me? there are more but they have diagrams and i cant put them on here
Since the original photo was enlarged, then the poster is proportional to the photo. Thus, you can set up a proportion:

5/8 = (x^2-6)/(x^2+12)

Solve for x by cross multiplying (Don't let the x^2 term scare you; in this case, you'll get a whole number):

5*(x^2+12) = 8*(x^2-6)

Let W = x^2-6 and L = x^2+12

Plug it back into the the equations above. Then W*L will give you the area of the poster.

When you set up proportions, it doesn't matter which one is on top or which one is on the bottom in the fractions, as long as you are consistent with corresponding sides.

I hope this helps.
__________________

Last edited by batman555; 02-02-2008 at 12:31 AM.
batman555 is offline   Reply With Quote
Old 03-02-2008, 08:02 PM   #1057
Hunter-nin
 
DeathGuiseX's Avatar


Join Date: Feb 2005
Location: East Side, NERV
Posts: 2,390
My Mood:
Rep Power: 31
DeathGuiseX has a reputation beyond reputeDeathGuiseX has a reputation beyond reputeDeathGuiseX has a reputation beyond reputeDeathGuiseX has a reputation beyond reputeDeathGuiseX has a reputation beyond repute
Send a message via AIM to DeathGuiseX
Default Re: Homework Help v1.3

I was just introduced to Integration by parts.

How do you do: int. (xe^x)/((x+1)^2) dx

And also int. arctan x dx. For this one, I got up to xarctanx - int. x/(x^2 + 1) dx, but I dont know how to integrate that part.
__________________
DeathGuiseX is offline   Reply With Quote
Old 04-02-2008, 04:04 AM   #1058
Genin


Join Date: Oct 2005
Posts: 75
Rep Power: 0
ahme has much to be proud ofahme has much to be proud ofahme has much to be proud of

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

Quote:
Originally Posted by DeathGuiseX View Post
I was just introduced to Integration by parts.

How do you do: int. (xe^x)/((x+1)^2) dx
∫ x e^x/((x+1)^2) dx I'll call this integral I

Let's stop and think for a little. In integration by parts, you take a product of two functions and make one of them u and the other dv.
∫u*dv = u*v - ∫v*du
Here, we have two types of functions: the exponential is the first and the fraction being the other. We know that the derivative and integral of e^x is e^x so let's look at the other function. If I make u = x/(x+1)^2, I'll just make the problem even worse because the degree of the denominator will increase. It's decided, let's take u=e^x and dv=x/(x+1)^2 dx so du=e^x dx
v = ∫x/(x+1)^2 dx = ln(x+1)+1/(x+1) (This is an easy integral if you just make the substitution z = x+1)

I = e^x*ln(x+1) + e^x/(x+1) - ∫(e^x*ln(x+1)+e^x/(x+1))dx
I2 = ∫(e^x*ln(x+1)+e^x/(x+1))dx
Let's deal with each integral separately: I3=∫(e^x*ln(x+1)) dx
In I3, you'll need to do integration by parts again. And using the same reasoning stated above, you should take u = ln(x+1) and dv=e^x dx
If you work out the integral, you get I3 = e^x ln(x+1)-∫(e^x/(x+1))dx
I2 = I3 + ∫(e^x*ln(x+1))dx
I2 = e^x*ln(x+1) + C
I = e^x*ln(x+1) + e^x/(x+1) - e^x*ln(x+1) + C
I = e^x/(x+1) + C
ahme is offline   Reply With Quote
Old 04-02-2008, 04:15 AM   #1059
Genin


Join Date: Oct 2005
Posts: 75
Rep Power: 0
ahme has much to be proud ofahme has much to be proud ofahme has much to be proud of

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

Quote:
Originally Posted by DeathGuiseX View Post
And also int. arctan x dx. For this one, I got up to xarctanx - int. x/(x^2 + 1) dx, but I dont know how to integrate that part.
How do we evaluate int. x/(x^2 + 1) dx?
I did explain that here on how to evaluate int. sin x/cos x dx

Quote:
Originally Posted by ahme View Post
Just take u = cos x and go from there.
One trick to solve integration in the form of coefficients is to see if the numerator is the denominator's derivative or the denominator's derivative multiplied by a constant.
Well here we have the derivative of cos x which is - sin x. Bingo! blindly take the u = cos x and make the substitution. u = cos x then du = - sin x dx thus sin x / cos x dx = 1 / u . -du

Now, given the hint you instructor gave, it should be very easy to do the integral.
ahme is offline   Reply With Quote
Old 04-02-2008, 06:12 PM   #1060
Akatsuki
 
Ice(v)an's Avatar


Join Date: Nov 2004
Location: Urahara Store
Posts: 9,394
My Mood:
Rep Power: 36
Ice(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant future

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

Second Assignment,

finding the kth smallest item in an array. Implement this idea and use it to form the basis for a percentile function. This function should take two arguments, an array or vector of numbers A and a percentile p. It should return the number n in A such that p percent of all items in A are smaller than n.



This specification is intentionally a little imprecise. For example, it will normally be the case that no number in A exactly fits the definition, although one or more comes close. You'll need to decide what to return in that case. Be sure to document your choices and assumptions thoroughly.



Test and demonstrate your percentile function by embedding it in a program that generates sets of random numbers and then finds various percentiles in each set.
__________________



thanks to Tom, ~Mrge and Simonarturo, EE
Ice(v)an is offline   Reply With Quote
Reply