Yes you can usesetprecision just like you are using setw.
mrnutty 761 Senior Poster
mrnutty 761 Senior Poster
Yes you can Overide any operator you want. This can be done globally or at a specific level.
http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.5
Learn the concept first! When I say learn it, I mean know it inside and out. Its easy to pick up a language once you get the concept down. Stick with one language for now, and use it for your needs. Program data structures using that language and become a master at it
You can basically do a 'binary split adding the middle every split. I tried coding something real quick and here it is:
#include <iostream>
#include <cmath>
#include <iterator>
#include <vector>
using namespace std;
template<typename T, typename Result>
void _splitImpl(T begin, T end, Result& result);
template<typename RandomAccessIterator>
std::vector<int> binarySplit(RandomAccessIterator begin, RandomAccessIterator end){
std::vector<int> result;
_splitImpl(begin,end,result);
return result;
}
template<typename T, typename Result>
void _splitImpl(T begin, T end, Result& result){
if(begin > end) return;
else{
size_t mid = std::distance(begin,end)/2;
result.push_back( *(begin + mid) );
_splitImpl( begin , begin + mid - 1, result);
_splitImpl(begin + mid + 1, end , result);
}
}
template<typename T>
void print(T begin, T end){
while(begin != end){ cout << *begin << " "; ++begin; }
}
int main(){
int a[] = {401, 414, 428, 431, 439, 444, 450, 456, 367, 372, 501, 515, 529, 554};
const int size = sizeof(a)/sizeof(*a);
print(a , a + size);
std::vector<int> result = binarySplit(a , a + size);
print(result.begin(), result.end());
}
That should get you going, but there is a bug there, a "off-by-one" bug which I'll leave for you to fix, because I need some sleep. Cheers!
firstly, you forogot the using directive. cout would be uindefined without it.
secondly it still give me the errors described. i think it's the template declarator that may be incorrect (not the function but what ever the code used to create the definition for template)
thirdly my syntax is correct:
return x==y ? 0 | 1
returns 0 if x != y and 1 if x == y see c++ operators for ?
I assumed you were smart enough to figure the implicit stuff out. Btw, you're trying to use ternary but you are using the wrong syntax, you want, return x == y ? 1 : 0
but even more simpler, just return x == y
You want :
template<typename T>
bool logicalAnd(T x, T y){
return x == y;
}
int main(){
int x = 3, y = 5;
cout << logicalAnd(x,y) << endl;
}
Btw, you probably don't want to use double underscore as an identifier because its reserve
Use sort via command line on the file
Yes, its called machine code. But you wouldn't want to do that. Google it, if you feel like procastinating for a little bit.
Pass them by reference. Its better than polluting globals.
Another way is to use java applets with JNI. You can use JNI to access C++ functions and then you can use java to use applets to embed them on the web.
What is wiggly jiggly curvy line? Either you can hardcode it or use other software to draw out the trajectory and then get the raw data points, then you can interpolate it into a equation.
Make it a template function. Other than that, I need to see more code
What do you have. If you have an equation for the trajectory, then you can simply use that equation as the position equation for the picture
Note: Pointer !== Array
Also for B), O(n+m) \in O(n) so you can just say O(n)
I think you're implementing it wrong. It should be,
if(CheckCollision(bPos, b_Width, b_Height, p1Pos, p1_Width, p1_Height))
{
Vector norm;
norm.myVector.x = 1;
norm.myVector.y = 0;
// i - (2 * n * dot(i, n))
bPos.myVector.x = bPos.myVector.x - 2 * norm.myVector.x * bPos.DotProduct(norm);
bPos.myVector.y = bPos.myVector.y - 2 * norm.myVector.y * bPos.DotProduct(norm);
}
}
You had an extra 2 term
Maybe you should look at the definition of artificial. Here it is.
Artificial:
1) Made or produced by human beings rather than occurring naturally, typically as a copy of something natural: "artificial light".
2) Not existing naturally; contrived or false: "the artificial division of people into age groups".
* found via google search, "define: artificial", without quotes
Why don't you just return std::string instead of char* ? Also you need to null terminate result1.
>>But it is always 0 after optimize
What does that tell you? That unless your doing this for a legitimate reason, you shouldn't have to worry about it
You need to resize the vector to M, then for each element in the vector, you need to resize each element to N, get it?
It evaluates to true. Work from inside out. Note 1 = true, 0 = false
Initial expression : (! (1 && !(0 || 1)))
inner most expression is (1 && !B)
where B = (0 || 1)
Since 1 = true, !B also needs to be true inorder for 1 && B to be true. So lets check out B. B = (0 || 1)
evaluates to true, because for the OR operator only one of the operands needs to be true. Since there is a 1 there, the whole B expression is true.
So now we have (1 && !1)
, we just substituted B for true, and that expression turns into (1 && 0)
which is false. Now we plug this into the initial expression : (!(1 && 0)) = !(0) = 1 = true
Yes, but if you want to do it that way, you need to do manual allocation.
void foo(string** strs, int width, int height){
//...
}
int main(){
int width = 0, height = 0;
cin >> height >> width;
string **strs = new string*[height];
for(int i = 0; i < height; ++i){
strs[i] = new string[width];
}
foo(strs, width, height);
}
You might want to skip doing manual memory management and possible use std::vectors
typedef std::vector<string> StringArray;
void foo(std::vector<StringArray>& arrayList){
//...
}
int main(){
int height = 0, width = 0;
cin >> height >> width;
std::vector<StringArray> myList(height , StringArray(width) );
foo(myList);
}
It depends on the definition. The second one might not even be allowed
>>Btw, if you don't know already, one of the best place to start with OpenGL is by going through the NeHe tutorials.
That's where I started a few years ago when I first started learning opengl, but now looking back, I believe it needs major updates, and the code written is not very good. They also use obsolete opengl functions. There are other up-to-date tutorial one can learn from, or better yet, read the RED book.
And btw, if you know trig/geometry/linear algebra, you should be fine! One would rarely use any higher mathematics.
If your comfortable with the math, you should be fine
Well I ran into a problem once again. I've misplaced my adapter for the monitor to my mini so I've broke down and pulled out my macbook. Will the link you gave me also work for intel based macs?
Yes they should work but check the specs
To offset sprite you can just add to its position, ball.x += 10; ball.y += 10;
Other than that, I'm not sure what you want
What do you mean move circle inside a square? You mean move the circle when a key is pressed? If so then in your display function check if certain key is pressed, if it is, increase xpos
Usually, think of lemma as a fact. Its like a theorem but just not as big fact.
public static int[] GreaterThanFive(int[] values)
{
int counter = 0;
int[] vals = new int[values.length];
for(counter = 0; counter < values.length; counter++)
{
if(values[counter] > 5)
{
vals[counter] = values[counter];
}
}
return vals;
}
Isn't correct. You need something like this :
public static int[] GreaterThanFive(int[] values)
{
int[] vals = new int[values.length];
int resultIndex =0 ;
for(int counter = 0; counter < values.length; counter++)
{
if(values[counter] > 5)
{
vals[resultIndex++] = values[counter];
}
}
return vals;
}
But there is also one problem with the above, the problem is that vals.length will be the same as values.length but vals might not contain all values greater than 5. So you might want to trim it.
What is the exact problem you are trying to solve?
It depends on the size of each cell in the graph. For example, if graph[0][0] is a rectangle of size 1 unit, then when the user presses right, you can move the sprite one unit to the right, and it would now be in graph[0][1]. And similary, if the user presses down, assuming he started at graph[0][0], you can move him one unit down, and now be in the location of graph[1][0] and so on
>>Who in God's name would use a struct like that? That is not what structs are there for.
It was an example, albiet not a complete one.
Just from a little googling, here is the code in the OpenGL Red Book.
#include <math.h>
#define X .525731112119133606
#define Z .850650808352039932
static GLfloat vdata[12][3] = {
{-X, 0.0, Z}, {X, 0.0, Z}, {-X, 0.0, -Z}, {X, 0.0, -Z},
{0.0, Z, X}, {0.0, Z, -X}, {0.0, -Z, X}, {0.0, -Z, -X},
{Z, X, 0.0}, {-Z, X, 0.0}, {Z, -X, 0.0}, {-Z, -X, 0.0}
};
static GLuint tindices[20][3] = {
{0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1},
{8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},
{7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6},
{6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11} };
void normalize(GLfloat *a) {
GLfloat d=sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);
a[0]/=d; a[1]/=d; a[2]/=d;
}
void drawtri(GLfloat *a, GLfloat *b, GLfloat *c, int div, float r) {
if (div<=0) {
glNormal3fv(a); glVertex3f(a[0]*r, a[1]*r, a[2]*r);
glNormal3fv(b); glVertex3f(b[0]*r, b[1]*r, b[2]*r);
glNormal3fv(c); glVertex3f(c[0]*r, c[1]*r, c[2]*r);
} else {
GLfloat ab[3], ac[3], bc[3];
for (int i=0;i<3;i++) {
ab[i]=(a[i]+b[i])/2;
ac[i]=(a[i]+c[i])/2;
bc[i]=(b[i]+c[i])/2;
}
normalize(ab); normalize(ac); normalize(bc);
drawtri(a, ab, ac, div-1, r);
drawtri(b, bc, ab, div-1, r);
drawtri(c, ac, bc, div-1, r);
drawtri(ab, bc, ac, div-1, r); //<--Comment this line and sphere looks really cool!
}
}
void drawsphere(int ndiv, float radius=1.0) {
glBegin(GL_TRIANGLES);
for (int i=0;i<20;i++)
drawtri(vdata[tindices[i][0]], vdata[tindices[i][1]], vdata[tindices[i][2]], ndiv, radius);
glEnd();
}
You can study it.
Yes it's possible to write C++ compiler in C++
You can implement a PatchCollection::iterator and have PatchCollection provide a begin and end function. This would be a good solution because it also makes your collection reusable to STL.
Or you can simply have PatchCollection implement begin(), end(), and getNextItem() function, but this adds more coupling to the class, which should be decoupled into an iterator.
Or even simply, provide a function in PatchCollection :
template<typename Func_1>
void onEachItem(const Func_1 func){
for each item i, in this set
call func( i );
}
Happy new year AD! For the first time, I went to see the "ball drop" in New York Times Square. It was harsh 7 hour stand but it was definitely worth it!
Each point on the circumference is defined by ( cos(x) , sin(x) ) 0<= x <= 2*pi
All other circle are a variation of that. Since your circle is of radius r, every point on the circumference of you circle can be represented by the above equation with just a minor variation
Sorry for being unclear. WinRar [possibly] uses different compression method than 7zip. They each have different compression ratio. If you want to see which one is better for what input, then try them both and pick the one with the smaller output size. Think of them( WinRar & 7zip) as being two products for the same thing.
What are you talking about? What country do you live? I thought diploma still matters today?
If you have good networks and are a good programmer, then you not necessarily need a degree. All you need is one job then from there its all about experience( mostly anyways ). That CS degree helps you get that first job. However, with proper connection and good skills, you all you need is that initial interview( no degree required) and your golden, assuming you can nail it.
The role of structures has largely been superseded by classes, which have the same basic purpose but have additional features for supporting object-oriented programming (e.g., inheritance).
Sigh. That is incorrect. Classes and structs are no different in C++ except for the fact that by default, structs uses 'public' and classes uses 'private' as an access specifier.
Nowadays, you don't really need the heavy mathematics as someone probably already wrote a library for that. Its more about problem solving and logic skills
Different compression methods