rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Computer forensics is a growing field, and there is always a need for competent analysts in that field of endeavor. If that is your interest, then I would suggest that you consider an MS in computer forensics as well as a BS in computer science. The CS degree is a good start on the forensics stuff, but there is a great deal of depth to the field that cannot be garnered in an ad-hoc manner. It is a real discipline that requires a rigorous approach to generate valid results from your analyses.

As for a final year project, there are a number of things you can do, such as keyword/keyphrase searches, deleted file analysis and non-destructive recovery of deleted data (requires physical access to the drive media, and may require specialized tools), etc. Remember, that in forensics, you need to preserve UNTOUCHED the original media, otherwise you have polluted the water and your analyses may not be admissible in court. So, first you make a bit image copy of the drive being analyzed, then you search that. The recovery of deleted data requires access to the physical media so you can do a sector-by-sector scan to dig out what has been deleted or overwritten. However, you have to document your processes to assure the court that you have made no changes to the media itself (read-only operations). However, the bit-image you made at the beginning should hold a lot of that, so hopefully you won't need to get into …

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

itsRadius is a pointer, you need to dereference it before incrementing it.

Precisely. Ie,

/Prefix, increment then fetch
const SimpleC& SimpleC::operator++()
{
	++(*itsRadius);
	return *this;
}
 
//Postfix, creates temp to store original, increment, then fetch 
const SimpleC SimpleC::operator++(int)
{
	SimpleC temp(*this);
	++(*itsRadius);
	return temp;
}

Anyway, good first effort. The mistake is common in new programmer code. One other issue/mistake is the question as to why you are using a pointer-to-int for itsRadius instead of a simple integer (unsigned is probably better)...?

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

It has to do with the associations of application and file extensions. If you right click on the .exe file, open properties, and then click on the tool icon, you will get a form that shows what applications are associated with that extension. You can change, or move them up/down to change the default. So, the system thinks .exe is another name for .zip... :-). A Windows exe file may run in the Wine environment, but you need to make sure you have Wine installed. Then you may be able to run it as an application in Linux.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Mike, you are giving away the recipe for the secret sauce! :-) Anyway, well stated!

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

In Linux/Unix systems, a dll is called a shared library, and has a .so extension. Read the g++ and linker documentation (man pages) how to do this. It is quite simple to create a shared library with Linux. In any case, the compiler directive when creating the library is -shared. If you are creating a shared library from object (.o) files, then make sure you compile the object files with the -fPIC option. That generates what we call Position Independent Code (PIC), which is necessary for a shared library, since the functions may need to be relocated (different memory position) when they are loaded into the executable.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

The << and >> operator do have higher precedence than the bitand & operator, see this table.

However, I would not recommend that you rely on operator precedence in that kind of fashion. If you need, absolutely need, to use a #define, then wrap everything with parentheses and avoid the problem:

#define FLAG_FAST         (1 << 0)
#define FLAG_VISIBILE     (1 << 1)
#define FLAG_BIG          (1 << 2)

In this case, however, you are defining those flags in a very impractical fashion. This is the more "usual" way, using hexadecimal numbers:

#define FLAG_FAST         0x00
#define FLAG_VISIBILE     0x01
#define FLAG_BIG          0x02
#define FLAG_FOO          0x04
#define FLAT_BAR          0x08
//...

But when I say that the above is "usual", I really mean that it is commonly found in C libraries or APIs, but not in C++ code. In C++, there are several alternatives that are safer and better. One is to use a const global variable (or static const data member of a class):

const unsigned int FLAG_FAST     = 0x00;
const unsigned int FLAG_VISIBILE = 0x01;
const unsigned int FLAG_BIG      = 0x02;

Another popular solution is to use an enum:

enum MyFlags {
  FLAG_FAST     = 0x00,
  FLAG_VISIBILE = 0x01,
  FLAG_BIG      = 0x02
};

And usually, the enums are nested in the class or namespace they are used in or for.

MACROs in C++ have their place for very special purposes that cannot be achieved by any other means and do require a simple text-replace preprocessing. But defining constants is definitely not part of the circumstances in which …

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Still of topic as question was asked why it is running slower on Windows. Down voting my re-primal that you are going off topic is just lame...

Lame, I agree, and apologize for my pique. Won't happen again, but you could cut folks a bit of slack in these regards. Just my 2cents worth.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Mostly, operator precedence is defined by the language standards, but precedence between operators of equal precedence is up to the compiler implementor. That's why I said "Caveat Programmer!" - define your macros as you intend them to be evaluated, scoping them accordingly. Otherwise, what works on one system or with one compiler, may not on another, or even the same platform and compiler after an update.

Another example of this situation is when arguments that are effectively function calls (including prefix/postfix increment/decrement operations) passed to a function have side effects. Since the order of evaluation of the arguments to a function are also implementor-defined, these side effects may cause the function to get arguments of values that are different that what you expect. Again, Caveat Programmer!

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Than's for the advice, I'm off to bed bet right now, just got up to post a news flash about Libya that I got from my phone, then saw your response. I'll definitely check this out in the morning though. Thank you very much:)

Sorry, accidentally down-checked this post - unfortunately, once you do that I don't know of a way to undo it... my bad!

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

@rubberman better read properly before you reply.

@1ML no idea why emulator is running so slow for you I have no problem on my pc (dual boot win 7 / ubuntu 10.10). However I do use IntelliJ instead of Eclipse. PS: You sure that partition was deleted? Windows normally moves boot-loader to it self, but it wouldn't wipe existing partition unless you told it to do. To recover boot-loader check this document

I was replying to the post immediately before my last one, so in that sense I think it was on topic, if not specific to the original posting of this thread.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

It sounds like some probing going on. Make sure your web server and other stuff is up-to-date security-wise. CentOS is pretty secure itself. Have you implemented SELinux extensions? That will help keep out baddies. One final thing is that you might post this to the security forum of www.linuxforums.org where there are more lurkers for Linux-specific stuff like this.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

There are also class static variables that can serve this purpose. The result is similar to the namespace solution mentioned by Saith, but probably better. It is not an uncommon approach to this problem.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

All that macros do is basically text substitution, so this:

#define SEVEN 2 + 5
 
int result = SEVEN * 5;

is really the same as this:

#define SEVEN 2 + 5
 
int result = 2 + 5 * 5;

Applying the order of precedence for numeric operators like this, it is the same as

#define SEVEN 2 + 5
 
int result = 2 + (5 * 5);

since multiplication has precedence over addition. Caveat Programmer!

So, if you want the SEVEN macro to be evaluated as a unit, it should look like this:

#define SEVEN (2 + 5)
 
int result = SEVEN * 5;
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

When you post C++ code like this, also post the class header. Without it, we are flying blind, so to speak. Also, explain what your Heap class is supposed to be doing - what it's purpose is, as clearly as possible. If we know your intention, we can better advise you.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

I think the OP is into it and has good initiative. I just know from personal experience that jumping into Windows programming can take a lot longer than one originally intended.

@rubberman I think your suggestion of a ready made is a good one. If any of them are open source, that's an even better opportunity for the OP.

I didn't look to see if any were (probably some). I just looked enough to see that there were a large number of seemingly reasonable prospects. It would be easy enough to refine the search to open source candidates to start from.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

You might also want to google the web for an already-built flash card application if you aren't into programming it yourself. This google query, "flashcard application download", results in a large number of what seem to be relevant hits.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

You have made a start on defining the problem. Work it out in pseudo-code (describe in plain language the data and processes you need to transform that data to get the results you need), and analyze that until you are clear on what you want to do. At that point, you are ready to start coding - creating classes to model the data, and their behavior to reflect the data transformations you have determined are necessary to solve your problem.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Myself, I'd just quicksort it with qsort() and be done with it. Unless you are supposed to implement a sorting routine for a class exercise, it almost never pays to implement something for which there is really good standard functions for.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

I am running Scientific Linux 6 (a clone of RHEL 6) for the past several months, after 3 years running CentOS 5 (close of RHEL 5). I've been happy with both, and both have some minor issues, stability not being one of those issues. Mostly they deal with changes in the desktop managers (KDE and Gnome). I run Windows in a virtual machine (using VirtualBox) which does support Windows 7, so if you want to run Win7 under Linux, you can easily enough. As for known problems with Win7 SP1, I don't know since as I mentioned before I don't run Win7. I have a couple of clients that run Win7, and they much prefer it to Vista, but that's not saying much.

peter_budo commented: Read carefully before replying -3
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Ok.

1. Write the code to an external .cpp file.
2. Use the system("TCXX progname.cpp") function, where "TCXX" is the name of the Turbo C++ compiler. Assuming it succeeds in compiling, go to #3.
3. Use the system() command to execute the program as in system("progname arglist") where arglist is the list of arguments to pass to the program.

This is just a general road map. Remember, the Devil's in the details... :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

I see mike_2000_17 and I are saying just about the same thing, in different words... :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Well, that should work. I think your comment about sortScores() being hinky (the correct technical term) is probably correct. However, it would be better just to treat scores as an array. Ie,

double avg(double *scores, int numScores)
{
	double total = 0.0;
	double average;
	sortScores(scores, numScores);
 
	for(int count = 0; count < numScores; count++)
	{
		total += scores[count];
	}
        average = total / numScores;
 
	return average;
}
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

What is it that you are trying to do? The question has a number of answers, dependent upon your goals.

1. If you want to take C++ code, compile it, and access/run it inside an already running code that is one thing.
2. If you want to take C++ code, compile it, and run it separately, that is something else entirely.

In the case of #1, that is very difficult (not necessarily impossible). In the case of #2, that is not difficult. Let us know more of what you are trying to do, and maybe we can point you in the right direction. "Give a person a fish, and they will eat for a day. Teach a person to fish, and they will never go hungry."

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Also note the constructor for the Person class, that the member variables are initialized inside the body of the constructor. This is very much beginner practice/mistake, and "not good", the reasons for which I shall not get into here (long-winded lecture material). However, each constructor has an initialization block between the end of the argument list and the beginning of the constructor body, which is where member variables are properly initialized. So, the correct way would be:

Person(string name1, int age1)
      : name(name1), age(age1)
    {
    }
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Mike makes excellent points. And he took a good deal of his valuable time to point these details out. I'm usually a bit more parsimonious in my advice! :-) Anyway, most of what he says is spot on.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Better:

struct Segment
{
  int start, end, value;
};

class Set
{
private:
  vector<Segment*> segments;
public:
  Set() {}
  virtual ~Set() {
    for (size_t i = 0; i < segments.size(); ++i) {
      delete segments.at(i);
    }
  }
  vector<Segment*>& getSegments() {
    return segments;
  }
  const vector<Segment*>& getSegments() const {
    return segments;
  }
  // accessor functions...
};
 
class Collection
{
private:
  vector<Set*> sets;
public:
  Collection() { }
  ~Collection() {
    for (size_t i = 0; i < sets.size(); ++i) {
      delete sets.at(i);
    }
  }
  void push_back(Set* set) {
    sets.push_back(set);
  }
  // other accessor functions...
};
 
int main()
{
  Collection collection;
  // open file, read file
  Set* set = new Set;
  while (!f.eof()) {
    Segment* segment = new Segment();
    set->push_back(segment);
    // fill segment
    // instantiate set using "new" as needed, and fill it with segments
    collection.push_back(set);
  }
 
  // do other stuff
 
  return 0;
}

Memory management in C++ is no different that C by default, BUT IT COULD BE A LOT EASIER! There are techniques, such as using smart pointers and reference counters to hold your Segments and such, so you don't have to destroy them manually. I do this all the time, and as a result, have nearly zero delete statements in my code, and no memory leaks. I also have to deal with very large data sets, for statistical analysis of stocks and options, or performance and failure analysis of large computer networks, for example. My wife also does a lot of C++ coding, but she has data sets that dwarf the mind! …

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Hi,

I've started developing for Androind [ditched Symbian but that's a whole diferent styory], and I'm not what you'd call a naturall Java developer [much prefer c++]. Eclipse seems to run rediculously slowly on windows 7 (64bit), and running a dual boot system with Linux [on which it seems to run a lot faster] is out of the qustion as it destabalises my machine. I don't have the cash to invest in a dedicated Linux machine at the moment so that's out of the question, and I need windows for music production.

My question is does this have anything to do with the fact that I'm having to develop in 32bit Java on a 64bit system. Can I run Eclipse useing 64bit Java, and develop the app in 43bit Java for Android?

Thanx

[P.S. Sorry about the spelling, I'm dislexic and I've just switched back to IE and it dosen't have aspell checking]

As to the specific reason why Eclipse seems to run slow on your Win7 system, I can't say, but I do know that there is a LOT of unnecessary cruft running on most Win7 systems I have seen (clients - I won't touch it myself with a 10' poll). The first thing to look at is the virus scanner. Most Windows AV tools dynamically scan EVERY bit of stuff that goes into memory, with the resulting serious hit on performance. So, go to the security center and turn off on-access scanning and then see if it runs …

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

So, putting my babbling aside, here is some simple pseudo-code for a substring search (not using the strstr() function) - and I am going to assume that the orderedArrayListType class has an array index operator - makes things a lot easier. :-)

S = subset (possibly)
L = list

current member of L is called cl
current member of S is called cs

// Outer loop
found = false
for cl = 0, while not found and cl < L.length(), cl = cl + 1
    // Check if S matches L at current position in L
    // Set placeholder true or false depending upon whether S.length() + cl
    // is past the end of L. If so, then we are done.
    // If the logic tests false, then the inner loop will be skipped and
    // we are done.
    maybe_found = (L.length() >= cl + S.length())
    for cs = 0, while maybe_found and cs < S.length(), cs = cs + 1
        if L[cl + cs] != S[cs]
            cl = cl + cs        // Need to adjust cl for number of elements in S we tested
            maybe_found = false
        end if
    end for
    found = maybe_found         // If maybe_found is still set, we are done.
end for
return found

Anyway, my point is that is is a generic search algorithm that can be adapted easily to your problem.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

This is just another name for substring search. Again what I keep saying to you programming newbies - understand clearly first what your task is and then write out what you need to do in plain language pseudo-code each step that you need to take to accomplish your task. Design first, code last.

Example: I had to develop a rule processing engine where customers could edit some specifications in the database, and it would adapt our compiled software (C++ code) to their site requirements. I first wrote out as clearly as I could what we needed to do. Then I designed UML models until I had a perfectly clear picture in my mind how the system was structured and how the data flows and transformations (including generating complex SQL query code) had to work. That took several months of intense work (mostly brain work). Coding and testing took two weeks. I got a patent for the work... In any case, complex manufacturing process changes could be done with editing less than a half dozen rules stored in the database. My program would read those rules, modify our classes internal structures as necessary, generate the appropriate (and optimized) SQL code to do things like route a lot (semiconductor wafers in this case) to the best next piece of equipment in the fab based upon the lot's process plan, the available equipment, recipes loaded in the equipment, maintenance plans for the equipment, priority of the lot, and a zillion other factors …

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

These sort of problems are much more amenable to understanding if you first write out your algorithm either mathematically, or in many cases, in plain language pseudo-code. Example for an insertion sort (your final code is not using an insertion sort, because it is sorting after the array is generated), you generate a number, and insert it into the list. The insert function will find the correct position and if it is not at the bottom, move everything below where it goes down one element, and put the new member there. So, in plain language pseudo-code:

main:
while not done
   generate number N
   insert N in list
   check if done
end while

insert N:
    # First do empty list optimization
   if list size == 0
       list[0] = N
       list size = 1
   else
       for i = 0, while insert not done and i < list size, i = i + 1
           if list[i] > N # we found the spot
               move list from i to list size - 1 down one element
               list[i] = N
               insert done = true
           else if i == list size - 1  # We are at end of list, N goes here
               list[list size] = N
               list size = list size + 1
               insert done = true  # this is redundant because the increment at the
                            # top of the loop will kick us out, but say what you mean
                            # anyway, it will eliminate an entire class of bugs
           end if
       end for
   end if

I'm leaving the move list down function to you... :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Try something you'd personally find useful, such as a CD/DVD cataloging application. Since you want to program in C++ (my favorite language - been using it for 20 years), try to "think objectively". Think about the things you are modeling, and write the classes for those things with the behavior they should have. Each class should have its own header file and source file - don't jam everything together in one huge source file. That just makes modifications and bug fixes more difficult.

Make sure your class constructors properly initialize all member variables that do not have constructors of their own.

Avoid the NIH (Not Invented Here) syndrome - use standard library functions as much as possible. They have been thoroughly tested, and trust me when I say that writing your own vector or string classes may be educational, you will spend a lot of time implementing something that isn't as good, fast, or efficient.

Passing arguments to functions, where in C you would use a pointer, use a reference instead. It will eliminate an entire class of bugs when you try to dereference a null pointer. The compiler will catch that stuff for you.

Always declare destructors as virtual, and always have a destructor, even if it does nothing. Some day you will want to use that class as a base class, or have it derived from some other class, and this will enable you to delete pointers to either base or derived and it …

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Without seeing what you are doing in assign3.c, this is not helpful. Also, what compiler (include version) and platform are you building on?

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

What mike said is generally correct. However, it is also dangerous! Never dereference a pointer like this without first making sure it is not a valid pointer. This is why we have reference objects in C++ since it eliminates the need to check the pointer first. IE:

int int_function_1(int* y)
{
   int x = *y; // BAD! If y is null, you are toast!
   return x+1;
}

int int_function_2(int* y)
{
   int x = 0;
   if (y != 0)
   {
       x = *y; // Better - we know that y is not null
   }
   return x + 1;
}

int int_function_3(int& y)
{
    int x = y; // Best - we know that y references a real integer
               // unless the caller of this function was a real meathead!
    return x + 1;
}

Also, in mike's example of doing array references (legal code), this is also dangerous in that you must know two things. First that the memory that y points to is really an array (if we are looking past the 0th element), and second that the array is big enough and properly initialized for the element we are accessing. In any case, this sort of code is a very big security hole.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Well, you can enable the setuid bit on the date command (chmod +s /bin/date), then use the system("date time_val") to set the date+time in your C/C++ program.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Short answers,

1. Same as you would in a C application.
2. Ditto - you can't.

Long answers.

1. Why? Call system("ntpdate ntp_server_address") - this will set the system time to the global clock. Guaranteed accurate. If you want to set it to your own value, use system("date date+time_value").
2. The problem here is that you will need to input the password for the root account, and that cannot be done if the process is being run in the background. So, for security reasons, you really can't do that. In a shell, running the command "su -" will request the password for the root account, and if the calling process is backgrounded (no stdin), then it will fail.