|
| |||||||
| http://www.narutomania.com/forums/New Month, New Problems |
| For these forums to remain up we need $480 within 7 days. Please donate HERE br> br> We need this amount no matter what to keep this website up. Thank you for your support. |
![]() |
| | Thread Tools |
01-02-2008, 01:42 AM
| #1041 |
| Akatsuki |
Is token a string that you made up? and what exactly is the sstream library?
__________________ ![]() ![]() thanks to Tom, ~Mrge and Simonarturo, EE |
| |
01-02-2008, 02:00 AM
| #1042 | |
| Donator | 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:
| |
| |
01-02-2008, 05:33 AM
| #1043 |
| Akatsuki |
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 |
| |
01-02-2008, 03:29 PM
| #1044 | ||
| Donator | Quote:
Quote:
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. | ||
| |
01-02-2008, 05:07 PM
| #1045 |
| Akatsuki |
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 |
| |
01-02-2008, 05:44 PM
| #1046 |
| Donator |
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. |
| |
01-02-2008, 05:58 PM
| #1047 |
| Akatsuki |
#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 |
| |
01-02-2008, 06:16 PM
| #1048 |
| Donator |
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;
}
Code: if (aCard.getRank() > 10) Alternatively, you can add a Code: bool Card::operator>(int tocompare) {
return (rank > tocompare);
}
Code: if (aCard > 10) Last edited by MuKen; 01-02-2008 at 06:25 PM. Reason: Code tags are handy! |
| |
01-02-2008, 06:27 PM
| #1049 |
| Akatsuki |
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. |
| |
01-02-2008, 06:42 PM
| #1050 |
| Donator |
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...
|
| |
01-02-2008, 06:47 PM
| #1051 |
| Akatsuki |
it's not showing up as K, Q
__________________ ![]() ![]() thanks to Tom, ~Mrge and Simonarturo, EE |
| |
01-02-2008, 06:57 PM
| #1052 |
| Donator |
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.
|
| |
01-02-2008, 09:11 PM
| #1053 |
| Akatsuki |
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 |
| |
01-02-2008, 11:53 PM
| #1054 |
| Donator |
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];
}
The "<dummy>" is because you have no rank 0 card. Last edited by MuKen; 01-02-2008 at 11:55 PM. |
| |
02-02-2008, 12:02 AM
| #1055 |
| Special Jounin |
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 |
| |
02-02-2008, 12:29 AM
| #1056 | |
| Kazekage | Quote:
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. | |
| |
03-02-2008, 08:02 PM
| #1057 |
| Hunter-nin |
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.
__________________ |
| |
04-02-2008, 04:04 AM
| #1058 | |
| Genin | Quote:
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 | |
| |
04-02-2008, 04:15 AM
| #1059 | ||
| Genin | Quote:
I did explain that here on how to evaluate int. sin x/cos x dx Quote:
| ||
| |
04-02-2008, 06:12 PM
| #1060 |
| Akatsuki |
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 |
| |