mrnutty 761 Senior Poster

if A goes out of scope does this mean the pointer B is a bad pointer meaning it does not point to anywhere?

Yes, A goes out of scope and its destructor is called. You should really
have B in the same scope as A. That means B shouldn't be global.

If so, does this mean I still need to have somewhere in my program an instance of class derived?

care to elaborate?

mrnutty 761 Senior Poster

-listening to music...
-going out...drinking and meeting ppl.
-gym...eating healthy...boxing.
-Thinking bout AI...if I had all the time in the world i'd do this...after my love of history...
-Testing render engines...(don't know why i like this)
-Flash and actionscript 3.0.

I hope you don't take offense to this, but I hate history. I find it
boring and useless for me, at least. I am surprised that a CSE-er finds history intriguing, unless its the history related to CSE-ish things.

mrnutty 761 Senior Poster

Whenever you have a "big" assignment like that, its really good to break it down. Here is the first thing your should do :
<quote> Create an inheritance hierarchy containing base class Account and derived classes SavingsAccount and CheckingAccount that inherit from class Account</quote?

Draw this out on paper. Let a box with a name represent a class.

So a class Account is a abstract base class. Then After you created that,
(don't worry about the method function) then create a Checking and savings account, that inherits from the abstract class, Account.

After you got this done, post, it and we will take it step by step.

mrnutty 761 Senior Poster

Go out with friends. Go to a dinner and movies with friends or go girl hunting, ahem. Then come back home to your families, and have a birthday
cake celebration. Happy late, b-day. May the light be with you.

mrnutty 761 Senior Poster

Fix to :

if(winner == 0)

Also make use of functions.

mrnutty 761 Senior Poster

change :

int mod(int &num, int &num2)

to

int mod(int num, int num2)

So it works with the copy of num1 and num2 and not it indirectly.

mrnutty 761 Senior Poster

Here are other Buzzwords I met today
1. Difference between Template class and template functions. Me I don't see except one is class and other is function

But a template class can have default arguments for a template
parameter.

2. How to best use try, throw and catch

Depends, if you even need it.

BTW, I found the book I'm reading the Author used void main :)

What book ?

mrnutty 761 Senior Poster

1. What is your favorite IDE

Microsoft visual studio. just tried eclipse, and its not bad either.
Both debugger are nice.

2. What is your favorite GUI library

OpenGL, the only one I use.

3. What is library that you often use?

STL's.

mrnutty 761 Senior Poster

Thanks!

I've got #include <string> and thought that "xyz" would be interpretted as a string versus the single quotation marks ' ' which indicate its a const char* :-S ?

Nope, then it would be ambiguous.

mrnutty 761 Senior Poster

>>output("1", "k"); // ?

should be a string :

output(string("1"), string("k")); // ?

Whats happening is that "1" and "k" is being interpreted as a const char*

mrnutty 761 Senior Poster

whats the problem?

mrnutty 761 Senior Poster
cout<<"*"<<endl;
cout<<"   *"<<endl;
cout<<"    *"<<endl;
cout<<"  *"<<endl;
cout<<"*"<<endl;
mrnutty 761 Senior Poster

haha. cool. same here, I'm trying to make a snake game too. i cant get the snake to move without me having to press the buttons again and again. getch, switch, scanf and everything waits for the user to press a key... so, how do we make a snake game?

You don't. You let the pro handle it, ahem, ahem.

mrnutty 761 Senior Poster

>>I keep receiving the same output for each record when I run it on the test data. I've tried numerous things...any suggestions?

Yes, learn how to use the debugger! You can't just dump "huge" code on us and expect us to fix it for you. If you "step-by" your code, you will find your problem fast. It will help you in the long run if you know how
to use a debugger.

mrnutty 761 Senior Poster

Appreciate your assistance! I also need to incorporate at least one function call within my code and that has me completely lost....Any help?

You already did, the displayTitle(); is a function call.

You also might want to make a function that returns the average, given an array and its size.

mrnutty 761 Senior Poster

I guess, if no one starts a special thread by this weekend , then I will just
post a start-up question. The question might be like project euler, where
there is a brute force way, and there is a optimal way. For now, I have to study for my finals.

mrnutty 761 Senior Poster

Well it will ask you questions of what you have covered.

Salem commented: Aparently, this wasn't obvious to the OP - it does not bode well for the exams... ;) +17
mrnutty 761 Senior Poster

What is enemies?

mrnutty 761 Senior Poster

Is there a particular problem? For you operator >, you can just do :
return !(a < b );

mrnutty 761 Senior Poster

But if you print it out with a huge dpi (dots per inch) then it is a perfect circle. This is because the ink is 3d.

No false, no matter how precise you get, its never a perfect circle.

mrnutty 761 Senior Poster
#include <iostream>
using namespace std ;

void displayTitle ()
{
     cout << "Active Duty Navy personnel Program" << endl ;
}

int main ()
{

    displayTitle () ;
    
    int Age[50] ;    // age of personnel
    int I ;          // number of ages entered
    int sum ;        // sum of ages
    float Average ;  // average of ages entered
    sum = 0 ;
    Average = 0 ;
    for (I = 0 ; I < 50 ; I++)
    {
       cout << "Enter current age of AD Navy Personnel" << ( I + 1 ) << endl ;
       cin >> Age[I] ;
        
       if ( Age[I] >=18 ){
          sum = sum + Age[I] ;
       }
       else {
             I = I - 1 ; // the same element the Age array will be read 
        }
    Average = sum/50 ;
    for ( I = 0 ; I < 50 ; I ++ )
   {
        cout << "Age of Personnel" << ( I + 1 ) << "is : " 
        << Age[I] << endl ;
       }
       cout << "The current average age of AD Navy Personnel is : " 
        << Average << endl ;
           
    cin.get () ;
    return 0 ;
}
mrnutty 761 Senior Poster

If you believe Paint or any other circle drawing program isn't accurate then let me demonstrate in a 3d model using 3d blender. I have drawn a perfect circle using 12 cyphers and if you connect them it will make your circle. However, in real life they are bunched together like in the MS Paint model. This is because each atom is so tiny that each atom does not have enough sides to form the perfect circle. Basically in the 3d model because there are 32 sides for the cylinder that means it can attach on whatever angle. However if they can only attach on the sides or direct diagonal that is where the MS Paint model is by far more accurate. This is really going into atomic physics now. You will find that atoms cannot attach on any angle that we can write down (example 98.35869049696 degrees). However they can attach on a certain number of degrees. It is due to this limitation that pi will never be true. Why? Take a look at my diagram, all the circles are at different angles to each other. what if you had 4,000,000,000,000,000,000 points in that circle. In reality that is only a few cm's. Then you would have to have some atoms beside each other and above each other to be able to make the perfect circle. And remember that atoms need to all be attached. That forces another limitation. If they need to all be attached and they have …

jonsca commented: Yes +0
mrnutty 761 Senior Poster

Your highest function should return an INT, and that int should be
the index of the highest element in that array. Change that first.

Next, your highest function is almost correct, except that your max should be the index to the highest value, and your if statement should check every element against the array content of the max value.
So it should be something like this :
//returns the index to the highest element in arr

int highest(student arr[], int cnt, int i)
{
	int max = 0;
 
	for (int j=0;j<cnt;j++){
		if (arr[j].gr[i] > arr[max].gr[i])
			max = j;
             }

	return max;
}
mrnutty 761 Senior Poster

Virtual functions and polymorphism are closely related.

A virtual function means that a some class with a virtual function will be derived from, and that virtual function will be overridden by the derived class.

To declare a virtual function the syntax is :

class VirtualBase{
public :
virtual void draw(){ cout << "drawing in virtualBase\n"; }
};

Notice that the virtual function is inside of a class, thats because it only makes sense for it to be in a class.

Take a look at this example :

class Based{
public : 
virtual void speak(){ cout <<"based\n"; }
};
class Derived : public Based{
public:
void speak(){ cout<<"derived\n" }
};

Notice that Dervied inherits from the Based class, and overrides the speak function. Now here is where the polymorphism comes in. When you have objects from base or derived, a base class object pointer can
point to either the derived class or the base class, and when you call the function speak with the base class pointer, the compiler will call
the speak function of either the base class or the derived class, depending on which it points to. Take a look :

#include <iostream>

using namespace std;

class BaseClass{
public:
	virtual void speak(){
		cout<<"Base Class says : Rough...Rough\n";
	}
};

class DerivedClass : public BaseClass{
public:
	void speak(){
		cout<<"Derived Class says : Meow...Meow\n";
	}
};

//Remember that a BaseClass pointer object can point to 
//a BaseClass object, or a DerivedClass object.
//and …
Clinton Portis commented: droppin' some mad knowlege on a complex topic +5
mrnutty 761 Senior Poster

This function is a total mess :

void NumberStorage::generate(int n)
{
	srand(unsigned(time(0)));
	n = 0;
	int* ArrayOne = NULL;
 
	ArrayOne = new int[n];
 
	for(int i = 0; i < n; i++){
		ArrayOne[i] = rand() % 100;
	delete[] ArrayOne;
}

Think about what you are doing.

mrnutty 761 Senior Poster

C++ is like a girl, make one mistake and it will kill you.

Debugging C++ code is like trying to figure out a girl, its almost impossible.

mrnutty 761 Senior Poster

I also have a theory and am still working on a formula to prove that pi is not infinite in length. If pi were infinite in length then the circle would have have an infinite circumference. And using MS Paint I have found that pi is not always 3.1415. It can vary depending on the size of the circle. For example, a circle about 6 atoms in diameter will produce pi of 3 instead of 3.1415... This can be proven with 2d cg models so try to draw a perfect circle in MS Paint. Then count how many dots in the circumference and divide it by the number of dots in the diameter and you will rarely get pi to more than 1 digit for a small circle.

Sorry man, but this I find stupid. First This statement is wrong :
<quote> If pi were infinite in length then the circle would have have an infinite circumference.</EOQ>

Just because the sequence is infinite length does not mean that
its value is infinity, and therefore the circumference of the circle is
not infinite.

And you can't use any software to draw a circle and prove that pi
is not 3.14159... because the circles are actually pixels, which are
rectangles. What you are trying to disprove is math. And if anything in this world,
I know that math is purely deductive.

mrnutty 761 Senior Poster

<quote>So basically I want to be able to stick a few zeros in front of the smaller binary numbers.

Check the length, while(binary.length mode eight != 0 ) addToFront('0');

mrnutty 761 Senior Poster

Test all cases if you can. If not then test the extrema. Then test randomly.
More test the better.

mrnutty 761 Senior Poster

Then you know almost everything you need to know. All you need to know is how to link them. And the way to link them would be using a linked list.
Have you learned about them ?

mrnutty 761 Senior Poster

How can find the repitition of a number from a given array with
less time complexity(<N)?

You need to check through every element in the array to ensure that there is no repetition right ? So if the array was of size n, then to ensure that there is no repetition inside the array, you need to check every element, namely n elements.

mrnutty 761 Senior Poster

can't you just use a function :

int generateGameID(){
  static int i = 0;
   ++i;
   return i;
}

And use that inside you game :

do{
    int currId = generateGameID();
    while(gameIsNotOver){
       runGame(currId) 
     }
}while( someCondition );

Or did I misread your post?

mrnutty 761 Senior Poster

So do you know how to create a regular 1d array of size n, dynamically?

mrnutty 761 Senior Poster

if your variable is in a class then you should have your class constructor and deconstructor for initializing the variable and deinitiliazing the variable

no such thing as deconstructor and deinitiailazing, in fact that's not even a word. I assume you mean destructor.

mrnutty 761 Senior Poster

How about using strings to represents float, char, double, int, and so on.

string Types[4] = { "124","1.234","aString","c" };

Then you can convert it accordingly with sstream.

mrnutty 761 Senior Poster

Nice your sudoku is really cool :). Good Job!

No its not cool, its kewl.

mrnutty 761 Senior Poster
//items are equal 
		else if(list1=list2)

or

// is items equal ?
	else if(list1== list2)
mrnutty 761 Senior Poster

That usually means that your variable contains junk and you haven't
initialized it to anything. I am guessing its a double variable somewhere in
your program.

9.222255e+061

Approximately it also means -9.2 * 10^61

mrnutty 761 Senior Poster

To use timer, you need to use the clock function. Maybe this example will help you :

#include <iostream>
#include <ctime> //for clock()

using namespace std;

bool myPrint()
{
	static int cnt = 10;
	cout << cnt << "!\n";
	cnt--;

	if(cnt <= 0)
		return false; //stop at 0

	return true;
}
int main()
{	
	//convert our starting time to seconds
	unsigned int clk_strt = clock()/CLOCKS_PER_SEC; 
 
	unsigned int UPDATE_TIME = 1; //update every 1 seconds

	while(true)
	{		
		unsigned int clk_end = clock()/CLOCKS_PER_SEC;
		//if the difference in the time we started
		//and the current time is greater than our 
		//UPDATE_TIME, which is 1 second then ...
		if(clk_end - clk_strt >= UPDATE_TIME)
		{
			//reset time
			clk_strt = clk_end;
			//count down
			if( myPrint()== false){
				cout<<"!!!BOOM!!!\n";
				break;			
			}
		}		
	}


	
	return 0;

}
mrnutty 761 Senior Poster

There must be something else thats wrong with your code then. Want to post it?

mrnutty 761 Senior Poster
const int REPEAT_CODE = 666;
int userInput = 666; //could be any value for now

do{
runGame();
getInput();
}while(REPEAT_CODE == userInput);
mrnutty 761 Senior Poster

i m overwhlmed now so i cant focus

Thats ok. All you needed to do was a minor change :

int highestScore(PlayerData [], int size , string& playerName)
{
   //set the highest Point to the first player's score
 
   int highest = data[0].Points;
 
   //steps through the array looking for highest
   for (int i =0; i<Num_Player; i++) 
   {
      if (data[i].Points>highest) 
      {
         //save this value
         highest= data[i].Points;
         //save this player number and Name
         playerName=data[i].Name;
 
       }   
 
   }
//return the value
return highest;
 
}

and the call should look like this :

string highestPlayerName = "";

//Display Highest Score of the Player and the number or name of the player
 double highest = highestScore(game, Num_Player, highestPlayerName);  //highestPlayer is by ref
 
  cout<<"Highest Score:"<<highest;
 
  cout<<"(Player"<<highestPlayerName<<"\n";
mrnutty 761 Senior Poster

These variable are used for numbers :

int word, a, perfume;

What you need to use is something that can handle words, like std::string;

string word, a, perfume;

Also I notice that "a" variable, is the correct word that you are trying to compare in this statement :

if (word == a)

That means that you should initialize "a" variable to something like so:

string a = "room"; //correct answer
string word, perfume;

Also it would be better if your variable name is not "a". Give it something more meaningful like correctAnswer;

Here is a complete program , which is the same as yours but with my suggestion incorporated.

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

int main()
{
	string userInput;
	string correctAnswer = "room";

	
	cout<<"Singing bee game.\nGuess the missing word for phrase."<<endl;
	cout<<"Are you ready?\nset\nStart!"<<endl;

	cout<<"it's four am and i'm waking up to your _______"<<endl;
	cout<<"what is the missing word to complete the phrase?"<<endl;
	cin>> userInput;


	if(userInput == correctAnswer)
	{
		cout<<"Correct answer!\nYou can now proceed to the next song."<<endl;
	}
	else //incorrect answer
	{
		cout<<"Wrong answer!/nSorry, try again next time :P"<<endl;
	}

	return 0;

}

Also I am not sure if its supposed to be case insensitive or not, but it is in the above program.

mrnutty 761 Senior Poster

First your temp variable is not initialized but you use it.

Second check this and see if it help, look particularly at the logic inside the loop.


Third you have the x declared before the for loop and inside it. So that
might be your problem.

Doing this works so far :

bool add (int a[], int b[], int sum[])
{

    int x = 0, temp = 0;
    for(x = MAX_DIGITS-1; x>=0; x--)  // first index of array is 0 in C/C++
    {
     
        sum[x]=a[x]+b[x];  

        if(temp==1)
         sum[x]=sum[x]+1;
        
        
        if(sum[x]>=10)
        {
            temp=1;
            sum[x]=sum[x]-10;
        }

        else 
        {
            temp=0;
        }
            
    }

    if(( x<0 )&&(temp==1)) // = is assignment == is comparison
        return false;
    else
        return true;

}
mrnutty 761 Senior Poster

Do you really this that this code :

if (data[i].Points>highest) 
      {
         //save this value
         highest= data[i].Points;
         //save this player number and Name
         highest=data[i].Name;
 
       }

Does what you think it does, assuming your think the way you comment?

The variable highest is a int variable, but, data.Name is a char array.
Can you assign a int variable a char array?

What made you think that you can " //save this player number and Name" ?

What you wan't to do is this :

int highestScore(PlayerData [], int size , char * PlayerName){

//inside your for loop assign PlayerName to the highest scored points.

//the return highestScore, and PlayerName also contains the player with the highest score.
}
mrnutty 761 Senior Poster

>>it cracks the string h3ar7 in 16 seconds on my computer.

Thats pretty slow. There is no reason to use recursion here.

mrnutty 761 Senior Poster

Wow over 500 lines for a determinant. Maybe you should be a teacher?

Seriously, I wouldn't want use that function to calculate the determinate, becuase I would have to do this : compute(matrixVar,var1,var2,matrixVar,a,b,c,d,e,f,g ..........);
Do you think that pleasent?

As for your question, try print out the result at certain steps and see what you get?

mrnutty 761 Senior Poster

I thought you knew what you were doing until I seen this :

if (data[i].Points>highest) 
      {
         //save this value
         highest= data[i].Points;
         //save this player number and Name
         highest=data[i].Name;
 
       }

What are you trying to achieve here? Explain, so I can see what you
are thinking.

mrnutty 761 Senior Poster

This part :

for(int index = 0; index < dim; index++){
		aux = matrix[i][index];
		matrix[i][index] = matrix[j][index];
		matrix[j][index] = aux;
		}

What do you think its doing? Were you trying to swap ?

mrnutty 761 Senior Poster

I like the idea of building recognition software or a flash-based movie... or even programming a game. This might be simple for some, but not so for others. We are not all going to be at the same level and so I suggest that there be problems for three different levels: easy, medium, hard, and those who are very skilled might take on extremely complex problems offered by some of the senior members.

Sounds good. I am not a senior, nor a junior, just a freshman, so
I am relying on someone else for now.;)