Freaky_Chris 299 Master Poster

I undestand that there are exceptions to the rule. But it's not always the correct case to do either.

I think it comes down to a few things, firstly whether or not you are expecting a higher volume of passes, or fails. You would assume in his case it is normally going to be valid input, so this is an argument for try/catch.

But also the OPs original question does infact state any non numeric characters, which suggests that there will be no input such as (-|.) e.g. characters associated with negative values & floating point numbers.

Also, suggesting the comparison of a large number doesn't really play ball here. Integer.toString() is going to be limited by the value of Integer.MAX_VALUE so if you only wish to allow numbers upto that size then it will only have 10 digits to check (at max). On the flip side, if he is wishing to allow numbers to be greater than this, then there could well be meritt to manually checking. But this does depend on how the data is intended to be used, as Long, or BigDecimal may be a better approach.

But I understand that perhaps I am a little over the top inregards to things like this due to the fact I am used to developing on restrained equipment, where by avoid exception is seriously important, and I comply with the fact that an exception is only used in an exceptional case because of this.

Chris

Freaky_Chris 299 Master Poster

Hi Fruit Punch,

Welcome to DaniWeb :).

Without any of your code as a starting point it is very difficult for us to give you a direct answer, but we prefer to give you the information you need to get your results anyway!

@cool_zephyr's approach will work, however it is slow (due to exceptions) and considered bad practise.

If you are having issues with working out how to display an error message, try looking at JOptionPane, if you still have difficult understanding how to use it post an example of your code and we can explain what you're doing wrong.

  1. If your issue is you are unsure how to check if the field is empty. Then consider the following code snippet.

    jTextField.getText().isEmpty()

  2. For determining if it is a number you could use functions such as Character.isDigit() to determine if the string contains all digits. Not this will only work for positive integers, you will need to be a little bit more complex if you want to account for negative values and floating point numbers.

Another option would be to consider regex, but it all really depends on your needs.

Chris

Freaky_Chris 299 Master Poster

The very point at which I made in my post was in fact not made in your post when I replied.

Freaky_Chris 299 Master Poster

AKill, avoid editing your post after someone else has posted to make there post seem pointless. After all, your post was rather different until I had posted mine.


Regards.
Chris.

Freaky_Chris 299 Master Poster

Forum glitched :/

Freaky_Chris 299 Master Poster

In reply to your question bangor boy,

public void showFeelings(int howManyGoals)
{        
    switch (howManyGoals) 
    {
        case 0: case 1: case 2: System.out.println("Oh dear, not very good"); break;
        case 3: case 4: case 5: System.out.println("Ive seen donkeys shoot better"); break;

            //and so on
     }
}

Also why is your name Bangor boy, are you at Bangor, Wales or perhaps Bangors, Ireland?

Chris

Freaky_Chris 299 Master Poster

Do you understand how to work with file streams? Do you understand how to implement a pow method? Either your own or the existing one?

Freaky_Chris 299 Master Poster

Lucy,

What Adak is suggesting is that rather than us telling you the bet way to do things you should research the algorithm, see what searches are a possibility then decide whether you want to be CPU intensive or stack hungry.

You make some descisions about it, try and write up a program, or even write the program with multiple search algorithms and then runs some tests against them to see which out perform others.

As Adak said, we won't do the work for you, but we are more than welcome to help you with problems. But at the moment, you don't have a problem.

Regards,
Chris

Freaky_Chris 299 Master Poster

No, if its type BO then it will be BO.m, if its type DO (derived object) then it would be DO.m But when a destructer is called, it would execute D constructor first (i beleive this is the order) then B destructor.

The M method in the derived class masks the M method in the super class, so calling the M method on the derived class will always execute the M method in the derived class, but never the M method in the super class

Chris

Freaky_Chris 299 Master Poster

Your welcome

Freaky_Chris 299 Master Poster

Pass the count array to your function, then increment its values and print out after the whole file has been read.

void countLetters(string str, int* count);

...

int totals[N] = {0};
    while (getline(file, str) != NULL) {
        countLetters(str, totals);
    }
Freaky_Chris 299 Master Poster

Your Welcome

Freaky_Chris 299 Master Poster

@tintin,

Recommending the use of a recursive solution is rather an obscure method of helping someone out. Since everyone knows that a recursive function isn't exactly the most efficient solution by any means, although in normally provides a neater looking solution that is easier to code. 99 times out of 100 they turn out to be resource hungry machines.

Chris

Ancient Dragon commented: Yup +27
Freaky_Chris 299 Master Poster

as long as arraysieze contains a value when you try to allocate memory for your array yes. Here is an exmaple,

#include <iostream>

class myLameArray {
    private:
        int *x;
        int sizee;

    public:
        ~myLameArray(){
            delete[] x;
        }

        void setUpArray(int size){
            x = new int[size];
            sizee = size;
        }

        void initArray(){
            for(int i = 0; i < sizee; i++){
                x[i] = i;
            }
        }

        void printArray(){
            for(int i = 0; i < sizee; i++){
                std::cout << x[i];
            }
        }
};
#include "myLameArray.cpp"

using namespace std;

int main(void){
    myLameArray* l = new myLameArray();
    l->setUpArray(10);
    l->initArray();
    l->printArray();

    delete l;

    return 0;
}

Chris

Freaky_Chris 299 Master Poster

don't use eof() use file.is_good();

Also, the reason you are getting random numbers is because you don't initialise your array.

int count[N];

becomes

int count[N] = {0};

The reason it prints after everyline is because you call your function for each line, and it is your function that prints


Chris

Freaky_Chris 299 Master Poster

You can define a class wide variable within your class.

class myClass {
     private:
          myStruct mS*;

}

Which will allow you to access mS in both functions, so you could allocate the memory to it in one function. Use it in a second function and then deallocate it in another function, such as the destructor

Chris

Freaky_Chris 299 Master Poster
output+= String.format("%1$10d%2$10.0f%3$10d%4$10.0f\n", i, QQ, d, inventory);
alisneaky commented: Love your work.i figured it out by studying what you gave me..thanx heaps +0
Freaky_Chris 299 Master Poster
JFileChooser jfc = new JFileChooser();
jfc.setDialogTitle("My Title");

Chris

Freaky_Chris 299 Master Poster

alisn you should start up your own thread rather than reviving old threads.

System.out.printf("%1$10d%2$11.2f%3$10d%4$11.2f\n", i, QQ, d, inventory);

Chris

Freaky_Chris 299 Master Poster

I dislike vsc++ but there we go. I just compiled it on MinGW with no problems what so ever, i was presented with a list of the address that your data was stored at.

if you want the data to be printed you will need to use **it not just *it.

Chris

Freaky_Chris 299 Master Poster

Have a read of the fisher-yates shuffle or perhaps the durstenfeld algorithm for shuffling.

Chris

Freaky_Chris 299 Master Poster

Luke you are assuming the use of VC++, it might be unmanaged C++ he is using.

Rather than passing what type of connection you wish to check, you should be passing a pointer to a data structure to hold the different connections that are avaliable to you.

So you should be passing a LPDWORD* to grab the data. Then check the content of the returned data structure.


Chris

Freaky_Chris 299 Master Poster

Singh,

Please do not hijack other peoples threads. I suggest you read the forum rules as you have just broken most of them.

You're first post was a very bad one. I suggest you read and try again in a more suitable way.

Regards,
Chris

Freaky_Chris 299 Master Poster

What is your problem?

Freaky_Chris 299 Master Poster

do not use eof();

Do this instead.

while(getline (openFile,line) != NULL);
{
	cout<<line<<endl;
}

Chris

Freaky_Chris 299 Master Poster

@CppBuilder

I'd recommend getting an upto date compiler. You might find that they work properly then ;)

Freaky_Chris 299 Master Poster

Look at method signatures.

Freaky_Chris 299 Master Poster
([a-zA-Z\. ]+,)|([a-zA-Z\. ]+<[a-zA-Z\., ]+(<[a-zA-Z\.,< ]+>)*>+[ ]*,)

Does that help?

Chris

Freaky_Chris 299 Master Poster

Please don't drag up 2 year old threads. And it should be noted that in standard C++ no there is not a way.

Chris

Freaky_Chris 299 Master Poster

please use [code=c] [/code] tags to post code, also please come to us with a specific problem, rather than asking us to program you homework

Freaky_Chris 299 Master Poster

Compare your code with that of ancient dragon, and study them hard, you will soon see what he is doing differently to you. Until you have had a good hard look and have some sensible suggests please stop posting loads of code that means nothing.


Regards,
Chris

Freaky_Chris 299 Master Poster

I already gave you a solution in a C++ thread. Why do you keep cross-posting?

Freaky_Chris 299 Master Poster

Using the stdlib.h header in conjunction with the time.h header you can generate pseudo-random numbers which will allow you to select a random fortune cookie.

#include <stdlib.h>
#include <time.h>

int main(void){
     srand( time(NULL) ); // seed the random generator, with current time, making it a different seed when run each time

     int myRandomValue = rand() % n; // returns a random number inclusive of the range 0..(n-1)
     
     return 0;
}

Since we are in the C++ forum lol, mistake by me. Make it ctime header and cstdlib :)

Chris

Freaky_Chris 299 Master Poster

try using isCharacter(), .charAt() and .length

Chris

Freaky_Chris 299 Master Poster

This is a sample code snippet of a quicksort that uses templating and function pointers to allow the user to sort an array of anything from numbers to strings to structures.

The idea is, that the coder writes a small function thats return type is bool, It should return true if the first parameter is "less than" the second, or if you which to sort it in descending order then "greater than" the second parameter.

Below is an example of the quicksort being used on an array of ints, strings & a structure.

Hope this is helpful to people and provides a small insight into templating and function pointers with callback procedures.

(Note: perhaps not the best code ever, but nice)

Freaky_Chris 299 Master Poster

This snippet can be used to convert from bases between 2 & 16 to base between 2 & 16.

This is an extension on converting decimal to any base snippet found here: http://www.daniweb.com/code/snippet1067.html

(By no means is this the best method of doing this, but provides rather a nice way)

Freaky_Chris 299 Master Poster

int main() is not a choice, it's standard! Don't make people start ranting. Also iostream.h shouldn't be used either, there are a whole host of reasons....and Borland is out dated!

Also you really do need to free the memory! If you don't do it then people using the snippet wont unless they know exactly what is going on.

Freaky_Chris 299 Master Poster

The following code snippet can be used to convert a decimal integer into any base from 2-16. This is a simple piece of code and I hope t proves useful to people.

I see many people posting Decimal to Hex. or Decimal to binary, non any better than the next. I'm not saying this is the best method, but I think it's small size, clarity, and flexibility (not restricted to converting to one base) makes it a nice snippet.

Freaky_Chris 299 Master Poster

I think you should look at all of your brackets, most of your classes are contained within the PreviousButton class or whatever it is called, so get counting :)

Chris

Freaky_Chris 299 Master Poster

This is solved, I just found the IE only auto stub -_-

Thanks anyways.

Regards,
Chris

Freaky_Chris 299 Master Poster

Ok So I'm a newbie to HTML & CSS anyway I decided to play around with a dreamweave default page and now I'd adding in a menu section on the left hand side. And I'm getting blnk unwanted space inside the dive before my list item and I cannot work it out for the life of me. Thats in IE 8 btw,

any help would be great thanks,
Chris

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css"> 
<!-- 
body  {
	font: 100% Verdana, Arial, Helvetica, sans-serif;
	margin: 0;
	text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
	color: #000000;
	background-color: #FFC848;
	padding-top: 20px;
	padding-right: 10%;
	padding-bottom: 20px;
	padding-left: 10%;
	display: block;
}
.twoColLiqLtHdr #container {
	width: 900px;  /* this will create a container 80% of the browser width */
	background: #FFFFFF; /* the auto margins (in conjunction with a width) center the page */
	border: 1px solid #000000;
	text-align: left; /* this overrides the text-align: center on the body element. */
	top: 20px;
	padding: 10px;
	margin-top: 0;
	margin-right: auto;
	margin-bottom: 0;
	margin-left: auto;
} 
.twoColLiqLtHdr #header {
	background-color: #FF2424;
	margin-bottom: 20px;
	padding-top: 0;
	padding-right: 10px;
	padding-bottom: 0;
	padding-left: 10px;
} 
.twoColLiqLtHdr #header h1 {
	margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an …
Freaky_Chris 299 Master Poster

Firstly, don't use sysrtem. use the function given to you by AncientDragon.

Secondly for an example, read the page it has a link to one.
Thirdly, that page tells you what parameters are needed, what they could be and what they do. Also it tells you what headers you need etc.

Please read information when someone points you to it, they don't do it for fun. They do it to try and help.

Chris

Freaky_Chris 299 Master Poster

The size of arrays are resolved at compile time, when qs_pair is 10, thus when you enter more than 10 you will get overflow errors.

You should be using dynamic allocation when dealing with creating an array of size N where N is specified by user input.

int *example = new int[N];
...
delete [] example;

Chris

Freaky_Chris 299 Master Poster

You cannot asign an unknown value to the size of an array at compile time. You need to use dynamic memory.

double *P = new double[N];
...
delete [] P;

For the second bit, you cannot do a mathematical equation on the left hand side of an assignment operator. It must be a variable etc.

Chris

Freaky_Chris 299 Master Poster

Perhaps his real question is how can he compute the value of that series to a given figure amount using C++?

Freaky_Chris 299 Master Poster

Don't bother using text tags for yout text, thats not what its for. it stands for Latex, a Mathematical Notation Syntax.

Secondly, we don't know what your program is supposed to do and what it is or is not doing, so we can't help you.


Chris

Freaky_Chris 299 Master Poster

Unmanaged Win32 Code, is directly interfacing with the win32 API. Managed Win32 is using the MFC. Which is what MVC++ users tend to do. Thus you do not need the catorgarized link that he sent you, but you need the MFC, since this will probably easier for you. The MFC (Microsoft Fundamental Class) is a wrapper for the Win32 API making it easier and faster (in some cases) to write GUI Interfaces,
http://msdn.microsoft.com/en-us/library/d06h2x6e.aspx
http://www.functionx.com/vcnet/index.htm

They should get you started.

Chris

Freaky_Chris 299 Master Poster

use a string comparison function rather than a pointer to the first letter in the string. Use strcmp().

Chris

Freaky_Chris 299 Master Poster

Please note, we will not provide code solutions for you, you will need to do some work yourself and show evidence of the fact you have done so.

It's really not to hard, if you know some basic file handling techniques you can do it no problem.
It can get a bit more advanced but to start with it's simple enough, and I'm sure if you do some research; it would be even easier.

Chris

Freaky_Chris 299 Master Poster

First of all, i'm going to assume that you are using Visual C++, since after all thats the link you posted. Please make it clear if you are using Manged or Unmanged Win32 for your application, even better make it clear what operating system you are using too. Since linux will be different to windows. However it is obvious that you are indeed on a Windows OS of some kind.

Originally I was going to post a link to Unmanged Win32 because I thought that was what you were on about, then I checked your link and Noticed I was wrong.

But i'm still left confused since the link you posted does demonstrate this and the main page has a whole host of examples http://www.functionx.com/vcnet/index.htm

Chris