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

Main() returns an int. Give this a read.

You cannot use the bitshift operator with a string, the compiler states that very clearly. You could probably write your own shift function that will push a 0 onto the beginning or the end of your string. Otherwise for the built-in ones to work you'd need to convert your binary string to an unsigned int and work with the bits using masks.

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

Your sentinel is given to you and is not a number so trying to compare your character to a number is not right. SENTINEL should be of type char and be equal to '.' It should become apparent based on what AD told you to what you should compare your SENTINEL value.

The second thing is, you have a second loop condition that you need to fulfill. When I first ran your program I could enter 11 characters or 11111 characters without any restriction. Nothing stopped me at 10.

Finally, you may want to look into using an ignore() call after you read in the character.

P.S., Purely an aesthetic thing, when you print out the reversed string you get the period at the beginning. So you should either pass i-1 to your method or adjust the method itself.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No No, i mean that there are some software in market by the help of which we can create bad sector in CD, so that nobody can copy that CD.

No, wasn't aware of that sorry. I thought you were trying to get rid of some confidential CDs.
Maybe ask the men and women of the hardware forums.

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

You mean for disposing of it? Run the edge of it through a good solid paper shredder(be careful to keep your fingers). Otherwise if you are trying to use it yourself how would you read it with a bad sector?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

All of your reader/writer definitions should probably be wrapped in using() , e.g.,

public string ReadWholeFile(string file)
{
     //create a string variable to hold the file contents
     string fileContents;
     //create a new TextReader then open the file
     using(TextReader reader = new StreamReader(file))
    {
     //loop through the entire file
       while (reader.Peek() != -1)
       {
           //add each line to the fileContents variable
           fileContents += reader.ReadLine().ToString();
       }
     //close the reader
       reader.Close()
     }
     //return the results
     return fileContents;
}

so that the objects are disposed of properly (using in this context adopts a try/catch/finally implicitly, and the finally is always run to Dispose())

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No problem! Nice job seeing it through.

ddanbe commented: Nice guidance! +6
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

Here's the heart of it. Adding it to the listbox is a matter of taking the substring 8 characters long after the indicies found. Text is a string found by reading all of the text file until the end.

List<int> intlist = new List<int>();
            string pattern = "te_";
            int index=-1,temp;  //index = -1 to start from zero below
            while(((temp = text.IndexOf(pattern,index+1))>0))
            {                              //when not found temp = -1
                intlist.Add(temp);
                index = temp;
            }

I'll let you have the rest of the fun. :) Post back with any questions.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try looking here

Salem commented: Works for me :) +18
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 a time when you need golf commentators at the forum:
"Well, Jim we're waiting on a post from JoaoC to see what he's got up his sleeve"
"Bob, all we can do it just wait patiently. The crowd is quieting down, he sets up to putt"

Nick Evan commented: Haha :) +12
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

Ok, wow, so this is interesting. How on earth are we supposed to help you if you don't have the problem laid out? Translate it as necessary and come back.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

http://www.csharp-station.com/tutorials/Lesson15.aspx
(or google C# try/catch for plenty more)

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

First off, what is the actual problem at hand?? Secondly, what code have you tried so far to solve this problem?

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've told us much about the main window but nothing about what type of database are you using. Is it a situation where LINQ can be used?

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

I enter marks through textbox, which gets saved in database.

If you've stored them in the database what is stopping you from retrieving them again. Is it a database of your own design?

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

I found a good article here(see the QPC section). Windows has a certain amount of wiggle room between interrupts lowering the precision of the timing (I don't know much beyond that) and this is why people turn to embedded and real time solutions.

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

should i not use arrays to do this?

Unless you know the exact number of records you will have (or it can be determined at runtime e.g, by the user entering a value), it is far better in most situations to use a list. Take a look at some of the information and links that the other posters have provided for you. A list will expand itself as it needs more storage (to a finite limit of course but far far larger than anything you would need). A list also has built in methods that make it highly searchable and sortable. C# arrays provide a few more bells and whistles than their C++ counterparts but they are still limited.

i cant use variables because people can enter more than one

I'm not sure what you mean by this... do you mean more than one record. You can use the Add() method of the list ad nauseum. Make a new object, add it to your list (if you're feeling adventurous you could simply add a "new" object myList.Add(new myObject(constructor parameters)); and save a step).

I hope I haven't made you more confused. It might be helpful for you to give us a brief summary of what you know so far about arrays and lists and why each would or wouldn't be appropriate for your problem (1-2 sentences not a term paper).

Geekitygeek commented: very well put :) +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.7 . It's within the answer to another (not really related) question but the information is the same.

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.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

how i made the 2 others, update() and delete()?

Well delete is easy but you can't use foreach since you are modifying the list during the process.
So for both processes (update and delete) make a search function as you suggested which returns the index of a matching criterion for example (employeeList.lastName == "Smith"), return i if this is true. Do this search using a regular for loop with i<employeeList.Count as your loop condition.
Then use employeeList.RemoveAt(i) to get rid of that one. I'll leave the Update() method to you, but suffice to say use that search function and return the index, then make the changes accordingly.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

We will not simply convert the program to your requirements for you. Please make an attempt and once you reach a point that you are stuck, post back your code (or a sample therein) with specific problems.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Welcome. Is there a specific issue you are having with the program? Please let us know so we can help you better.

EDIT: One change right away:

#include<iostream> //no .h for the C++ standard
#include<cstdlib> //C++ version of header stdlib.h
#include<cstring> //you were partly right
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Welcome. Please read the following http://www.daniweb.com/forums/announcement8-2.html and please note that we do not give "complete program"s.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

and why when i set more than one employe i get list of only one in the print() method when i chose '4' in the menu? i mean, i need to show all of the employes i have stored...

Take out the Console.clear() call that you have in your Print() statement, you are clearing the screen in between each output. I'll leave it up to your creativity to get it so that it only prints the banner once and the rest with just the names.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

you mean put the set() methods in the employe class? but how can do that? by not using constructors?

Well, what you should do is have your secretary inherit from employee and either have the methods of secretary be the ones to get the monthly hours, etc. or call the constructor for secretary which would include the hours per month and then send all the other parameters to the employee constructor (the base).

public Secretary(string name, string lastName, string bDate, float baseSal,float hoursPerMonth)
            : base(name, lastName, bDate,baseSal)
        {
            this.hoursPerMonth = hoursPerMonth;

        }

But in terms of what you are doing, you can add the methods to get the data from the keyboard (set_employe and set_secretary, etc) as methods of the employee class. You would be writing to private members of the class just as if you called the constructor. But in fact nothing is stopping you from having both a setter function and a constructor that takes in the parameters. These are design decisions that may or may not be according to best practices but for your project you should pick one and stick to it.
One thing, though, if one of your menu functions is to edit your data you'll need some way to get access to those private variables.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Move your list declaration and instantiation outside of your do loop.

List<employe> employeeList = new List<employe>();

    do
    {
      Console.WriteLine("chois: add = 1\tupdate = 2\tdelete = 3\tprint employe list = 4\tquit = 5");
       chois1 = int.Parse(Console.ReadLine());
       switch (chois1)
       {
             case 1:
            {
               Console.WriteLine("Chois: secretary = 1\tsellsMan = 2\tManager = 3\tTopManager = 4");
                char chois = char.Parse(Console.ReadLine());
                switch (chois)
                 {
                     case '1':
                              {
                               set_employe(out name, out lastName, out bDate);
                               set_secretary_sall(out sellPerHour, out hoursPerMonth);
                                        //then still do your adding here
                               employeeList.Add(new employe(name, lastName, bDate));
                               employeeList[employeeList.Count-1].setsecretary(sellPerHour, hoursPerMonth);
                                        //get rid of all these things
                                         //count++;

                                        //e = new employe(name, lastName, bDate);
                                        // e.setsecretary(sellPerHour, hoursPerMonth);
                                        break;
                                    }

Change case 4 (of the main menu, to print)

case 4:
{
      foreach (employe emp in employeeList)
      {
          emp.Print();

       }

       break;
 }

And down in the print method, get rid of the for loop

public void Print()
      {
              Console.Clear();
              Console.WriteLine("name\tlast\tbirthdate\tsallary");
              Console.WriteLine("----\t----\t---------\t-------");
              Console.WriteLine("\n\n{0}\t{1}\t{2}\t{3}", name, lastNmae, bDate, sallary);
         
      }

I still remind you though, that your method for setting the employee data that you call probably should be a method of the employee class. Check your assignment and make sure there is not supposed to be inheritance between the employee class and the subtypes.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

shank123,
Thanks for helping the poster. However, in the spirit of truly helping posters with their homework, it's best not to give the answer away completely.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Post your code in its entirety. Also, please describe what problems you are having with it. What ddanbe was saying was that your declaration (and initialization) of employeeList should be at the level of Main() so that you are not creating it new every time your user selects option 1.