Narue 5,707 Bad Cop Team Colleague

>I am trying to find the best cmplier for the C++ program.
If one compiler were the best, there wouldn't be so many out there, would there? :icon_rolleyes: The trick is to try out a bunch of them and pick the one you like best.

tux4life commented: Yup +6
Narue 5,707 Bad Cop Team Colleague

>Am am I right in thinking it has something to do with external linkage?
Something like that. The following operators are implicitly declared in every file:

void *operator new ( size_t bytes );
void *operator new[] ( size_t bytes );
void operator delete ( void* );
void operator delete[] ( void* );

If you override them with a matching definition, all uses will refer to your definition, not the implementation's.

>Basically, Im wanting it so that my overide of operator delete
>is only used in the source files I include Memory.h in.

I strongly recommend not overriding the global new and delete operators. It's tricky to get right and easy to be surprised. Why exactly do you need this behavior?

Narue 5,707 Bad Cop Team Colleague

>Well as for why somebody would care about the process is that clones are like machines.
That's the whole point. I don't see clones as being inferior, while you clearly do. I think it's blinding you.

>However they still are organisms but a low level organism and what does that describe - animals.
Your arrogance is most impressive. You talk about respecting animals, then turn right around and call them low level organisms. Methinks my original post hit the nail on the head.

>So far it sounds like more people prefer evolution to go through its
>natural process until humans are the only species left on the earth.

If you're going to construct a straw man, at least use your superior human intelligence to make it somewhat reasonable.

Narue 5,707 Bad Cop Team Colleague

When you changed int to T in the iterator parameters, they became dependent types. You need to specify that iterator refers to a type name:

template <class T>
int number(
  T n, 
  typename vector<T>::iterator start, 
  typename vector<T>::iterator end)
{
  int count = 0;
  for(start; start != end; start++)
  {
    if(n == (*start))
      count++;
  }
  return count;
}

Or you could just use the std::count template function from <algorithm>. It does the same thing as your function.

Narue 5,707 Bad Cop Team Colleague

>I doubt it'll stem the flow of begging or spoonfeeding - which
>is becoming a growing problem - but it wouldn't hurt.

IMO, all of those announcements and stickies are completely ineffective for fixing the problem. All they do is make it easier for mods to justify punitive action.

sknake commented: agreed +0
Narue 5,707 Bad Cop Team Colleague

>To specify a 64-bit integral (long long) type, use the LL or ll suffix.
However, note that long long is not standard C++ yet (C++0x is nearing completion though), so you might encounter either complete failure or a difference in the details with various compilers.

kvprajapati commented: Agree! +6
Narue 5,707 Bad Cop Team Colleague

>Dev is quite a good compiler and editor but IMO the debugger...sucks.
Yes, the debugger in Dev-C++ has a bit to be desired. It's actually just a graphical interface into gdb, and not a very good one.

>So I would like to know your opinion on Dev
I like it, but I fall back to separate debugging tools or alternative strategies from the integrated debugger. However, note that Dev-C++ is no longer in active development and hasn't been for several years. The longer you use it, the more you'll fall behind as compilers evolve.

>and maybe other IDE suggestions.
My favorite IDE is Visual Studio, and it's entirely because the debugger is pleasant to use.

>I have Dev but use it only when I write portable code.
You know that portable code can easily be written in Visual C++ and Borland C++, right? A good way to write portable code is:

  1. Know the line between standard and non-standard.
  2. Verify your assumptions by compiling on at least three different compilers (ideally on different platforms).

This brings together theory and practice, and because there are so many good free compilers and operating systems, it's no longer an expensive thing to do.

Narue 5,707 Bad Cop Team Colleague

>if you learn C it will be easier for you to solve problems yourself.
As opposed to if you learn C++ it won't be easier to solve problems yourself? What a ridiculous notion.

Narue 5,707 Bad Cop Team Colleague

>IMO, clones are like animals since their not a creation of god or evolution
Is this the underlying issue? Personally, I don't see a problem with treating clones the same as naturally born creatures of the same species. The end result is the same, so who cares what the process was?

That whole "clones are like animals" is both nonsensical and rather mean spirited. Animals are a "creation of god or evolution", so if clones are not a "creation of god or evolution", why are they like animals? Your logic doesn't follow. Further, you've already apparently passed judgment on clones and deemed them lesser beings, which makes all of your arguments reek of pushing a movement that you don't truly believe in to feel better about yourself or look better in other people's eyes. Quite selfish, in my opinion, and it has nothing to do with the topic of animal (or clone) rights.

>I was mainly referring to things like animal abuse and hunting
>of animals. Animals have emotions too you know.

Do lions care how the zebra is feeling when they hunt it down and devour it? Probably not. Your question goes against the natural order.

>they should be treated with the same respect as a human is treated.
Spoken like an idealist tree hugger with no grasp of reality. There's no respect in the animal world between species, only fear. Prey fears a predator. We can fear predators too in the …

Narue 5,707 Bad Cop Team Colleague

>do any of you guys have any idea how to typedef this templated structure?
You don't need to. That typedef strongly suggests that you're using a C-style trick to remove the need for the struct keyword. C++ automatically does it for you:

template<class type>
struct linked_list {
  type value;
  struct linked_list *next;
};

int main()
{
  linked_list<int> my_list; // Okay in C++
  struct linked_list<int> other_list; // Also okay
}

>linked_list.c:7: error: template declaration of ‘typedef’
Typedefs can't have template arguments. You need to specify an explicit type for the instantiation.

Narue 5,707 Bad Cop Team Colleague

>I have used Microsoft
I seriously doubt if you can find at least one version of Microsoft's compiler (try 2008) that doesn't run on Microsoft's operating system. :icon_rolleyes:

>I also tried turbo C.
Somehow I'm not surprised. Many beginners like to find the oldest possible compiler and try to run it on the latest and greatest machines.

>I do not re4member the 3rd one.
Probably Miracle C. :D

Salem commented: Nice :) +18
Narue 5,707 Bad Cop Team Colleague

>I rather not have member variables public rather than private.
Just because it's the default doesn't mean you have no choice. Using your example from earlier in the thread:

template<typename Type>
struct CStack
{
public: 
  const static int MAX = 100;
private:
  Type _array[MAX];
  size_t currentMaxIndex;
};

The only thing I changed was the keyword class to struct . The data members are still private because you used an explicit access section. Nothing else changed because the code doesn't use the default access rules.

>But judging what he is doing he should use classes.
He is using a class. It just happens to be defined with the struct keyword. You can put any philosophical spin you want on the differences, but to the compiler they're the same (the symbol table might even use the same symbol for both). You seem to be implying that there's a fundamental difference that makes classes more OO than structures, which is false. Might I suggest an argument that's far more convincing?

[Good Argument]
Using class is conventional in C++ for most user-defined types, so it should be preferred. struct is there for C compatibility and the class keyword was introduced to match Bjarne Stroustrup's concept of OOP. If you use struct instead of class , new programmers will be confused and experienced programmers will pause to wonder why you didn't follow convention.
[/Good Argument]

This is a practical argument that has a strong foundation in writing …

Agni commented: Some clarity on the issue finally, i used to get all mixed up on that qs a lot of times +3
tux4life commented: Exactly! +6
Narue 5,707 Bad Cop Team Colleague

>Maybe this will give a clearer meaning of what I'm trying to do.
strtok doesn't make a copy of the token, it modifies the original string by adding a null character at the end of each token and then returns a pointer to it. Every pointer in token, and consequently every pointer in CopyAllc.info, is actually a pointer to your dynamically allocated memory. When the memory goes away, so do all references to it.

You need to make the copy yourself:

// Was CopyAllc.info[i] = token[i];
{
  CoypAllc.info[i] = malloc ( strlen ( token[i] ) + 1 );

  if ( CopyAllc[i] == NULL ) {
    /* Handle the error */
  }

  strcpy ( CopyAllc[i], token[i] );
}

Now for some general commments.

>FBUFFER = malloc(sizeof(char)*lSize);
sizeof(char) is guaranteed to evaluate to 1, so you can simplify your call to malloc:

FBUFFER = malloc ( lSize );

Also, an unadorned size is suspicious when allocating memory for a string. Usually I'd expect +1 for the null character:

FBUFFER = malloc ( lSize + 1 );

>for(i = 0; i < sizeof(token); i++){
There are two things I'd recommend on this:

  1. sizeof(token) is not sufficient to get the size of an array unless it's an array of char. You need sizeof token / sizeof *token because token is an array of pointers to char. sizeof gives you the total bytes in the array, and dividing it by the size of …
asm2hex commented: Helped me greatly. +1
Narue 5,707 Bad Cop Team Colleague

>Prefer classes to structs.
Do you have any particular reason for that guideline? I ask because I've met too many people that have some unreasonable idea of classes being more OO than structures. :icon_rolleyes: The only difference between structures and classes is default visibility (public for structures, private for classes). If you always label your visibility blocks, the only difference is the keyword ( class or struct ).

I personally prefer classes much of the time because I tend not to label my data member block:

class foo {
  // Data members here
  // Private by default
public:
  // Member functions here
  // Explicitly public
};
Narue 5,707 Bad Cop Team Colleague

>You could maybe do it by building a linked list of character variables?
That's a little excessive both in terms of space and time. Let's assume you use pointer links for the nodes, that adds the size of a pointer to each character in the "string". It also adds the cost of allocating a new node for each character and whatever overhead is involved in appending the node to the list.

>Another approach is each time allocating the memory needed for the current string plus 1
This is the naive approach. String libraries will typically increase the size by either a chunk or a calculated amount (such as size * 2 ) to avoid expensive memory allocations. For example:

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

char *getline ( FILE *in )
{
#define CHUNK 16

  char *base = NULL;
  size_t capacity = 0;
  size_t size = 0;
  int ch;

  while ( ( ch = fgetc ( in ) ) != EOF ) {
    if ( size == capacity ) {
      char *save = realloc ( base, capacity += CHUNK + 1 );

      if ( save == NULL ) {
        /* If realloc fails, call it a bust and clean up */
        free ( base );
        base = NULL;

#ifdef ENOMEM
        /* Signal a useful error aside from NULL */
        errno = ENOMEM;
#endif

        break;
      }

      base = save;
    }

    if ( ch == '\n' )
      break;

    base[size++] = (char)ch;
  }

  if ( base != NULL )
    base[size] = '\0';

  return base;

#undef CHUNK
}
tux4life commented: Good thing that you told him about the downsides as well :) +6
Narue 5,707 Bad Cop Team Colleague

>There seems to be a lot of conflicting opinions on whether one
>should learn C before C++ or its OK to go straight in to C++?

Anyone who claims that one is a prerequisite for the other is misinformed. You can learn them in either order, just pick the language that appeals to you more. But I do recommend learning both eventually.

Narue 5,707 Bad Cop Team Colleague

>Shouldn't this be an error?
It is an error. Just because it doesn't blow up spectacularly when you test doesn't make it any less wrong.

Narue 5,707 Bad Cop Team Colleague

>note that my native language is not english.
What a convenient excuse, but Your English is good enough, so I'm not buying it.

>a person is insulting, only if he/she intends to insult.
Communication is a two way street, genius. Even if you don't intend to insult, the people you're talking to can still be insulted by your words. Once again, your attitude is extremely self-centered. If you don't intend to give insult, you should probably choose your words more carefully.

>I had only one question in this thread
Last I checked, you've started more than one thread.

>I control my expectations freely
Yes, that's the problem.

Narue 5,707 Bad Cop Team Colleague

>I didn't insult.. I said what I thought.
Just because you're being honest doesn't mean you're not being insulting. You have to be pretty self-centered to suggest that we're not helpful due to your inability to ask a smart question and have reasonable expectations.

Whether I know the answer to your questions or not, don't expect me to help you. You'll find more and more people of that particular opinion as you burn your bridges with reckless abandon.

Narue 5,707 Bad Cop Team Colleague

>the only goal is strong protection.
Why does your code need to be protected? Usually when someone asks for this, they're under the false impression that not being able to (easily) reverse engineer the code somehow makes the application more secure.

Narue 5,707 Bad Cop Team Colleague

Sorry dude, I have a hard time believing that any legitimate school project would require you to make a robust keylogger.

Narue 5,707 Bad Cop Team Colleague

>Hint, initialize your variables.
It's not that simple. An untrained eye could easily say that the variables are initialized prior to use.

>for(int i=0, sum=0; i<=4; i++)
You're actually defining a new sum variable here, not initializing the parameter named sum. The new variable hides the old one, and any changes you make in the loop modify the local variable rather than the reference parameter. You need something more like this:

void getNum(int& num,int& sum)
{
  cout<<"Please enter 5 numbers:"<<endl;
  sum = 0;
  for(int i=0; i<=4; i++)
  {
    cin>>num;
    sum=sum+num;
  }
  return;
}
Narue 5,707 Bad Cop Team Colleague

>can u explain it in an easy way... i mean the complements
Bits go flip floppy.

jonsca commented: Nice! +1
Narue 5,707 Bad Cop Team Colleague

>This should be most performant unless Narue says otherwise
AFAIK, country codes are organized in a prefix hierarchy, so a trie would be the most direct data structure for the hierarchy. Obviously reusing an existing library is ideal, but because there aren't many country codes, you could use just about anything and it'll be fast enough.

However, unless there's a required format for the input string where the country code is separate, some kind of prefix data structure (like a trie) where the query can be refined at each subsequent prefix would make the job much easier.

Narue 5,707 Bad Cop Team Colleague

>toupper() will tell you if the letter is upper case
>tolower() tells you if the letter is lower case

You mean isupper and islower. Well, toupper and tolower will tell you too, but it's a pretty fair bet what the result will be. ;)

Ancient Dragon commented: Yup :) +25
Narue 5,707 Bad Cop Team Colleague

Here's an example that shows your most immediate problem:

#include <cstring>
#include <iostream>

void foo ( char *p )
{
  p = new char[4];
  std::strcpy ( p, "foo" );
}

void bar ( char **p )
{
  *p = new char[4];
  std::strcpy ( *p, "bar" );
}

void baz ( char*& p )
{
  p = new char[4];
  std::strcpy ( p, "baz" );
}

int main()
{
  char *p = 0;

  foo ( p );
  std::cout<<"p == "<< ( p != 0 ? p : "(null)" ) <<'\n';
  delete p;

  bar ( &p );
  std::cout<<"p == "<< ( p != 0 ? p : "(null)" ) <<'\n';
  delete p;

  baz ( p );
  std::cout<<"p == "<< ( p != 0 ? p : "(null)" ) <<'\n';
  delete p;
}

foo is equivalent to what you're doing now. bar and baz are two ways to fix the problem. The problem is that pointers are passed by value, so when foo assigns to p, it's actually modifying the copy rather than the original. Passing a pointer to the pointer or a reference to the pointer allows the function to access the original pointer.

Fix that and we can talk about any further problems.

Narue 5,707 Bad Cop Team Colleague

Assuming by "empty" you mean if you try to read any characters, the input will fail immediately at end-of-file, then testing for an empty file is trivial:

#include <fstream>
#include <iostream>

int main()
{
  const char *filename = "test.txt";
  std::ifstream in ( filename );

  if ( !in )
    std::cerr<< filename <<" failed to open\n";
  else {
    // Read a character, test for end-of-file
    bool empty = ( in.get(), in.eof() );

    std::cout<< filename <<" is "
      << ( empty ? "" : "not " )
      << "empty\n";
  }
}
Narue 5,707 Bad Cop Team Colleague

>I am a diploma holder that's why I am saying this thing.
Proof that a diploma doesn't mean you know what you're talking about. I noticed a snipped link in your post. Are you a spammer?

Narue 5,707 Bad Cop Team Colleague

>i thaught that this website was usefull
It is...for people who are interested in learning and ask real questions. All you did was post code hoping someone would solve all your problems for you.

>but it turned out that all its members are arrogant
I strongly recommend that you don't generalize like that. You're certain to offend the members who aren't arrogant. You'll probably also offend the members who are arrogant, but feel that refusing to help a lazy student doesn't warrant that particular label.

>and wont help a beginner in c++
I've helped countless beginners in C++. A lot of them weren't even worth the effort, but I did it anyway. If you had asked a smart question, I probably would have helped you too. But you didn't, so I didn't. C'est la vie. :)

>so thank you
My pleasure.

Narue 5,707 Bad Cop Team Colleague

>sorry didt know the rules ;) nvm
At least you apologized for not knowing the rules, even though it's pretty obvious you knew you were cheating and you'll likely go elsewhere to cheat now that you know we won't give you a free ride. I'll pray for your complete and utter failure at life.

Narue 5,707 Bad Cop Team Colleague

>i got to something but i still have some final
>touches please can someone help me!!!!

Wow, how lazy can you get? You're basically done. Even a braindead code monkey could finish this program off using trial and error. The first and last rows are super easy, you can subtract one line from the two triangles (because they step on each other), and the second triangle needs to be shifted left by one space. I'd guestimate 15 minutes of work, tops.

Edit: Ah, you also need to print spaces instead of asterisks between the first and last character of each triangle row. That's not difficult either.

Narue 5,707 Bad Cop Team Colleague

This is a trivial homework assignment and we won't help you cheat. Do it yourself.

Narue 5,707 Bad Cop Team Colleague

>If so, how we can free that memory?
Assuming the pointer was dynamically allocated in the function (which it wasn't in the case of foo), you either free it within the function or suffer a memory leak.

>since size of a pointer(**ptrtoptr is a pointer) is always fixed?
>suppose instead of value(int) we are using a value(char) is it correct??

That's the whole point of the construct. If you take the size of the pointer object you're assigning to, the type is deduced automatically. Thus, if/when the type of the pointer changes, you don't need to change the call to malloc:

char *a = malloc ( sizeof *a ); // Allocates a char
int *b = malloc ( sizeof *b ); // Allocates an int
double *c = malloc ( sizeof *c ); // Allocates a double

struct coord { int x; int y; };

struct coord *e = malloc ( sizeof *d ); // Allocates a coord

Notice that the call to malloc follows the same pattern, and that the type is only specified in the declaration (not the call to malloc). Compare that with the more traditional way you were using:

char *a = malloc ( sizeof ( char ) ); // Allocates a char
int *b = malloc ( sizeof ( int ) ); // Allocates an int
double *c = malloc ( sizeof ( double ) ); // Allocates a double

struct coord { int x; int y; };

struct …
sree_ec commented: thanks for the detailed reply +1
Dave Sinkula commented: Thanks for clearing up some fuzz I'd left. +13
Narue 5,707 Bad Cop Team Colleague

>Well, i have used this program in visual C++ 6.0. And it works perfectly.
It crashes and burns in Visual C++ 2005 and 2008, but that's after I fix the code to be more standard. Before that it doesn't even compile. I guess you're behind the times. Not a good thing when you're likely to use the more modern versions out in the real world.

>I am a beginner, and so this code has been checked by a proper teacher.
Yes, you are a beginner. And this code may have been checked by a teacher, but certainly not a proper teacher. A proper teacher would have seen the glaring overflow bug.

>Mistakes will always be found.
Yes, and it's preferred that mistakes be found before the code goes live. Because fixing a mistake in production is far more expensive and time consuming than fixing a mistake during development.

Narue 5,707 Bad Cop Team Colleague

Atleast u'll not have to waste time like i did!!!!

How can it be a waste of time when you learn how to do something? You're basically just preemptively doing everyone's homework for them with this code snippet (seeing as how this program was homework, judging by the file comment).

Anyway, the code is filled with assumptions and poor practices. Here are a few of the ones that stick out:

>#include<iostream.h>
Not standard, becoming more and more scarce as modern compilers start refusing to compile it.

>void main()
main returns int. It always has, even back to the prehistory of C (C++'s primary parent language).

>if (k<=33)
You're making assumptions about the range of long double.

>//register will enhance performance by minimizing access time
In practice, register will probably be ignored by your compiler. Even if this hint is honored, the effect is likely to be detrimental as the compiler is far better at allocating registers than an application programmer. As such, adding restrictions when there's no guaranteed (or even likely) benefit is silly.

>int numArr[10000];
The array size is an unwarranted assumption.

>numArr[10000]=1; //start from end of array.
You mean start by overflowing the array. In an array of 10000 elements, the last accessible index is 9999.

>//numArr is being accessed in this for loop because we have
>made i as register which means the memory is allocated

Um, i is an automatic …

Salem commented: Go get 'em! +18
xavier666 commented: Narue is a surgeon of code +1
Narue 5,707 Bad Cop Team Colleague

>this question need an expert and we are students
Speaking as an expert, that's bullshit. It's a beginner problem that's perfectly suited to students. You think I can't recognize homework exercises? In the time it took to get this far in the thread, you could easily have finished the exercise.

>and if u know it we can learn from u
You mean you can cheat off me. Try it yourself first and we can help you correct mistakes or clarify your understanding of the problem, but we're not going to do your work for you.

Narue 5,707 Bad Cop Team Colleague
class Example {
  int x;
};

Example::x is a private data member. This means that only friends and the Example class itself can access it. This is good practice, data members should be private. But let's say you still want to give users of the class restricted access. A get member function will return the value of x. A set member function will accept a new value for x:

class Example {
  int x;
public:
  int getx() const { return x; }
  void setx ( int value ) { x = value; }
};

This is still unrestricted access, so it's no better than making x public in this particular example. However, unlike making x public, you now have a specific interface that allows for adding restrictions without altering the calling code. Say you want to limit the value of x to a set range. With a public x it can't be done cleanly, but with the get and set member functions it's simple:

class Example {
  int min, max;
  int x;
public:
  Example ( int min, int max )
    : min ( min ), max ( max )
  {}

  int getx() const { return x; }
  void setx ( int value )
  {
    if ( value >= min && value <= max )
      x = value;
  }
};

The concept is simple, though the logic behind it might not make sense if you don't think in terms of public interface vs. private data.

Narue 5,707 Bad Cop Team Colleague

>same q but i need to put something between ""
That's not the same question, it's the exact opposite. You already know what object to print, but you need the format string. The original question needed an object to print.

>but i dont know wat am stcuk
Unsurprisingly, my answer is the same to you as it was for the OP. The documentation on printf will tell you how to construct the format string for printing a single character. It's quite trivial, and you need to learn how to do simple research, so I won't give you the answer. Try googling for "printf format specifiers".

p.s. This isn't a chat room. You can take the time to write well here. You can even preview your post for proofing before posting it. There's absolutely no excuse for such horrid writing. Programmers should be more attentive than that.

Narue 5,707 Bad Cop Team Colleague

>who can answer thi question??
You can. We can too, but won't, because we don't help students cheat on their homework.

Narue 5,707 Bad Cop Team Colleague

>may be the question itself is wrong
It's more likely that you remembered it incorrectly.

Narue 5,707 Bad Cop Team Colleague

The program requirements say all that needs to be said:

Please solve it on your own/submit your own solution.

We don't help cheaters cheat.

Narue 5,707 Bad Cop Team Colleague

Think of console input as a two tier operation. At the top level is the shell (the console itself), which talks to the keyboard driver and buffers characters typed by the user. When the user signals the end of input (usually in the form of a newline), the shell stops gives control over to your program and the input stream begins buffering characters from the shell buffer.

The disconnect is at the newline. If the shell blocks until a newline, control doesn't reach your program until the user has signaled the end of input. Thus, there's no way your program can control how the user types characters without bypassing the shell and controlling input from the keyboard driver itself. This can be done, but not in a standard way. Here's one way using the conio.h library:

char base[31];
char *p = base;
int limit = 30;
int ch;

while ( --limit >= 0 && ( ch = getch() ) != '\r' )
  *p++ = ch;

Take note that by bypassing the shell buffer, you also need to manually handle things like backspaces.

Narue 5,707 Bad Cop Team Colleague

>What does BIOS do on modern PCs after the operating system is loaded and running?
A whole lot of nothing. The whole point of the BIOS is to put the system into a state where the OS can be loaded. After the OS is loaded, it takes over control of interfacing with the hardware. On older OSes (*cough*DOS*cough*), the BIOS was a primary tool for basic I/O even in userland applications. You can still do some of that on Windows, but probably only through very low level (ie. assembly) programming.

Narue 5,707 Bad Cop Team Colleague

>BTW.. look at the previous post. Python IS useful atleast some of the time..
I'm not the one you need to convince. You quoted me, but Ancient Dragon is the one who claimed Python was a toy (which, for the record, I disagree with). Python is an excellent language and I use it on a regular basis both for personal and professional projects. However, if I need C or for something, Python just doesn't cut it. So your original question is still baffling because I don't use the two interchangeably. I use the best tool for the job.

Narue 5,707 Bad Cop Team Colleague

>Are you saying the other 85% should be on my hit list?
[sarcasm]
Of course not. That's silly. You should put everyone who doesn't bow down and kiss your feet on the ignore list! Stupid retarded pleebs who don't know their place deserve it. I mean really, don't they realize that we're the most awesomesauce d00ds on the planet and they should frame our posts after thanking us profusely for our time?!
[/sarcasm]

Narue 5,707 Bad Cop Team Colleague

>whch progrms u need????????
If you do this guy's homework for him, I'll be most displeased. :@

>our teacher just gave us two days...
Which is plenty of time. Stop acting like a loser and do your own damn work. We'll help you if you have specific questions, but we're not programmers-for-hire-by-lazy-cheating-loser-students.com.

>n as one day is already passed
And if you had spent the first day actually doing work instead of trying to find other people to do your work, you might even have been done by now.

Narue 5,707 Bad Cop Team Colleague

>Can I use an overloaded assignment operator for copying character pointers.
Yes, of course. Just keep in mind that you'll probably need to do more than just copy the pointers themselves. If the memory is dynamically allocated (as I assume it is for you to be asking this question) then you basically have to duplicate the logic for the constructor with the added concern of self assignment:

#include <cstring>
#include <iostream>
#include <ostream>

class jsw_string {
  char *_base;
public:
  jsw_string ( const char *init );
  jsw_string ( const jsw_string& rhs );
  ~jsw_string();

  jsw_string& operator= ( const jsw_string& rhs );

  friend std::ostream& operator<< ( std::ostream& out, const jsw_string& s );
private:
  char *_alloc_base ( const char *src );
};

jsw_string::jsw_string ( const char *init )
{
  _base = _alloc_base ( init );
}

jsw_string::jsw_string ( const jsw_string& rhs )
{
  _base = _alloc_base ( rhs._base );
}

jsw_string::~jsw_string()
{
  delete[] _base;
}

jsw_string& jsw_string::operator= ( const jsw_string& rhs )
{
  if ( this != &rhs ) {
    char *save = _alloc_base ( rhs._base );

    delete[] _base;
    _base = save;
  }

  return *this;
}

char *jsw_string::_alloc_base ( const char *src )
{
  char *s = new char[std::strlen ( src )];

  strcpy ( s, src );

  return s;
}

std::ostream& operator<< ( std::ostream& out, const jsw_string& s )
{
  return out<< s._base;
}

int main()
{
  jsw_string s = "this is a test";
  jsw_string r = s;

  std::cout<<"s = "<< s <<"\nr = "<< r <<'\n';

  s = "foo";

  std::cout<<"s = …
iamthwee commented: Does the 's' stand for sarah or sally? +11
Narue 5,707 Bad Cop Team Colleague

Looks like a pigeonhole sort to me.

Narue 5,707 Bad Cop Team Colleague

>Cool, I have no idea what this does tho:
It's functionally equivalent to this:

// std::copy ( p, p + std::min ( old_n, new_n ), save );
std::size_t n = old_n < new_n ? old_n : new_n;

for ( int i = 0; i < n; i++ )
  save[i] = p[i];

>or this
So I would assume. I was giving you an example of a new concept, that concept being the use of allocators.

>Is this in the stl? Any good places to look these up?
The std::allocator class is in the standard library. You can read about it here.

Narue 5,707 Bad Cop Team Colleague

>there some that dont have answer which you know please do tell..
No. We'll tell you if your answers are correct or not, but we're not doing your homework for you.

>Write a brief answer to the following items.
No. You write a brief answer and we'll tell you if those answers are correct or not.

On to the questions with answers:

False 1. When you go through a list of names, from beginning to end, until you reach the one you need, you are performing a binary search.

Correct. That's called an linear search.

True 2. The sort characterized by first locating the smallest item in a list and moving it to the first location, then finding the second smallest item and moving it to the second location, and so forth, is called the selection sort.

Correct.

False 3. When you locate a person’s name in a directory by opening the book about at the middle, determining whether the name is before or after that page, going to the approximate center of the remaining portion, and repeating this process until you find the page with the name, you are performing a sequential search.

Correct. A basic binary search is being described.

False 4. The soft algorithm characterized by some data sinking while other data percolates is the insertion sort.

The question is probably describing bubble sort, but insertion sort can fit the bill too. I'd say this question is poorly worded, but you likely …