no. the k is passed in from main. So k can be any number.
For example, inside you main :
int main()
{
binomial(5, 10); // here k = 10;
binomial(3, 276); // here k is 276
}
no. the k is passed in from main. So k can be any number.
For example, inside you main :
int main()
{
binomial(5, 10); // here k = 10;
binomial(3, 276); // here k is 276
}
thank you that would be great:icon_cheesygrin:.
and no, I don't have glut.h. I wouldn't use it (I make my windows with the win32 api) but its a pain when I'm trying to see how other peoples code works
You could still download glut just to see other programs, but you
don't have to use it.
Modulo 10?
eg:
54%10 = 4
TO expand x % 100 will give you the last 2 digits, and x % 1000 will
give you last 3 digits, and in general :
x % 10^n will give you the last n digits. IN the special case
where n = 0, the result will always be 0, since you ask to get the last "0" digits, which does not make sense.
SNIP
This is basically what I do in my free time :
1) Procrastinate ( of course )
2) Try to learn more things about programming
3) Practice programing
4) Play NBA2k9 and/or Call of Duty : modern warfare 2 (awesome games)
5) Chill with friends and laugh at stupid things
6) Maybe do some school work.
Cool we have so much in common. Only if you were a girl.
For part a) make a copy. For that copy, uppercase the first letter. Print it backwards.
For part d) make a copy. Swap certain positions. Print out the copy
backwards.
>Does anyone have code out there on how to do this?
Assuming this is homework, you don't really learn anything by stealing another programmer's code and palming it off as your own.
Sure you do. You learn the intricate art of stealing programs and
plagiarizing it, while feeling completely not guilty handing in the
work to the teacher, which leads to more plagiarism ( a drug ) because
he hasn't learned crap and now when the final comes, he will shi*t his
pants because the final will look like a foreign language.
Other than that I don't think he will gain anything important.
Good Luck!
Overload the boolean operator.
I don't know if you need precision with floats
but I will use floats, but you can easily just change its type if needed.
For y = -sqrt( r - x^2) you can do this :
const unsigned short R = 5;
//our boundaries of our graph
const unsigned int MIN = 0;
const unsigned int MAX = 10;
float y = 0.0f;
float x = 0.0f;
const float STEP = 0.1f;
//warninig : floats are slow in a loop,
//but for now we don't care about speed, right?
for(x = MAX; x < MAX; x+= STEP){
y = - sqrt( R - x*x );
plotGraph(x,y);
}
Assuming your plotGraph plots points, that should plot the bottom
half of the circle. Now you can either do the same this in another for loop for the top circle or make new variables and do it inside that loop.
I remember some of the sides in their cube was purposely distorted,
while other sides were not. Did first you just unzip it and run the .exe ?
The error means that you do not have glut.h ? Do you ?
Lets forget about a template swap for now.
Then A better swap than the above is this :
void swap(int &left, int &right){
int temp = left;
left = right;
right = temp;
}
Think about why that is.
This should work. However, your all of your function does not
necessarily return something. Also use code goes here
// Purpose: Complete the program to allow the entering of 3 integer
// numbers and have the program calculate the average, maximum,
// and minimum.
//------------------------------------------------------------------------
#include <iostream>
#include <cmath>
using namespace std;
//-----------------------------------
void Display(float AveXYZ, float maxXYZ, float minXYZ);
float ComputeAve(float x,float y,float z);
float FindMax(float x, float y, float z);
float FindMin(float x, float y, float z);
//-----------------------------------
int main()
{
float x, y, z;
//read data into x, y, and z
cout << "Enter 3 integer numbers: ";
cin >> x >> y >> z;
//compute the average of x, y, and z
float AveXYZ;
AveXYZ = ComputeAve(x,y,z);
//Find the maximum of x, y, and z
float maxXYZ;
maxXYZ = FindMax(x,y,z);
//Find the minimum of x, y, and z
float minXYZ;
minXYZ = FindMin(x,y,z);
//Display average, maximum, and minimum
Display(AveXYZ, maxXYZ, minXYZ);
//terminate program
return 0;
}
//-----------------------------------
// Name: ComputeAve
// Input: the average equation
// Output: the average of x,y,z
//-----------------------------------
float ComputeAve(float x, float y, float z)
{
return (x+y+z)/3;
}
//-----------------------------------
// Name: FindMax
// Input: None
// Output: The Maximum
//-----------------------------------
float FindMax(float x, float y, float z)
{
if (x > y && x > z)
{return x;}
if (y > x && y > z)
{return y;}
if (z > x && z > y)
{return z;}
}
//-----------------------------------
// Name: FindMin
// Input: None
// Output: The …
I suggest make a binary tree class and make the printing function.
Add a few numbers. And print them out pre,post, and mid. Examine the
output. Try to construct a binary tree from the output. You will then realize the pattern.
When printing a binary tree you can either print it in pre, mid, or post
order. I am not going to explain all of these. You should google them.
The usual way one would display a binary tree is by either one of the printing methods from above, pre ,post or min.
The way below is mid order :
void _recursivePrint(_Node* &Parent){
if(Parent != _NULL){
_recursivePrint(Parent->leftChild);
std::cout << Parent->data.var <<" ";
_recursivePrint(Parent->rightChild);
}
else return;
}
A per order would put the cout statement before the parent->leftChild
recursive call and a post order would put it after the recursive call
parent->rightChild.
What it does is it first goes all the way to the left most node. And prints
it. If the left most node has a right node, then it prints that. It "goes"
up the tree like that. Google it, better explanation out there. Its late
so I can't use my brain much.
You minXYZ and your maxXYZ function name should be :
FindMin and FindMax.
So replace the word minXYZ with FindMin and replace your maxXYZ with
FindMax.
Your function prototype and your function definition are not the same.
You have
void Display(float AveXYZ, int maxXYZ, int minXYZ);
float ComputeAve(int x,int y,int z);
float FindMax(int x, int y, int z);
float FindMin(int x, int y, int z);
Does this match the definition that you provide? Are the names the
same for the prototype and the definition?
post your current code.
All right if you must.
You have the equation of the circle : (x-a)^2+(y-b)^2=r^2
Lets say its centered at the origin for now, so the equation now
becomes x^2 + y^2 = r^2.
Lets say is a unit circle, so the equation becomes :
x^2 + y^2 = 1
Now to be easier lets do this in a two step process.
since x^2 + y^2 = 1
then
y^2 = 1 - x^2
and
y = plus/minus sqrt( 1 - x^2 )
The plus/minus determine whether the circle is the top of the bottom half.
So the top half of the circle is y = + sqrt(1 - x^2) and the bottom half
of the circle is y = - sqrt(1 - x^2)
So our 2 step process is to draw the top half first and then the bottom
half. And you can just make "1-x^2" , "r - x^2" where r is the radius.
Now can you convert the 2 function into 2 different 1 for loop algorithm?
Ouch, your logic is bad. You are killing your program slowly. Luckily it
fights back with the runtime exceptions.
Can you comment line by line so I see what your thinking process is.
That way you will learn better when you see whats wrong.
Ok thats a start. Now you need to create a vector of size 26.
This is how to do that :
vector<int> numberOfOccurance(26,0); //create a vector of size 26 with each element initialized to 0
After that you need to read in the data character by character.
One way to do that is this :
char character = 0;
ifstream iFile("test.txt");
while( iFile.get(character) ){
//do logic here
}
So the variable character inside the loop contains the 1 character inside
the file. This happens on each loop until the end of file is reached.
the "do logic part" is where you should do the frequency counter.
Hint : google tolower and toupper function.
Or just return an array of strings, whichever one, both do the same
job and depending on the context, one might be better to use than the
other.
Can you give me an example, as to how to use this, because I want to set the range of numbers.
int main()
{
srand( time( 0 ) );
cout << rand() % 2 << endl;
}
So that doesn't matter if the string entered is an even or odd length?
Nope it does not matter. The check n != last makes it so. But just though about it, the check in the for loop should be :
for(int n = 0; n < last - n; ++n);
So I made that change.
We are not checking any value after the first + n and the last - n
reaches the same index or after the first reaches an index greater than first.
Try to make your own the first way you though about it. Then look
back at this example after you get that working. That way you
will understand it better.
look at this and see if it helps. Its a table for the "for loop"
<input> = 1001
//we check the first + n against the last - n element
//when n is 0 in our for loop
first last
1 1
//when n is 1 in our loop
first last
0 0
//now after that our first + n is greater than last - n so we stop.
Can you use polar coordinate, or this equation of the circle ?
for theta = 0 to theta < 360 degrees; ++theta{
x = cos(theta) * radius
y = sin(theta) * radius
//center* is where the circle should be centered at
drawAndFillPoint(x - centerX , y - centerY)
}
This function :
float Display(int x, int y, int z)
{
cout << "\tAverage= " << AveXYZ << endl;
cout << "\tMaximum= " << maxXYZ << endl;
cout << "\tMinimum= " << minXYZ << endl;
return 0;
}
1st should be a void function.
Seconds you meant :
float Display(int x, int y, int z)
{
cout << "\tAverage= " << x<< endl;
cout << "\tMaximum= " << y<< endl;
cout << "\tMinimum= " << z<< endl;
return 0;
}
Third, make the x,y,z a different variable name, something more meaningful.
You can do that or you can do what dkalita suggested.
To expand on his suggestion :
Say the input is "1001".
To check if it is a palindrome you need to compare the first value + n, to the last value - n.
Lets start :
// Input
<input > value = 10001 .
The first value is 1, and the last value is 1, the second value is 0 and
the second-last value is 0. Then the first value index is the same as
the second value index, so its a palindrome. Look at the table below:
n firstValue lastValue "1 0 0 0 1 "
------------------------------------------------
0 1 1
1 0 0
2 0 0
Hope you see how that works. Now lets put this into an algorithm :
string input = "";
cin >> input;
cout << isPalindrome(input); //define below
So what should it look like ? Well remember the example at the beginning of this post. Lets try to convert that into an algorithm.
bool isPalindrome(string str){
//we need to check the first + n and last - n and compare it so :
int last= str.size() - 1; //the - 1 is there because str.size() returns 1 plus the end
//if first equals last then we are pointing in the same index so
// that means it passed the last below
for(int n= 0; n < last - n; n++ ){
//compare each character, first + n …
>>denominator = 1*2*...*k
I hope you know thats not valid. 1 * 2 * 3 ... k is called the factorial of K
So if K was 5, the the denominator will be 1 * 2 * 3 * 4 * 5.
So make a function : unsigned long factorial(unsigned long num);
Where it returns the factorial of the parameters passed. So if num
was 5, then the call would be : denominator = factorial(5); // = 120
Fix that then post back, because there are other problems.
Hi i want to friendship with a cut girl if there is anyone intrested reply me plz:*
This is too funny. One of the few post that made me laugh. You made
my day thinkersgroup, anyone see the irony with his name?
Well,
The circumference of a circle is 2*pi*r, but 2*r is the diameter so its :
C = D*pi, where D is the diameter of the circle.
Now if we divide the circumference by the Diameter then we are
just left with pi :
D*pi / D = pi.
In experiments, if you calculate the perfect circumference of a circle,
meaning how long the circle is if we un-wound it, and divide that number
by its diameter, then we would get PI.
Additionally, there are a series representation of pi. And a interesting
fact is that people have used super computer to calculate more than 1 trillion digits of pi.
[
no need to empty the string... the are already empty.
And by the way isn't 3 the prime number of 123456789??
Nevertheless its always good to manually initialize a variable( it can't hurt). And no the answer is not 3.
what sodabread said. You do not need to worry about the alpha channels
right now. For now, your goal is to load in a image and texture it.
Did you try out their .exe to see the result.
so it just counts the whole amount of elements stored in that string including the space :S
Yes.
Unless I am misreading your post, you can just use the advise
in my first pot.
do something like this :
//inside main somewhere
stringstream ss; //the sstream I was talking about
string sentence = "";
getline(cin, sentence); //get input
string aWord = ""; // will contain each individual word
ss << sentence ; //put our while sentence inside the stream object
while (ss >> aWord){ //extract word by word
cout << aWord <<" has " << aWord.size() <<" letters\n";
}
You need to include<sstream> to use stringstream.
Start out with the rock paper scissor games.
I'll try to give you a psuedo code body. (Not saying its right though)
#include<iostream>
using namespace std;
//function prototype
char getRandom(); //return random rock , paper , or scissors
int main()
{
//create variables
char playerPick= 0;
char computerPick = 0;
bool playAgain = true;
while( playAgain == true )
{
//ask user to pick either rock, paper, or scissors
// now get input into playerPick
computerOption = generateRandom(); //get random rock , paper or scissors
//compare values
if playerPick equals computerPick then print its a tie
else if player has a rock check to see what the computer has and determine the proper output
else if player has paper, check to see what the computer has and determine the proper output
else if player has scissors, check to see what the computer has and determine the proper out put
//ask use to play again ?
// get input into the bool variable playAgain
}
//and we are done
return 0;
}
I am not sure the specification of your game, like score keeper and
things, but the game logic is the same.
Get this done first and worry about the hangman.
No :
string str = "12345";
cout << str.length() << endl;
String is an object, but it can be initialize without (), like
string str;
However if I define a user defined object, I must initialize it like:
myclass myobj();
How is it possibel to not use: () ?
The compiler will most likely mistake myobj as a function!
As Narue said, for default constructors, you do NOT need the
"()" after the object creation.
Try putting this after the eof bit is set :
cin.clear();
cin.sync();
>I have no clue on how to do this please help thank you
You'd better learn quickly how to deal with this situation without running to someone else for hand holding. The majority of the time, a programmer has no clue how to do something. That's why it's such a difficult field: we actually have to think and figure things out. :icon_rolleyes:But seriously, "I have no clue how to start" is synonymous with "I'm too stupid to be a programmer". It's like you're telling us not to waste our time helping you because it's a lost cause.
Yea, what he said.
You have this : "<< printMonth(x);"
In most of your function. Take out the "<<"
and let it just be printMonth().
You need to read the pixels. I guess you can take a snapshot of the
lenses. Then read in the data an trace pixels from there.
You need to do a little more :
int LoadBitmap(const char* filename)
{
GLubyte* pixels;
HBITMAP hbmp;
BITMAP bmp;
GLuint size;
GLenum format;
GLuint totalBytes;
texID++;
hbmp=(HBITMAP)LoadImage(GetModuleHandle(NULL), (LPWSTR)filename.c_str(), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
if(hbmp==NULL)
{
MessageBox(NULL,L"ERROR : CANNOT LOAD FILE!",L"IMAGE LOADING",MB_OK);
return -1;
}
GetObject(hbmp,sizeof(bmp), &bmp);
size = bmp.bmHeight*bmp.bmWidthBytes;
totalBytes = bmp.bmBitsPixel/8;
pixels = new GLubyte[size];
memcpy(pixels,bmp.bmBits,size);
DeleteObject(hbmp);
delete [] pixels;
return 1;
}
What sort of premutation? On what set?
Sure what part. There is a lot. You need to be more specific. Take it
part by part. Do you need help with input and output, vectors, algorithms,
what?
Not sure but here is a suggestiong. Look at the pixel where its way off
the average , so if a camera lens is white , then its average should be
close to white. If there is a dirt on the lens, then its pixel will be
way of the average pixel, white. So now you detected the spot.
And to circle it, you can find the the radius of the spot by tracing the pixel, seeing where it reaches close to the average. Now you have the diameter, just using polar coordinates to draw a circle around the pixels.
Just a suggestion, don't know if it will work completely though.
Or you can just look at your lenses and clean them.
For bubble sort all you have to do is blindly swap :
int A[5] = {5,3,1,7};
//bubble sort
for(int i = 0; i < 5; i++){
for(int j = i+1; j < 5; j++)
if(A[i] > A[j] ) std::swap(A[i],A[j]);
}
Ouch. First off your code is not very readable. In fact there are statements
in your code that you probably think is doing something else than it does.
I think we need to take this step by step, for your sake and for my eyes.
So what is your main goal? You can't just dump some code and expect
us to know precisely what you want, you know?