jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

you can use a variant of the using statement using std::cout; using std::cin; thereby qualifying those method names only.

I realize that I might have been confusing. If you put using std::cout; once underneath your #include (though it could be anywhere) you're covered for the remainder of the program in being able to use cout without the std::. Do the same for any members of the std:: namespace that you need. The way you did it is totally fine and is in fact preferred by a lot of people, but if you're just starting out it can be painful.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It has a variant Substring(startindex, length) . If you're going to do it based on index of the number alone you could copy it into a new string without the commas.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
newtextbox.Text = oldtextbox.Text.Substring(12);

The 12 accounts for the commas in the string. Substring(12) grabs all characters (including) 12 and beyond.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't use goto. Use a loop instead. This way you can put in an exit option. When getting input like you are use a do/while loop so that you can test for whether you should exit the loop after you've gone through one cycle.

Your function names leave a bit to be desired and the abbreviated names seem to be opposite of what they should be. There's no need to skimp on characters especially for readability. It's the old 6 month rule, could you come back in 6 months and know what exactly they did?
(also why comments are a great idea)

Skip all these sleep calls. By and large the places you have them wouldn't require it anyway. Needing the Windows functions adds a tremendous amount of overhead to your application.

Your functions return an int, but you should actually return the value you got for the conversion to the main program so their return type should be double. When returning to main() use the return (your double variable here); keyword, don't call main again. Skip the "would you like to go back to main" portion of it and just have a return statement (no system("pause") in these functions either).

Your system("pause") in your main program will never see the light of day as you return 0, and you've exited your program. But skip it anyway because (and you had the right idea with the getchar) use cin.get() to have the user press a …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're very welcome, glad to hear it!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Select all the items on your form (or select them in groups if you don't want the same settings for all of them). Go over and click on the properties tab under Solution Explorer (if you can't see it, go to View/Properties Window). Go to the margin setting. Change as you see fit (can change any and all sides)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post a small portion of your code so I can try and run it?

for IComparer you need a class (can be within the same namespace, not sure if that's what should be done with it though):

Say you have a class Person that has a public member variable of type int named year of birth and you wanted to use this as your key.

public class PersonComparer : IComparer<Person>
{  //don't select IComparable which is something a bit different
    //see the article below

    //Now normally with ints, we arrange them from highest to lowest
//but we want our sort by age, so we reverse the usual scheme for 
//returning 1 if the first value is greater than the second one, or if they 
//are equal and -1 if first is less than the second

public int Compare(Person A,Person B)  //must be compare as that's
//what the interface dictates
{
           if(A.Year < B.Year)   
                  return 1;
          
           if(A.Year > B.Year)
                   return -1;
           else
                    return 0;

}
}

Then back in your program where you defined your list:

PersonComparer pc = new PersonComparer(); //for obj1
SortedList<obj 1,obj 2> personlist = new SortedList<obj1,obj2> (pc);

Excellent ref with some more examples:
http://support.microsoft.com/kb/320727

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I can't make the function of type void

If a function has a return value you don't have to cout it.

In your case you can either call it like lonelyday proposed square(side); which essentially ignores the return value completely
or you could say

if(square(side) == 0)
       cout<<"Success!"<<endl;

which implicitly calls the function when it tests the == 0 relationship.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

A few hints:
1.) int square(int side, int i); is a function prototype. It should not be placed in main()
2.) function parameters are used to convey information between different methods. what information is i bringing into the square() method?
3.) grab a pencil and paper and go through your loop step by step for say side = 3, read through the instructions and draw what the program output is. You'll find at least one of your errors quickly.
4.) Where is the zero co ming from on the display? What are some of the options for the return type of a function? Do you need to cout for everything?

tux4life commented: Good hints :) +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try it as template <class E> typename LinkedList<E>::node * LinkedList<E>::getNode(const E &item) since I believe the situation is equivalent (or at least parallel to) this thread.

i'm sorry but i don't understand what you mean by

No, not a problem at all. I just meant that classically people put declarations, defines, etc. in the header file and leave the implementation to a separate .cpp file whereas with templates all of that (declarations, definitions, etc) together has to get lumped in the same .h file with almost all compilers.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are your indicies of a type that have the ability to be directly compared? (like ints or strings)?

If not you must write an IComparer<your_index_object> method and pass it into the constructor of the sorted list.

Here's the MSDN for sorted list.
http://msdn.microsoft.com/en-us/library/system.collections.sortedlist.aspx

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do you have the method definitions in the same header file with the declarations? It kinda runs counter to your experience with headers but for templates it's usually necessary.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

These two might be overkill for what you are seeking (but they are in C#):

http://www.menees.com/index.html

http://www.codeproject.com/KB/recipes/diffengine.aspx

Do a net search on "Diff" which is the utility in *nix to do this kind of thing. I think (it's been eons since I've used it in any form) that it makes a table of all the strings in the file and compares each new entry to those in the table.

You can probably get away with using a list or a dictionary after parsing your text file and just using the Contains() method.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I may be missing something but why do you have (const E &item) _after_ the braces?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

First, make sure the files are in the same namespace. Look at the top few lines of each after the using statements to see. If that's not the problem type out the steps you followed to add the file in.

EDIT: What mahmoud says may be the way to go if they are in the same class. If it's a new class you're starting do the namespace check.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Click back on Tag this thread and you can uncheck the ones you don't want.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I use monoDevelop on a mac book pro

Gotcha. Well I'm using the old fashioned VC# express. Google around and see if there is some setting for wide characters that needs to be set. I would only be guessing.
I would tag your post (see further down on this page) with "mono" or "monoDevelop" as it may attract those in the audience using those systems/tools.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The ch3 is Æ is what printed on my system. I don't think I have any settings on for international characters so I'm not sure why it worked.

In your IDE does '\u00c6' appear brownish with the syntax highlighting?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i meant c++ graphics..

No such thing, at least not in standard C++. What you have is a non-standard library which was created by Borland (and others). If you are still trying to use a ca. 1993 Turbo 3.X technology on a ca. 2006 operating system then you may be out of luck. What Rahul is trying to say is that there are libraries out there that are more current and supported by recent versions of Windows.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i still not clear enough about the use of isPrime=true; at there..

Then move it up to the top as Rahul suggested.
In the original code the variable was initialized as true when it was declared. If in going through the loop, the number was not prime it is changed to false. If we leave it as false without resetting the next time it goes through the loop all the numbers will appear not be prime even if they are. It needs to be reset to the original value of true somehow so that we do not get false negatives.
The way Rahul did it makes sense also. He's essentially moving the initialization of the isPrime into the loop and resetting it at the top each time (which in a loop would be technically right after when it would have been reset at the bottom). He saves that earlier initialization step when the isPrime is declared but it doesn't make it any more efficient to do it that way (perhaps slightly more readable).
I think you are over thinking this. Sit down with a pencil and paper and go through the loop for your input of 7.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It resets the indicator for whether or not the number is prime for the next cycle through the loop. Otherwise it stays false and will keep breaking out of the inner for loop instead of testing.
The total number is simple just put a counter inside the if (isPrime) statement after cout << "Prime:";

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can use the Split() method of the string to divide it up by a set of delimiters into a string array. Then you can use the static TryParse method in any of the numeric types (e.g., Int32.TryParse(), float.TryParse(),and for double, Int16,Int64, even boolean) to get numbers from the individual strings. The TryParse methods are a bit like those in the Scanner class (it's been a while since I've worked with Java but with TryParse I don't think (AFAIK) you can use it to go from one number in a string to the next, for example).

Note: TryParse returns a bool value as to whether or not it converted the number. If you are into exceptions you can use the Parse method of each of those (e.g., Int32.Parse()) but it will throw an exception when it cannot convert. See the documentation below for some examples.

String.Split()

Int32.TryParse()
(others will be similar)

Post back with any further issues or if I misunderstood what you wanted.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Either run your code from 0 to i<7 and afterwords put another if statement for the i = 7 case

for(i=0; i<7; i++)
    {
       if(binaryinput[i] != '0')
       {   
           printf("%d + ", (int)pow (2, 7 - i));
       }
       else
             printf("0 + ");
   
    }    
     if(binaryinput[7] == '1')
            printf("1 \n");
     else
            printf("0 \n");

You could also nest an if statement inside your other if

for(i=0; i<8; i++)
 {
       if(binaryinput[i] != '0')
       {   
           printf("%d ", (int)pow (2, 7 - i));
       }
        else
                printf("0 ");
      
     //new if statment
      if (i !=7)
           printf("+ ");
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
if(binaryinput[i] != '0')
{
       printf("%d + ", (int)pow (2, 7 - i));
} 
else
      printf("0+ ");  //this assumes you've screened your string to make 
                            //sure that there are no other digits
                            //which can be done when you are stepping through
                            //to calculate the result (e.g.   binaryinput[i] !='0' && 
                             //binaryinput[i] !='1'  then break out of the loop

And PLEASE use code tags //your code here

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sorry, that was my abbreviation (it might have been faster just to write it out hehe) for (int)pow (2, 7 - i) .

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why not use

enum pInfo
{
	pLevel,  // =0
	pMember, // =1
	pLeader   // =2
};


int PlayerInfo[MAX_PLAYERS][3];

otherwise you have all the elements in the enum = 0 so PlayerInfo[n][pLeader] would be the same as PlayerInfo[n][pLevel] (all accessing the [n][0] cell). The latter change is going along with what NathanOliver said, but I'll add since you know the number of elements in the enum ahead of time there's no reason not to declare your 2D array as such.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you're printing a chain of additions out, each will have printf("%d + ",powexpression) except for the last which will have printf("%d,pow expression) so you'd have "128 +" (next loop) "0 +" (next loop) + ...+"0"

fgets just takes your array, binaryinput, the size of your array, 9 (as Narue pointed out), and stdin (as it can be used with other streams.
besides standard input). It's safer in that it takes in only your 8 characters and null terminates the string. getche is also specific to the conio library and is as xavier pointed out non-standard (as is system("pause") but we'll save that for another time.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

printf (int)pow (2, 7 - i) with a plus sign after it unless it's the last bit (no extra + at the end). If you don't put a '\n' into your printf it will all go on one line.
Did the other corrections work?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

hint: on this line printf("\n\tThe binary number %s has been converted to %d decimal\n\n",i ,result); the variable i is not a null terminated string.

Also, try fgets(reference here - ignore that it's a C++ site)for your input it's much cleaner (and standard).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I just meant to change a digit here and there but ok. See my edit to the above post.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You may want to obfuscate your MAC number in the file.txt I think you should be ok behind a router but I'm not up on the nefarious side of things.

EDIT: path = @"d:\\file.txt"; should either be a literal string (with the @) or with the escaped backslash, not both. Same with the rest of the paths (some need @ and don't have them and have single slashes). So pick one style and stick with it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
if (!File.Exists(path))
            {
                using (StreamWriter sw = File.CreateText(path)) // Create a file to write to madavas2.txt.
                {
                }
            }

I'd let the command prompt worry about creating the actual file. If I remember correctly the redirect > simply clobbers whatever file it was anyway. You should test for it after the file has supposedly been created, though, it couldn't hurt.

same thing with this part

path = @"d:\\madavas1.txt";
            if (!File.Exists(path))
            {
                // Create a file to write to madavas1.txt.
                using (StreamWriter sw = File.CreateText(path))
                {
                }
            }
            path = @"d:\\madavas2.txt";
            if (!File.Exists(path))
            {
                // Create a file to write to madavas2.txt.
                using (StreamWriter sw = File.CreateText(path))
                {
                }
            }

In the regex stuff, the way I had it toggling the found (found = !found) it will miss the last line that matches the regex pattern. That's why I had put that (found || last) portion in.

There are a couple of stringreaders and I think one streamwriter that should have using statements also.

Otherwise, if possible could you put up a sample madras1 and madras2 (as text) and probably a file.txt (I can run route print on my machine but the results may be different). Obfuscate them all you want, in fact throw in some artificial regex matches to see if it works.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

EDIT: StringReader madvas2 = new StringReader(readtext); on line 47 is wrong, readtext is your text string, not a path.

Is completely incorrect on my part. I misunderstood what you were trying to do. I'll work on the other part and get back to you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You'll need to put some "getter" methods in your employe class. For example:

public string getLastName()
      {
          return lastNmae;    //this is still your variable name you might want to change it

      }

and then use the contains on the string.  

employeeList[i].getLastName().ToLower().Contains("me")

As it is you were seeing if the list contained that string element but it won't look inside your objects to find it, I don't believe.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i'm using windows xp and turbo c++ 3.1 and also 3.0

give me a clue that what is wrong with the compilers

Have you tried anything like mingw (included with Code::Blocks or standalone) or Visual C++? All of the above are free and much much more recent (to put it politely).

EDIT: From the linker output it looks like you are using graphics.h. You may have to change some of your code to other libraries (e.g., nCurses and its variants) for it to be fully functional.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This is when it becomes time to sit down and write it out with pencil and paper. There are only a few numbers to deal with so it's manageable in this case. Write down what's happening at each call to your recursive function.
EDIT: goofed up base case

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You are not getting any output because all the programs you have posted are calling decrement() but never displaying the value it returns. If you can output within your recursive function itself it will make things easier on you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's best with any kind of stream operation to use the using keyword, as it disposes of the resources properly. Try in lines 15-17 to have it follow the

using (StreamReader sr = new StreamReader(file))
{
       lines 16-17

} //closing this off destroys the object

EDIT: StringReader madvas2 = new StringReader(readtext); on line 47 is wrong, readtext is your text string, not a path.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You index a list by [] just like an array. sl[0] gets you the first array of strings and sl[0][4] gets you the last entry in the first array of strings.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

a quick problem

System.Diagnostics.Process.Start("cmd.exe", @"/c del  d:\\file.txt"); //Delete the  output dump file

i am trying to delete the file.txt after the use using the dos command. but the file is not getting deleted.

Did you close the streamwriter with the Close() method? Theoretically the "using" statement should take care of that, but it's probably a good habit to explicitly close it. I didn't close my streamreader in one of the other posts, it was an oversight.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can force garbage collection in your program.
See:
http://msdn.microsoft.com/en-us/magazine/bb985010.aspx
But also see this (and related opinions against doing so on the web):
http://stackoverflow.com/questions/233596/best-practice-for-forcing-garbage-collection-in-c

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use

List<string[]> sl = new List<string[]>();
            string temp;
            string [] delim = {" "};
            using (StreamReader sr = new StreamReader("data.txt"))
            {
                while ((temp = sr.ReadLine()) != null)
                {

                    sl.Add(temp.Split(delim, StringSplitOptions.RemoveEmptyEntries));
                }

                
            }

(this was just my test program so you can do the manipulations on temp directly)
Then use Int32.Parse to get the last element in each string array and compare them however you wish.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't need anything after the first line in this snippet. If you read the file to the end then the SR won't have anything more to read.

StreamReader streamReader = new StreamReader(filePath);
            string readtext = streamReader.ReadToEnd();
    StringReader re = new StringReader(readtext);
  string temp = null;

My current problem is that in the text file obtained, there are numeric values like 257, 266 etc. i want to compare the value and check whether the first one is greater than second one. Is there a way to achieve this>?

Where are the values coming from? The line numbers? If they are different numbers you'll have to parse the individual lines for the numbers.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Dictionary <int,string> strdict = new Dictionary<int,string>();

but this code is getting d:\file.txt as the value in the while loop and is not reading line by line

I'm not sure what you mean by this. Console.ReadLine() reads one line at a time until there are no more lines to read.

since i got the line number , i want to copy the text file between these two to a new file . any idea

use a streamwriter and reverse the process. Use a foreach loop to step through the dictionary. Read briefly on the Dictionary container (google c# dictionary. Write each line out one by one.

Instead of putting Console.ReadLine(); after the last line is read, just put Console.ReadKey() at the very end of your program.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How about (I use a dictionary but you could use any container to keep track of the line numbers or strings):
(you can flesh out the other portions -- I can't have all the fun)

bool found = false,last = false; 
                //strdict is of type <int,string>
                while ((temp = sr.ReadLine()) != null)
                {
                    if (Regex.IsMatch(temp, regMatch))
                    {
                        if (found)
                            last = true;
                        
                        found = !found;
                     }

                    if (found ||last)
                    {
                        strdict[lineNumber] = temp;
                    }

                    if (last)
                        break;
                    
                    lineNumber++;
                }

This gets the lines starting with the first match and up to the second match (I think that's what you were trying to do...).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There's also the intersect method of the region itself. It requires a rectangle but send your point in as a 1 pixel by 1 pixel rectangle. If the intersection is empty you'll know the point is not there (looks like you need to save a copy of your region first since it will clobber it with the result when you call the method). I don't think that makes any assumptions about the shape of the region.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I gotcha. I had that possibility in the back of my mind but I wasn't sure how the regions were defined. Apologies.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you use RectangleF rf = r.GetBounds(graphics); then if(rf.Contains(p)) do whatever? I'm assuming that graphics is of type Graphics and is initialized somehow.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Pop in a second variable to keep count in your new array.

int j = 0;
for (int i = 0; i < customer.Length; i++)
            {
                if (TypePerson.Manager || TypePerson.Vip)
                {
                    importantCust[j] = customer[i];
                     j++;
                }
Sivyo commented: Thanks this is the answer. So obvious, don't know why I didn't see it +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, using the same employeeList, sorry. Make a method like the following:

int SearchLast(List<employe> empList,string lastName)
{
          for loop over the whole list
           {       
                     if(lastName.ToLower() == empList[i].lastName.ToLower())
                              return i;
                     else
                              return -999 to main code for not found or  
                               another way you can think of
                              (could probably throw an exception but I don't 
                               know if you've crossed
                               paths with those yet) 
           }
}

note there are fancier ways to search your List item but this will suffice for your purposes (see http://msdn.microsoft.com/en-us/library/x0b5b5bc.aspx)

Then up in your menusystem in Main(), call your function from the delete one for example as employeeList.RemoveAt(SearchLast(employeeList,"Smith")); I'll leave the update method up to you but based on how you have designed things you may need to save the pertinent information to intermediate variables, delete the record, add it back in again as the updated record. The option then exists to have the getter and setter methods within your class so you can manipulate the information directly.