Duki 552 Nearly a Posting Virtuoso

Perhaps something like,

Int32 myInt = 0;
if ( System::Text::RegularExpressions::Regex::IsMatch(myTextBox->Text, 
	"^[-0-9]*.[.0-9].[0-9]*$") )
{	
	myInt = System::Convert::ToInt32 ( myTextBox->Text );				
}
else
{
	MessageBox::Show("Not a number");
}

This is an excerpt from another message board on the same topic.

Duki 552 Nearly a Posting Virtuoso

>It is due you are trying to access a value pointed by pointer outside the scope.

So... did you bother testing your code before posting it? Sure it prints now - but perhaps pointing member variables to the same memory location throughout the entire program isn't the best idea (i.e., char n[21]).


@o/p - With the suggestions from the previous post, you should see how adding a few more variables to your program should fix things up. However, keep in mind that changing the values of your main() variables (assuming you'll be doing char arrays) will in fact change the value of your members.

E.g.,

//pseudo
char temp[10];

cout <<"\n Enter the first name of 1st employee:: ";
e1.setName(gets(n));			
cout <<"\n Enter the last name of 1st employee:: ";
e1.setLastName(gets(n));

Sample Input:
Billy
Bob

The above code will indeed change your employee's last name to Bob, but will also change your first name to Bob.


edit> I have to agree with tkud. Much cleaner than trying to use char[]

Duki 552 Nearly a Posting Virtuoso

For the record, I do actually look at your posts. I've actually been to your site quite a few times also. I would have loved to have a professor in college who was able to teach on the same level as you or AD.

Duki 552 Nearly a Posting Virtuoso

Wait.. what? Do you want it to be cleaned up? Or are you trying to demonstrate how it's not cleaned up? I'm confused.

Duki 552 Nearly a Posting Virtuoso

Please don't shout - it hurts our ears. :(

Duki 552 Nearly a Posting Virtuoso

When I see a thread in C++, and the last poster is "Ancient Dragon" or "Narue", I just don't bother even opening the thread. It would be like Han Solo explaining The Force to someone who just got off the phone with Yoda... amirite?

Duki 552 Nearly a Posting Virtuoso

I'm amazed how often users wind up here, when undoubtedly searching Google for their question. Don't get me wrong, I (like most of us here) enjoy giving advice for free, and enjoy receiving it equally as much. But there's a point when you have to realize, reading for yourself is often quicker than the lazy way out. That's my rant for the day.

Duki 552 Nearly a Posting Virtuoso

Instead of doing a switch() on id, how about doing a switch on the menu choice? Then, it would be very simple to create a few functions that take the id as a parameter to do what you want.

e.g.,

//pseudo
switch(menu_choice)
{
case 1:
	CheckBalance(id);
	break;
case 2:
	Withdraw(id);
	break;
case 3:
	Deposit(id);
	break;
case 4:
	break;
}

This way, you're not "setting" anything (i.e., "//Set the account to the selected account values."). You can just pass an ID to your functions, which will then determine what action to take on which account. Unless I'm misunderstanding what you're trying to do?

>As another tip - try to keep your main() relatively small. I would suggest creating a couple of functions to InitializeAccounts() & ExecuteCommand(choice), or something similar. This makes accessing your data a little different, but it's worth the extra work.

Duki 552 Nearly a Posting Virtuoso

>>Don't use System("pause"), instead as LordNemrod suggested use cin.get().

Yes, never use System("pause").

Duki 552 Nearly a Posting Virtuoso

Can someone explain why this:

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">
<TableRow
    android:id="@+id/upcoming1"
    android:clickable="true">  <<<<
        <TextView
            android:text="-------"
            android:gravity="left"
            android:padding="3dip" />

Doesn't allow me to click the row?


edit> Maybe the more important question. How can I fetch it using onClick or something similar?
e.g.,

TableRow tr = (TableRow) findViewById(R.id.upcoming1);

Is this close to what needs to be done?

Duki 552 Nearly a Posting Virtuoso

Good to hear - don't forget to mark your post as solved in case others may need to reference it.

[and for self esteem reasons]

Duki 552 Nearly a Posting Virtuoso

You're referring to this part of my code, right

cout << "How many stars: " << flush ;

for (int i = 0 ; i < ... ; i++)    //For every column...
{
	cin >> temp;
	for (int j = ... ; j >= ... ; j--)   //...we need to adjust the rows...
		stars[j][i] = ' ';   //...removing '*' where necessary.
}

Here you need to index very carefully. I've given you the last part of the for() loop you're asking about - it should be j-- (that's not a blank). j--, as compared to j++, does exactly the opposite. Instead of incrementing it decrements. So think of it as, you're starting at MAX_ROWS (whatever you want that to be) and you're removing stars all the way down to your Temp variable (the value the user inputs for that column). Does that help?

Duki 552 Nearly a Posting Virtuoso

I see where that could be confusing now. In general, I tend to associate height with columns and length with rows. :)

Duki 552 Nearly a Posting Virtuoso

>>you need to adjust your prompt to fit the requirements of the assignment.

Pay attention to his suggestion here. The user needs to know what they're inputting. Try changing your prompt to something more like,

Give me a number (0-25):

To get even a little fancier here, you could do something like,

int main ()
{

	int num; // input
	string ary[26] = {“Zero”,"One", "Two", … , "Twenty-Five"};

	bool invalid_input = true;
	while(invalid_input)
	{
		cout << "Give me a number: " << flush ;
		cin >> num;

		if (num>=0&&num<=25)
		{
			for (int i = 0 ; i <= num ; i++)
				cout << i << "\t - \t" << ary[i] << endl ;

			invalid_input = false;
		}
		else
		{
			cout<<"Invalid!"<<endl;
			 invalid_input = true;
		}
	} 

	return 0;
}

This way you could loop until you get a valid input.

Duki 552 Nearly a Posting Virtuoso

His original post explains what he wants, quite understandably.

>>You people are over-analyzing this. All he needs to do is use IOMANIP. He should use a for loop to print however many asterisks are specified to a line, aligned to the right after he sets a width for each row. Then he should fill in the blank spaces with a " " character.

Wrong. You're thinking he needs rows, not columns. (again, the original post is very handy when answering questions).

What you're explaining would produce

Enter the numbers: 1 2 3 4 3 7

      *
     **
    ***
   ****
    ***
*******

When in fact, he needs it to display

*
     *
     *
   * *
  ****
 *****
******

>>
only problem is i need an UNLIMINTED ammount of rows to be specified, and after a user inputs a 0, it will print out.

Use a vector instead of an array.

Duki 552 Nearly a Posting Virtuoso

My code works just fine if you can fill in the 5 blanks I left you.

Duki 552 Nearly a Posting Virtuoso

My post overlaps somewhat with fbody, but should help answer your remaining questions.

edit> noticed a typo in my first post - modified part about the for() loop slightly.

Duki 552 Nearly a Posting Virtuoso

edit> sorry for double post fbody :P

----> string ary[26] = {"Zero","One", "Two", "Three", ... , "Twenty-Five"}
You can do that also, it doesn't matter.

It's doing this,

//pseudo
ary[25]  .....  this equates to 

ary[0]
ary[1]
ary[2]
.
.
.
ary[23]
ary[24]

//THEN - compiler does this

ary[0] = "whatever is first"
ary[1] = "whatever is next"
.
.
.

//So - you could actually do this

ary[25] = {"Ten", "Eleven", "Seven", "Horse", "Chair", ...}

//and be completely legal as far as the compiler is concerned.

cout << "Give me a number: " << flush ;
For lack of a detailed description, flush as opposed to endl just sets the cursor at the end of your line to make input cleaner. So instead of,

Please enter your name:
Bobby Joe

You can have something like,

Please enter your name: Bobby Joe

-----> for (num=0,ary=0;num<=25,ary<=26;num++,ary++)
Not at all, sorry. Here's a hint - you only use one statement in each blank. So take out everything and re-look at my for() loop. Remember, if you start at 0 and your array is only 25 items large, your indexing doesn't go all the way to 25, right? So even in the case of trying to access ary[25], it would blow up.

Your for loop should look like this

for (int i = 0 ; i < ... ; i++)

Question: ary[26]?
Sorry, wrong again here. You want to …

Duki 552 Nearly a Posting Virtuoso

>>"N_showdata.N_enterData();" which says "error C2660: 'NomineeData::N_enterData' : function does not take 0 arguments"

It means exactly what it says.

Duki 552 Nearly a Posting Virtuoso

I practically gave you the answer to this problem already (without the use of pointers and dynamic memory). Does your assignment require that you use pointers?

Duki 552 Nearly a Posting Virtuoso

Personally, here's what I would do.

Imagine drawing the stars logically:

[ ][ ][ ][*][ ][ ][ ]
[ ][ ][*][*][*][ ][ ]
[ ][*][*][*][*][*][ ]

[*][*][*][*][*][*][*]

We need to figure out how to input these accordingly though. For me, it makes more sense to initialize our array with all *'s to start with. This just makes our loops easier to create (you'll see later):

int temp;
const int COL = 6;   //These consts could be done away with
const int ROW = 4;   //if you're using a vector
	
int ROW_INDEX = ROW - 1;  //We use this to keep track of which row we're on in the loop

char stars[ROW][COL] ;

//Code excluded - this initialization is easy enough to figure out.

[*][*][*][*][*][*][*]

[*][*][*][*][*][*][*]

[*][*][*][*][*][*][*]

[*][*][*][*][*][*][*]

Now that we have our array initialized, it's time to get a value and then adjust our first column accordingly:

cout << "How many stars: " << flush ;

for (int i = 0 ; i < ... ; i++)    //For every column...
{
	cin >> temp;
	for (int j = ... ; j >= ... ; j--)   //...we need to adjust the rows...
		stars[j][i] = ' ';   //...removing '*' where necessary.
}

I've left blanks for you to fill in.

So, now that we have this awesome-sauce picture stored in our array, we need to figure out how to output it. Easy enough - Just remember the picture is inverted from what we've logically stored.

for …
iamthwee commented: Nice +13
Nick Evan commented: Nice post +15
Duki 552 Nearly a Posting Virtuoso

>Also Duki, I think you switched from Nodes to Toms on accident. And arrays initializer lists use curly braces, not parentheses.

Sure did - thanks.

Duki 552 Nearly a Posting Virtuoso

My source is compiling his code for myself and getting errors on that line in Visual Studio 2010...

error C2440: '=' : cannot convert from 'main::baseClass *' to main::derivedClass *'

Keep in mind that I'm referring to o/p code - not the casting you mention.

Duki 552 Nearly a Posting Virtuoso

Happy to help.

Duki 552 Nearly a Posting Virtuoso

Ok, so:

#1 - What you're experiencing is due to something called early (static) binding. At run time, your compiled code has no clue about basePtr pointing to derivedObject. This is one reason you use virtual functions. If you noticed, your last function call did actually call the derived function ("virtual, derived" was output). This demonstrates the differences between early and late binding.

#2 - Same answer as before. The only reason you're calling yVirt() is because it is in fact a virtual function. Virtual functions are not bound at compile time, but instead are bound during run time. This way, your program can decide during run time which function needs to be called based on which object is calling the function.

#3 - Technically possible, but you'll get a load of exceptions. Newer compilers probably won't even compile that.

A very good resource that should help you better understand these topics.

Duki 552 Nearly a Posting Virtuoso

Look here.

Duki 552 Nearly a Posting Virtuoso

Something like this should get you started... just a hint.

int matrix[6][6];
int cols[6], rows[6];

cols[0] = rows[0] = matrix[0][0] = 0;	//Corner of Matrix

....

//Populate multiplication table
for (int i = 1; i <= 5; i++)
{
	matrix[0][i] = cols[i];
	matrix[i][0] = rows[i];

	for (int j = 1; j <= 5; j++)
	{
		matrix[i][j] = rows[j] * cols[i];
	}
}

I'll go ahead and give you this part too.

//Output the table
for (int i = 0 ; i <= 5 ; i++)
{
	for (int j = 0 ; j <= 5 ; j++)
		cout << matrix[i][j] << "\t";

	cout << endl ;
}
Duki 552 Nearly a Posting Virtuoso

Unless 6.0 is required, go here and select Visual C++. That is the newest version of Visual Studio.

Duki 552 Nearly a Posting Virtuoso

Hey Tom, you can do this two ways. The easiest way would be to use a vector instead of an array:

vector<Node> Tom(5, Tom(width));  //5 Tom objects calling Tom(width)

The other way, if you want to (a) specify the parameters for each object or (b) continue using arrays:

Node Tom[5] = ( Tom(1), Tom(2), Tom(3), Tom(4), Tom(5) );

Hope this helps

Duki 552 Nearly a Posting Virtuoso

Post your code.

Duki 552 Nearly a Posting Virtuoso

Your question doesn't make any sense! How are the values in the matrix generated? What are you trying to do?

Duki 552 Nearly a Posting Virtuoso

Touche'

Duki 552 Nearly a Posting Virtuoso

I agree with embooglement. You functions should rarely (if ever) be that large. The general rule I go by is, if it takes more than a sentence or two to describe the function, it's too long and should be broken up. This also plays along with OOD in that, you want your code to be extensible and reusable. Creating many smaller functions rather than a few large functions increases the probability that you'll be able to use those functions later for something else.

Example: Instead of writing one large function to measure the square footage of a particular building, going through and adding the square feet of every room in the building for a given number of rooms - You could instead write a function to determine the square footage based on the result of a separate function used to calculate a room. This way your BuildingSquareFeet() function has just been transformed from a function for a specific building to a function that can be used on any building.

Duki 552 Nearly a Posting Virtuoso

You haven't corrected it. Take another look at firstPerson's post.

You can implement your function just like you did the other three.

bool checkGuess(int ans, int guess)
{
	if ( ans != guess )
		return false;
	else
		return true;
}
Duki 552 Nearly a Posting Virtuoso
Duki 552 Nearly a Posting Virtuoso

I would also suggest sticking with arrays for now, especially since you have a set index. Something like this might get you going:

int num = 0;
string ary[25] = {"One", "Two", "Three", ... , "Twenty-Five"};

cout << "Give me a number:  " << flush ;
cin >> num;

for (int i = 0 ; ... ; ...)
    cout << num << " - " << ary[...] << endl ;

I've left blanks for you to fill in.

Fbody commented: I like the blanks... +2
Duki 552 Nearly a Posting Virtuoso

So the only thing you want is the last line of the file I assume... since your while() loop will not break until reaching the end of your file.

Duki 552 Nearly a Posting Virtuoso

Thank you.

Duki 552 Nearly a Posting Virtuoso

If that's all you need, then you could probably just use a tmp variable and a static count variable. If you just want the lowest number of guess for every round (i.e., if the fewest guesses it took for any given 10 rounds was 4 guesses, you want to output that) then just pass in a tmp variable, compare it to lowest_count, if lower, replace.

Duki 552 Nearly a Posting Virtuoso

>If they want me to take a course, which will cover a bunch of stuff I already know, then that's what I'll do.
Just don't let them make you pay for it. They're the ones who want you to take a course, despite hiring you for your programming prowess. If it's important enough to stuff you in a class now rather than learn on the job or on your own, they can foot the bill.

Agreed.

Duki 552 Nearly a Posting Virtuoso

Using the ++ operator on a pointer is different from a traditional variable. *ptr++ will increment the memory space which ptr is pointing to based on the variable type.

For example, if you have

int *ptr;

and suppose it's pointing at memory location 1000. We know that an integer is 4 bytes, right? So if we do

*ptr++;

our pointer will now be pointing to location 1004.

As for which occurs first, I'm pretty sure that since the ++ operator is on the right of the statement, it occurs first, then assignment. If it were the other way around (e.g., ++*ptr) you would first assign the values and the increment. Someone should probably check my answer on this part though...

Duki 552 Nearly a Posting Virtuoso

@embooglement: Unless the o/p has an application that requires this type of encapsulation or abstraction - in which case, simply calling from main() won't work.

@o/p: I wouldn't avoid this type of design for the sake of preserving your stack, assuming it's because you're trying to maintain OOD. You'll see as you begin in a real-work environment, this is extremely common with larger applications. I work with software that sometimes has nested well over 10 functions before returning up the stack. If it helps you maintain a good design, and it's not a ridiculous number of function calls, don't worry about it.

Another point worth noting is the number of allowed function calls depends on the function and it's variables. Larger functions with large numbers of variables will decrease your stack much quicker than a simple 4-5 line method.

Duki 552 Nearly a Posting Virtuoso

Did half a programming class just register to post in this thread?

Duki 552 Nearly a Posting Virtuoso

Another thought is to use a static 2d array. e.g., [generated_num][count]

Duki 552 Nearly a Posting Virtuoso

You could save the values to a file each time. Then use a function to read those values, and determine the Count you want to display.

Duki 552 Nearly a Posting Virtuoso

Can you post some code...

Duki 552 Nearly a Posting Virtuoso

For Windows I prefer Visual Studio. I also am a huge fan of Qt, but if you're writing only for Windows platforms, Visual Studio's native support of .NET is invaluable.

Duki 552 Nearly a Posting Virtuoso

Hey Arthas - have you tried logging on to the Boost IRC channel? They have quite a few people who are always logged on. That's where I found most of my help.

Duki 552 Nearly a Posting Virtuoso

Just use a break and loop like Fbody suggested.

e.g.,

int answer = 1;
while (answer >= 1 && <= 4)
{
	switch (answer)
	{
		case 1:
		{
			cout << "what do you want to do?\n";
			cin << answer;
			break;
		}
		case 2:
		{
			//do stuff
			
			cout << "what do you want to do now?\n";
			cin << answer;
			break;
		}
		case 3:
		{
			//do stuff
			
			cout << "what do you want to do now?\n";
			cin << answer;
			break;
		}
		case 4:
		{
			//do stuff
			
			cout << "what do you want to do now?\n";
			cin << answer;
			break;
		}
	}
}
Duki 552 Nearly a Posting Virtuoso

Have a look here.