mrnutty 761 Senior Poster

@ddanbe, Awe man idk I havent tried to soldier them yet, just recently got an audrino board, hopefully it goes smooth. Which type of LEDs do you have? There are these awesome RGB ones but theyre so expensive

mrnutty 761 Senior Poster

@ddanbe: Haha I was going to guess for xmas. Nice sounds pretty cool, definitely more rewarding to build your own haha. I recently started a LED project as well, trying to make one of those led cubes. They look so cool.

mrnutty 761 Senior Poster

@imthewee: Haha I'm doing good, the app is my side project. At my job I'm doing pretty important stuff, can't really talk about right now. As for my side-project, I'll have a prototype of the app soon, its web based. Tested it on iphone/android and desktop and looks good so far. I'll definitely let you guys know when alpha is ready so you guys can check it out and maybe test it.

How's firstPerson doing? You seem to have settled into your new job... Do you have a linky to your app or is it a non disclosure company thing?

mrnutty 761 Senior Poster

C++ doesn't have an interface to allow you to create any GUI code, but you can use external libraries to draw the GUI stuff and control it with C++.

For example here is a gui application in C++ using the QT library:

#include <qapplication.h>
#include <qpushbutton.h>


int main( int argc, char **argv )
{
    QApplication a( argc, argv ); //create a window object

    //create a button object with the text 'hello world'        
    QPushButton hello( "Hello world!", 0 ); 
    //set the size of the button
    hello.resize( 100, 30 );
    //add it to the window
    a.setMainWidget( &hello );
    //enable our button to be shown, by default it is hidden      
    hello.show();
    //show our whole window
    return a.exec();
}

There are many tutorials out there for this, I just stole the above from here: http://web.njit.edu/all_topics/Prog_Lang_Docs/html/qt/tutorial1-01.html ,

But judging from your post, I do not suspect that you have grasped most of the concepts in C++, so I would suggest to start doing more projects and not worry about gui stuff until you have a solid grasp of C++. How much of its concepts do you know, for example arrays/if-else/classes/structs/templates?

Ancient Dragon commented: good advice +14
mrnutty 761 Senior Poster

@ddanbe: Building from scratch? Are you planning on making anything with those LEDs?

mrnutty 761 Senior Poster

I use that mapeditor, but usually export it to json. Actually exporting it to json is what you need. It has a "data" attribute which is an array of numbers like you have above, and each number represents a tile.

mrnutty 761 Senior Poster

@iamthewee, whats your fav movie? any suggestion?

mrnutty 761 Senior Poster

We all go through them, some worse than other, the key is to realize that you are in one and then try to get away from it by doing various positive fun things. But depression isn't all bad, its actually healthy in small dosage according to me lol.

Grimjack- dont let you depression get you down i just dealt with my depression about two months ago.

mrnutty 761 Senior Poster

No way hot glass workbench, thats pretty cool. Do you have some pictures of what youve made so far or what you plan to make. What are you doing in Montana?

mrnutty 761 Senior Poster

Me? Oh nothing much, just bored at work. Working on a new web-app project on my free time. Planned to be in the appstore. Going to hit #1, just watch. How about you?

mrnutty 761 Senior Poster

I'm using Phaser engine for a 2d web platformer game, its not too bad, give it a shot

mrnutty 761 Senior Poster

Can you just use notepad search/replace to format the csv file? or is this just for practice

mrnutty 761 Senior Poster

Else statement is connected to the if statement. Once the if statement is executed, else statement is not executed even if the while statement inside the if returns false or true or never returns.

mrnutty 761 Senior Poster

Try this cout << " just inserted new element. " << (ret.second==true) << endl; or better yet just cout << " just inserted new element. " << ret.second << endl;

mrnutty 761 Senior Poster

Usually you overload the operator[] for constant-ness. Are those operators defined in some class?

Consider these statement

T* a = getA();    
const T*b = getB();

if(a[0] == 1) doA();
if(b[0] == 1) doB();

Without the const T& operator[](int)const version, the b[0] == 1 would not compile because b is declared as a constant, therefore could only call member functions that are constant.

mrnutty 761 Senior Poster

Royal blue, bought my first car last summer. 2007 tiburon GT. Sexy little self. Got it for a bargin too. 21K miles for 8G.

mrnutty 761 Senior Poster

Interesting history post. Thanks for the information. Off topic kinda but I wish more people would just stop what they are doing for 5 minutes and just observe. Observe the society, observe the body languages, observe the human interaction, observe nature and its wonderful mathmatical creation, observe people and their talents,and just appreciate life and its wonderful glory. Its beautiful.

mrnutty 761 Senior Poster

Be nice. So you want to alternate rotation. In that case you need a little bit more logic like so:

if( isSpaceKeyPressed()){
  int currentRotation = line.getRotation();
  if(currentRotation == 90){ //is horizontal( flat line )
    line.setRotation(0); //make it straight line
  }else{
    line.setRotation(90); //make it flat line
  }
}
mrnutty 761 Senior Poster

Maybe this startup hint would help you

#include <iostream>
using namespace std;

void getMonthsData(int data[], const int SIZE){
  //print message
  //for i = 0 to size 
    //ask for data[i]

}
void getYearData(int data[], const int SIZE){
 //print message
 //for i = 0 to size
   //ask for data[i]
}

void getAverate(int data[],const int size){
 //your get_average logic here
}

int main(){
 int data[12] = {0}; //zero initialize everything
 int MAX_SIZE = 12;

 int choice = -1;
 cin >> choice; //get user input

 switch(choice){
  case 1: MAX_SIZE = 12; getMonthsData(choice,MAX_SIZE); break;
  case 2: MAX_SIZE = 10; getYearData(choice,MAX_SIZE); break;
 }
 cout << "Average= " << getAverage(choice,MAX_SIZE) << endl;
 return 0;
}
mrnutty 761 Senior Poster

Member functions are not the same as regular functions. There is a little more work, here is an example:

class SampleClass
{
public:
    int plusfunc (int a, int b);
};

int SampleClass :: plusfunc (int a, int b)
{
    return a + b;
}

typedef int (SampleClass::*functor3) (int a, int b);

int main(){
 SampleClass sc;
 functor3 f[1] = {&SampleClass::plusfunc};
//note you need an object to call the function that f points to
 cout << (sc.*f[0])(1,1) << endl;
 return 0;
}

http://codepad.org/w6WexeJy

mrnutty 761 Senior Poster

@nullptr, nvmd didn't realize the 'last' word in 'lastLargestIndex'

mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

No need for copies or iterating over multiple condition. There can be perfect forwarding,references or pointers, if needed. And you can combine multiple functors into one if you only want to run through the list once. I just think this would be the better option of the two and a lot less code

mrnutty 761 Senior Poster

If you are going to go the iterator route, then you might as well make it stl compatiable and inherit from `std::iterator'.

Another option is to simply have a filter function like so:

template<typename Container, typename FilterCondition>
std::vector<typename Container::value_type> filter(const Container& cont, const FilterCondition& cond){
 std::vector<typename Container::value_type> filteredList;
 for(int i = 0; i < cont.size(); ++i){
    if(cond( cont[i] )) filteredList.push_back( cont[i] );
 }
 return filteredList;
}

bool isDead(const Actor& actor){ return actor.isDead(); }
bool isChildActor(const Actor& actor){ return actor.age() < 18;}
bool isGirlActor(const Actor& actor){ return actor.type == Actor::GIRL_ACTOR: }
int main(){
  ActorList actors = getActors();
  ActorList childActors = filter( actors , isChildActor );
  ActorList childActorWhoAreGirls = filter( childActors, isGirlActor );
  //..and so on

Warning, syntax is probably wrong somewhere, but the general advice should help.

mrnutty 761 Senior Poster

Is this operation being performed on Actors only? Do you have a list of Actors available to apply the filtering?

mrnutty 761 Senior Poster

Your code seems fine, it might be how you setup the environment. How'd you set up your environment? I haven't used netbeans in years. But typically in any ide, there is an option to create a C++ project. Did you try to run a simple hello-world program and see if that works:

#include <iostream>
using namespace std;
int main(){
  cout << "TEST" << endl;
  return 0;
}
mrnutty 761 Senior Poster

Is that function a virtual function, can you change its sigs? Why not return a std::pair<bool,Handle> ?

mrnutty 761 Senior Poster
bool operator==(const Birthday &x, const Birthday &y) 
{
  if ((x->getMonth() == y->getMonth()) && (x->getDay() == y->getDay()))//i am getting errors here
    return true;
  else
    return false;
}

Bad syntax above, try this:

bool operator==(const Birthday &x, const Birthday &y) {
  return (x.getMonth() == y.getMonth()) && (x.getDay() == y.getDay());    
}
mrnutty 761 Senior Poster

ok cool, don't forget to delete what you new-ed. What is your question?

mrnutty 761 Senior Poster

Awesome, thanks dani

mrnutty 761 Senior Poster

I hope you know that std::string has a find method in which you can use to find another string. So for your Contains function, you can simply so something like so:

bool contains(const std::string& target, const std::string& src, bool ignoreCasing = false){
   const std::string& adjustedSrc = ignoreCasing ? toLower( src ) : src;
   const std::string& adjustedTarget = ignoreCasing ? toLower( target ): target;
   return adjustedSrc.find( adjustedTarget ) != std::string::npos;
}

The toLower is a function you would have to create that lowers the whole string. Other than that suggestion, your code is fairly complicated, and I'm not sure why it needs to be that way.

mrnutty 761 Senior Poster

In C++ 1/2 = 0 because of inteeger division. Thus you want something like so:

float divide(float x, float y){ return x/y;}
int main(){
 float x = 0, y = 1;
 cin >> x >> y;
 cout << divide(x,y) << endl;
}
mrnutty 761 Senior Poster

Omg nitpickers haha. Sorry should have been more precice.

  • For all positive number v,w,x,y,z
  • 1/a is not an integer division
mrnutty 761 Senior Poster

You want to get the input and set the member variables:

#include<iostream>
#include<string>
using namespace std;

class student
{
public:
       void input();
       float GPA() const;
       void Display() const;

private:
       string name;
       int id;
       int grade1;
       int grade2;
       int grade3;
};

int main()
{ 
       student kyle(name, id, grade1,grade2,grade3);
       kyle.Display();
       return 0;
}

void student::input()
{
       cout<<"enter student id number"<<endl;
       cin>>id;
       cout<<"enter student name"<<endl;
       cin>>name;
       cout<<"enter three grades"<<endl;
       cin>>grade1;
       cin>>grade2;
       cin>>grade3;
}

float student:: GPA() const
{ 
  return (grade1 + grade2 + grade3) / 3;
}

void student:: Display() const
{
       cout<<" Student Gradepoint average is: "<< GPA() <<endl;
}

Note the syntax changes and the function prototype change.

mrnutty 761 Senior Poster

Gravatar is getting really popular, may sites like stackoverflow or github have incorporated the avatars. It would be nice to have a consistent avatar throughout all forums and sites.

mrnutty 761 Senior Poster
I know we haven't been doing much of these C++ Community problems so I though I'd write one up to get it started once again.

Problem Statement: For some integer v,w,x,y,z find all solution to the following equation

   1   1   1   1   1
   - + - + - + - + - = 1
   v   w   x   y   z

For example one solution is v = w = x = y = z = 5, find the rest. If there are none the prove it with your code or some algebra. Happy coding fellas.

mrnutty 761 Senior Poster
if(Clock.GetTime() >= FPS){
            Screen->StartFrame();
            Player.Draw();
            Screen->ShowFrame();
            Clock.Start();
        }

Why do you do Clock.start() here again? A better way to handle it is like so:

if(Clock.GetTime() >= FPS){
    Clock::TimeDiff diffTime = Clock.GetTime() - FPS;
    updatePhysics(diffTime);
    updateEntities(diffTime);
}

Check out a full tutoial here

mrnutty 761 Senior Poster

Hmm...seems like its a little more complicated than it needs to be. Some of your algorithms can be simplified using the algorithms in the string library, for example:

 std::string GetExtension(const std::string& filename){
    _validate(); //your exception validation
    auto endExtensionPosition = filename.find_last_of('.');
    auto endPathSeperatorPosition = filename.find_last_of("/\\");
    if(endPathSeperatorPosition > endExtensionPosition || endExtensionPosition != std::string::npos) return "";
    else return filename.substr(endExtensionPosition);

 }

Thats a rough idea not sure if that works in one shot though. Also since most of these functions are static, it would make more sense to put it under namespace instead of class, just to follow the idiom.

Another thing is that this can easily be extended to be handled in non-win32 environment just by changing the reservedChars, pathSeperator and so on. Anyways, nice job!

mrnutty 761 Senior Poster

while (v[i] < 2147483648 && v[i] > -2147483647)

I have no words...except this sentence.

mrnutty 761 Senior Poster

There are so so many tutorials online about this. I'm not sure what you are confused by. As a quick glimpse, consider the following code:

//base class
struct Base{
   int x; 
   virtual ~Base(){};
};
//inherit properties and method from Base class
struct Derived: Base{
   int y;
};

After the derived class inherits from the base class you can access things in base class from derived class. For example,

Derived object;
object.y = 0;
object.x = 0; //this is the base class variable but the base class is part of derived class

That's very brief tutorial, you should really invest in a book or use online and do some research. Hope that helps.

mrnutty 761 Senior Poster

If you don't know the size of the parameter 'a' in your example, then it is not possible to correctly write the needed logic with the given information. Sure we can assume things such as the char array is null terminated which is a natural assumtion in this case, but its still an assumption.

mrnutty 761 Senior Poster

Seems like you need to first understand how to convert binary to decimal before actually programming it. Take for example the binary number 1010 which is 10 in decimal. How can we get to it mathmatically? Pretty easy actually, what you can do is sum up pow(2,nextOnePosition). For example,

1010 in base10 = pow(2,3) + pow(2,1) = 10
^^^^
3210 = position of each bit

Where did I get those numbers for pow function? The 2 is from it being base 2. The 3 is because there is a 1 in the 3rd bit. Similarly, for pow(2,1), the 2 is there because of base 2, and the 1 is there because there is a 1 in bit position 1. In general the base2 to base10 conversion is as follows:

Given a binary number, let b_i be the bit at ith position, where i = 0 is the right most bit and let 'n' be the length of the binary number. The formula to convert base2 to base10 is:

SUM(b_i)  = b_i * pow(2,i) 
i = 0 to n

Note, if b_i is 0 then b_i * pow(2,i) result in 0, thus being ineffective. But if b_i = 1 then we add pow(2,i). 

I would finish this up with the code but I'll let you work on that since you asked not to write the code. Also as a tip, use std::string if possible instead of char[8]. They work pretty much same char raw char arrays, but …

mrnutty 761 Senior Poster

I think you want something like so:

#include <iostream>
#include <fstream>
int main(){
  using namespace std;

  ofstream fileOutput("data.dat",ios::app); //open for appending
  cout << "What is your favorite number: "; //print to standard output the question
  int favNum; //create variable to store number
  cin >> favNum; //read response from user from standard input
  fileOutput << favNum; //save number into the file 
  return 0;
}

Notice I use the correct header as well the correct main function(i.e int main not void main)

mrnutty 761 Senior Poster

Check it out. For some numbers like 101,reverse(110) returns 11. So your reverse function isn't completely correct.

mrnutty 761 Senior Poster

Try cout << timeFunction( standardDeviation<delctype(v)>, v);

Why don't you make your timeFunction a template parameter as well?

mrnutty 761 Senior Poster

It should be something like so, in psuedo code:

bool isFull(board){
  bool isFull = true;
  for i = 0 to board.length   # 0 <= i <= 8
    if board[i] != 'x' && board[i] != 'o'
       isFull = false;
       break;

  return isFull;
}
mrnutty 761 Senior Poster

Few reasons why I prefer google than others

- It is popular, usually crowd knows best in the realm of technology
- It is fast
- It returns better search results than other few search engines that I've tried
- And is continually building
mrnutty 761 Senior Poster
  • Check if the board is full, meaning that all cells are occupied and not empty
  • Then make sure there aren't any winning patterns for 'x' -- use your checkAll('x')
  • Then make sure there aren't any winning patterns for 'o' -- use your checkAll('o')
  • If all the above passed then it is a tie
mrnutty 761 Senior Poster

Welp the thing is, I am on my vacation, which is soon to be over in 2 days. I just haven't had a interesting project I wanted to work on. I usually work with C++ and web stuff. So I tried learning about networking, which was cool, got some chat app running. Learned something new. Idk, maybe I need to think of something creative to work on. I think my problem is that if I believe I can do that project then I don't have any motivation to work on it or start it, because it seems trivial. I think my problem is that I need to sort out my other issues i have in my life. Maybe my concentration has been thrown off because of my other life issues.

mrnutty 761 Senior Poster

What's up ladies and gents. I've been lacking motivation to program lately. I've been doing a little programming here and there, but I work so I mostly program for my job. However, whenever I have free time, I use to program a lot, but that motivation and has been gone lately. I simply cannot find enough motivation to start some project again. I use to be addicted but now I don't find anything interesting to program. Maybe its a lack of ideas. So I ask how do you guys find motivation to program? Any advice?