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      
    //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

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

  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;

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.

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;

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;

  return isFull;
  • 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

Your asking for private code. I told you what I was doing.

Welp for one calm that attitude down. Second good luck with your problem then.

Rather than trying to explain, I'll link you to a article that talks about namespace. In general for simple question you should try to be more independent. Take care.

Somthing like this perhaps

template<typename FirstContainer, typename SecondContainer, typename BinaryOp>
void iterateTwoContainer(const FirstContainer& firstList,
                         const SecondContainer& secondList,
                         const BinaryOp op2){
 for(int i = 0; i < firstList.size(); ++i){
   for(int j = 0; j < secondList.size(); ++j){

void handleItemAndToys(const Item1& item, const Toy& toy){/*...*/}
void handleItemAndApples(const Item2& item,const Apple& apple){ /*...*/}
int main(){

myk45 commented: thanks! +5

You probably wany New(Shoe,num);

leaf = leaf->left; //move leaf 1 time to right

That comment conflicts with that is written.

leaf->key_value = temp->key_value; //assigning temp's key to leaf

That's not really needed since leaf is going to be deleted right.

Also I'm not sure why you are treating left-child different than right child when deleting using that algorithm. All you are doing is swapping a leaf node with the node to be deleted and deleting the stale leaf node. I don't see how this algorithm has any relation to a leaf having two children as your function deleteWithTwoChild suggests. Just being nitpicky there. If this is fro homework, then you probably want to follow the proper guidlines.

Anyways, can you print out the tree after each deletion? Also what happens if father is null? Have sanity check to see if father or temp is null. If possible post full code in pastebin.com because, the problem might be elsewhere. Can you post your deleteWithNoChild function? And also the destructor for this class.

deepecstasy commented: Comment is correct, yes leaf->key_value modification doesn't make a difference but I just wrote it to be clear, & I have pasted required functions, +0

I know the question was who, but lets cover more ground my casting it to what. What makes me happy are the things I love to do and enjoy. Some of which are

  • Spending time with family
  • Spending time with my brother, more specifically
  • Playing basketball
  • Programming
  • Making people smile
  • Helping people to make their day better
  • Simply appreciating life, and so much more

Yes in C++ you can return a pointer by reference, doing so will allow you to change the pointing address of the pointer and have it affect out of scope. For example

void reallocateRef(Node*& node, int newValue){
    node = new Node(newValue);
void reallocateNoRef(Node* node, int newValue){
    node = new Node(newValue);
Node * n1 = new Node(-1);
Node * n2 = new Node(1);
reallocateRef(n1, 0); //   n1.value = 0 instead of -1
reallocateNoRef(n2,0); // n2.value is still 1 instead of 0

As for what it is good for, it depends on context, somtimes it plays a good role for helper function and other times you just might need it. Usually you just pass pointer by value, but if you need to change what it is pointing to then it is necessary to pass by reference. There could be similar reasoning for returning by value versus ref for pointers.

Initialize you letter grades.

 char A('A'), B('B'), C('C'), D('D'), E('E'), F('F');

Taking a quick look,

" index=sub.find_first_not_of("aeuio");
    cout << "first consonant:"<< sub[index]<<endl;

what happens when that find_first_not_of fails?

How about adding some graphical feature to show the statistics on the number of successes the job finding site has acomplished?

Go for sfml, but there might be more documentation on sdl. Check out gamedev, they are generally good with helping with graphics. Or you can post here and we'll help as well. Just get some simple screen gonig on sfml then move on further from there.

You listed the answer, 1 = 5 therefore 5 = 1.

Sometimes simplicity is overlooked.

First you want to look at batch programming, at least I think that's a good starting point to showoff to your friends. Second, grow some balls. Who cares what they think? Why do you need to impress them. They are not programmers and probably never will be. They do not have any knowledge in our field. They just go by whatever is shown in the movies. Third, get a internship, get a job, contribute to open source, create an open source project, make your own programming projects. Do stuff that you can put on your resume. That's how you will impress recruiters.

Another option is to make a File struct.

struct FileInfo{
    std::string name;
    //possibly other things
    explicit FileInfo(const std::string& name = ""): name(name){}

class Lexical{
     ReturnType read(const std::string& sentence);
     ReturnType read(const FileInfo& fileInfo);

but I suggest to go the istream route as suggested in previous post.

And I have partly to thank you guys. I joined DW a while back only occasionly used it. Then stoped. Then started using it more and more. Over the years it has been great. Everything has been great. Everyone has been great. I wish it was possible that we could all go out and have a drink or something. I feel like I owe you guys one. Anyways, I don't want to get too mushy gushy. You guys have been a good part of my life. I remember constantly logging on here to either ask questions or answer them. While I was obsessed with programming for a few years a while back, you guys gave me the resource and fire to fuel that obsesison. Now it has died down a bit. You guys might not know it but you guys helped me through life a lot. From programming to relationship issues to religion. Extra thanks to imthewee, man you are one awsome person. I don't really know the point of this article, but I just want to show my appreciation to you guys. Man I'm such a bitch lol. Time flies by so quick. Hope everyone has been well up to this point. I like the new DW look although some new features annoy me. Take care ladies/gents.

yours truly,


You're looking for conversion operator. Something like

class Point{
    int x,y;
    operatir POINT()const{
       return POINT(x,y);
triumphost commented: Perfect! I never ever saw that before. Thank you. +5

I think the syntax is

int rowSize = 5;
int colSize = 5;
float **matrix = new float*[rowSize];
for(int i = 0; i < rowSize; ++i){
  matrix[i] = new float[colSize];

//do stuff with matrix[i][j]

for(int i = 0; i < rowSize; ++i){
   delete [] matrix[i];
delete [] matrix;

Of course you can avoid all of this by using std::vector.

  int rowSize = 5;
  int colSize = 5;
  std::vector< std::vector<float> > matrix( rowSize, std::vector<float>(colSize) );

  //use matrix[i][j]

  //no need to worry about deleting matrix

"First part is simple, my name is mike. The second part is an enigma for you guys. 2000 taken to the power 17 is about the total mass of the observable universe measured in grams. No, actually 2000 bitshifted 17 times writes FA00000 in hex which is cool. I'm kidding, seriously, 2000 and 17 is the longitude and lattitude of this private island that I own. Muhuahaha, you'll never figure out what it means!

Also python (the animal) is spelled pyton in Finnish.
Yeah, when a finnish colleague of mine proposed to use "pyton" for a project we had, said in the finnish pronounciation, it took me a while to realize he was talking about Python. Minä rakastan Suomi, mutta se on mahdotonta oppia suomea!"

Hmmm, hurricane michael ? Occured in the year 2000 on the 17th of october as a tropical storm?

mike_2000_17 commented: That's an awesome coincidence! +0

I haven't worked with mandelbrot set but try using this :
//zn is your last complex number used and n is the iteration count
flota smoothcolor = n + 1 - Math.log(Math.log(zn.abs()))/Math.log(2)
Color col = Color.HSBtoRGB(0.95f + 10 * smoothcolor ,0.6f,1.0f);

[B]M- happens to be a unknown function of N[/B]

That means, M = f(N), and you can't assume anything about f(N), so the runtime would be O(N * f(N)).
That could be linear, polynomial, quadratice, factorial, or whatever; all depending on f(N)

grh1107 commented: thanks! very helpful +1

[CODE]INPUT-BUFFER: 973 456.2 77F NEWLINE 973 456.2 77F

1) cin>> m; //m = 973
INPUT-BUFFER: 456.2 77F NEWLINE 973 456.2 77F

2) cin.clear (); //clears the state bits
INPUT-BUFFER: 456.2 77F NEWLINE 973 456.2 77F

3) cin.ignore (200, '\n'); //ignores 200 characters or until a new line is reached
INPUT-BUFFER: 973 456.2 77F

4) cin>> letter>> n>> n; //letter = '9' , n = 73 then n = 456

INPUT-BUFFER: [ is in a failed state I think not sure, sets the state bits ]

5) cout<< letter<< m<< n<< endl; //pass out 9973456[/CODE]

Pass them by reference. Its better than polluting globals.

Also for B), O(n+m) \in O(n) so you can just say O(n)