dusktreader 137 Posting Whiz in Training

But if we need to create a application for a particular device like mobile or digital camera we need to write in C or C++ with out using this libraries and it will take 100 to 200 likes depending up on our requirements is it right ?

So all this available libraries make our code easy and see the result immediately with out any difficulties in system...
Kumar

I use OpenCV every day, and, yes, I think it is an awesome library. However, you should realize that using OpenCV introduces a large overhead because it is a very rich library. On my system, libcv.so ( the main OpenCV library ) takes up 10 MB of space.

If you are just opening the image ( especially if you know the data format ), it would probably be better to use a smaller library. Of course, if you really are doing image processing, it may be excessive to implement the algorithms yourself.

What types of images are you opening? With which algorithm are you processing the data?

dusktreader 137 Posting Whiz in Training

>In my mind "b5" is greater than "b005", because my brain puts trailing zeros after the first.
The idea was that leading zeros and whitespace would be a part of the number rather than part of the previous character. So your example would be comparing "5" and "005" because 'b' matches in both. I felt that it made more sense for "5" to be less than "005".

In the context of file names, this makes sense.

dusktreader 137 Posting Whiz in Training

Here is my solution:

int natural_compare( const std::string& a, const std::string& b ){

    // Remembers which input had the first leading zero
    int lt = 0;

    // Temporaries.  Used for converting natural equivalents ' ' and '0' to '~'
    char ta, tb;

    // Remembers if the previous characters composed an integer value
    bool num = false;

    // Iterate over the strings stopping at the end of the shorter one
    for( unsigned int i=0; i<std::min( a.size(), b.size() ); i++ ){

        // If there is a data missmatch.  Look for special circumstances
        if( a[i] != b[i] ){

            // Use the '~' replacement unless the input is currently numeric
            ta = a[i] == ' ' || ( a[i] == '0' && !num ) ? '~' : a[i];
            tb = b[i] == ' ' || ( b[i] == '0' && !num ) ? '~' : b[i];

            // Because the strings don't match here, the can't be numeric
            num = false;

            // There is a natural missmatch with no special circumstances, so terminate
            if( ta != tb )
                return ta - tb;
            // The strings match, so check for leading zeros
            else if( lt == 0 )
                lt = a[i] - b[i];
        }
        // Still equivalent, so check for numeric state
        else
            num = ( num && a[i] == '0' ) || a[i] > '0' && a[i] <= '9';
    }
    // The strings are naturally equivalent, but the longer is naturally greater
    if( a.size() != b.size() )
        return a.size() - b.size();

    // The strings …
dusktreader 137 Posting Whiz in Training

I have another problem in implemention of Huffman code..
in some file there are chararacters that stop the reading of the chars from file if we put flag on default and if we put flag on binary we face a new problem.. in this case for example "Enter" read by get() translate '13' instead of 10 ... what can i do to solve this problem...
tnx

Well, I'm not sure exactly what you are asking here. If you are confused about processing binary files, this website might help you out ( just scroll down to the binary files section). If you post the code that processes the file and its exact output, that would help.

dusktreader 137 Posting Whiz in Training

Tnx so much for your help,if we change the code in this way :
byte = byte | ( bits << 7-i );
then we protect the order of byte :d

It depends on byte-ordering. Most modern architectures use a little-endian byte ordering, which means that the least significant bit is on the far right.

1 0 0 1 1 0 1
            ^
            |
           LSB

However, in arrays, we usually think of the element with the lowest order as being on the far left ( at offset 0 )

[1, 0, 1, 1, 0, 0, 1]
 ^
 |
 Lowest Order Element

You should think long and hard about what convention makes the most sense to you. There is no convention that is truly more correct ( though many would fiercely debate that ), however, you should make sure that you use a consistent convention to avoid confusion.

dusktreader 137 Posting Whiz in Training

any help

Sum
Variance
Perhaps try to help yourself some. There is this really great resource for programmers to find information to help solve their problems. It's called google.

Salem commented: Nice +19
dusktreader 137 Posting Whiz in Training

I recommend using std::copy so there is no chance for mistake.

He's doing a conditional copy, so the std::copy won't work. He asked about a similar question in another thread and Duoas already suggested to use the remove_copy_if method. I don't think the OP is listening, though.

dusktreader 137 Posting Whiz in Training

You, sir, are a perennial fail-monkey. I looked over some of your other posts, and it appears you aspire to meddle, if not maliciously, then carelessly with windows processes.

http://www.daniweb.com/forums/post1096793.html#post1096793
http://www.daniweb.com/forums/thread251123.html
http://www.daniweb.com/forums/thread251121.html

At any rate, you certainly aren't contributing anything worthwhile to the community...

dusktreader 137 Posting Whiz in Training

I hope to copy from container to another container.
But it is not easy. gdb said I'm trying to copy const string to string.
---------------------------------------------------------------------------------
0x00007ffff7b760f3 in std::string::assign(std::string const&) ()
from /usr/lib/libstdc++.so.6
---------------------------------------------------------------------------------
I don't know how to copy from container to container one by one.
WiIl you help me? thanks you.
This is my code.
---------------------------------------------------------------------

typedef class file_info 
{
public:	 
	int     ino_no;
	string  file_nm;
} file_inf;

vector<file_inf> input_stl; //Original container declaration

copy_123() {
vector<file_inf> inputA_stl; 
vector<file_inf> inputB_stl; 
	for(i = 1; i < input_stl.size(); i++) 
		{			
			j = i + 1;
			if(input_stl[i].ino_no != input_stl[j].ino_no)
				{
					inputA_stl[j].file_nm =input_stl[j].file_nm;
				       Acount++;
				}
            }
}

1. Your class is named file_info not file_inf
2. I don't understand why you are starting at index 1. C/C++ containers are indexed starting at 0
3. You are trying to set the jth value of a container that has nothing in it!

Carefully read this. You need to use push_back() to add values to a vector. However, you shouldn't be using them until you understand how they work. That goes for any construct in any programming language.

dusktreader 137 Posting Whiz in Training

I read your first lesson. It was....interesting. Here are a few highlights

You can name your variable anything (as long as it doesn't correspond with any keywords used in the C++ language; no spaces are allowed). You put a semicolon at the end of the line.

So, i can name my int variable int #1Awesome.variable/value; ?

The all powerful #define is the last thing you will learn in this lesson. You can use this to set text commands. Almost like macros.

Almost like?

You really have an odd assortment of information here. Some of it is correct and succinct. Some of it, you launch into way too much detail about things that a beginner needs to know nothing about. Some of it is misleading. Some of it is just plain wrong.

The best teaching tutorials I have seen take small, compileable programs and break down what is happening at every step along the way. I appreciate what you are trying to do, but if you are going to shepherd the lambs, take them to meadows you know well.

VilePlecenta commented: #lol^ߑ +0
dusktreader 137 Posting Whiz in Training

This is an excellent object lesson! Overrunning an array will not always result in a segmentation fault. So, you can often read data beyond the end of your array without error. If you are not careful, you may end up processing this junk data, and then you will spend a good deal of pounding your head against the wall wondering why your results are bad. Bounds checking is one of the single most import skills required by good C and C++ programming!

dusktreader 137 Posting Whiz in Training

I do want to setup my environment such that there is a possibility of adding attributes in the future, so from that perspective it seems that using a class might not be a bad idea.

You should probably spring for some type of object in this case. Though, you might find it more suitable to use a struct for your code. Struct objects don't need a constructor (though you can give them one) and all of their members are public, so access is simpler. Of course, you can specify a class with no constructor and all public members, but what would be the point?

It is true that I need flexibility to scale up/down the system easily, so if this is an advantage of vectors it would make sense in that case for me to make use of them.
...
The issue that I really have with arrays now I guess, is that when two particles collide in my simulations, they are reduced to one. Since the particles are basically indexed by the row number in the array, this means eliminating a row, which means shifting a whole lot of data up and down the array. I am worried that this might be a weak way of programming as lead to simple errors. With a unique identifier to the objects which is not linked to the row number in the array e.g., a pointer to the object, it is my understanding that I would be eliminating this …

dusktreader 137 Posting Whiz in Training

EDIT2: would that code work?

if(name==s[0]||s[1]||s[2]||s[3])
{
string name="******";
cout<<name;
}

You aren't thinking about what is happening here. The if statement is not going to do anything meaningful. C++ operator precedence says that == is evaluated before ||. So, you first test if name is equal to s[0]. You get a boolean value from this, say 1. Then you use a logical or ( || ) to compare the boolean value to a string. This is not going to help you out. I think you meant name==s[0]||name==s[1]||name==s[2]||name==s[3]

dusktreader 137 Posting Whiz in Training
s[0]=="badword1";
s[1]=="badword2";
s[2]=="badword3";
s[3]=="badword4";

These four lines will do absolutely nothing. You need to be careful to differentiate between the assignment and equivalent operators.

dusktreader 137 Posting Whiz in Training

Hi guys..
In the huffman algorithm I have made an output file contain 0 and 1..
how can I say to compiler that these 1 and zero are bit no Byte.
and how can i make the real Huffman output that its size is lesser than the initial file,
What is the huffman output?
tnx.

You can't output a single bit. The smallest amount of data that can be written to any storage ( register, cache, ram, HD ) is a byte. If you want to write individual bits, you need to first package them in bytes. So, take your 8 bits, use the left shift operator ( << ) to move the bits to the correct offest, then use a bitwise or ( || ) to combine them into a single byte.

char bits[8] = { 1, 1, 0, 0, 1, 1, 0, 1 };
char byte = 0;
for( int i=0; i<8; i++ )
    byte = byte | ( bits[i] << i );

Don't sweat the "char" type. It's simply an 8 bit integer. Note that the order of bits in the array is "graphically" reversed, so the least significant bit is actually the first item in the array. So, the byte will actually equal the binary value 10110011.

Good luck

dusktreader 137 Posting Whiz in Training

:) My mind went blank for a bit and I couldn't figure out such a simple programme. But then I had a shower and all was well :)

int factorial(int i){

    int fact = 1;

        for(int j = 1; j < i + 1; j++)
        {
            fact *= j;
        }

    return fact;
}

end quote.

You could trim this some more. Try setting fact to the input value i. In fact, since you aren't passing i by reference, you could simply use i to accumulate the factorial. Next start your for loop with j=i-1, decrement j in the loop, and terminate when j<2.

Even though this won't win you much in terms of overall performance, you should still try make your loops as efficient as possible. Eliminate unnecessary iterations and extra variables.

dusktreader 137 Posting Whiz in Training

You can use a stringstream to convert the string first to an integer, then use a stringstream with the hex keyword to convert the integer back to a string

Lookup stringstream and the hex keyword first. Should be easy after you read up.

dusktreader 137 Posting Whiz in Training

Thanks for setting the record straight Naruto, Salem, and WaltP.

I was thinking of bitwise negation, not boolean negation.

Is the double !! any more efficient than, say, impliedTrue && true or, as Salem suggested, impliedTrue != 0 . The last implementation seems to be the most obvious and readable.

dusktreader 137 Posting Whiz in Training

Well I wrote this programme, hoping what I wrote is a lenear sorting algorithm

if it's not pls tell me :-O

for (int j = 0; j < 10; j++)
	{
		for (int i = 0; i < 10; i++)
		{
                        //some operation...
			}
		}
	}}

It's not. I assume that you mean linear in time complexity? You should probably save your effort there. There are no known sorting algorithms that perform in linear time. First, your sort wont work (which you can verify by testing it yourself on random data). Secondly, your time complexity here is obviously O(n^2) which is poor performance for a sort. Basically, this sort can perform no less than n^2 operations for n inputs.

If you need a sorting algorithm, check out the standard template library. The sort is very efficient, as it is an implementation of the Introsort algoirthm. It's time complexity is O( nlogn ), which is about the best you can do with a sorting algorithm.

If you are looking to learn more about sorting, look up "Sorting Algorithm".

Most importantly, test your own code. Giving it random input is a start. Then, you should try to guess what the worst possible input could be ( the input that is hardest for you algorithm ) and test it on that.

dusktreader 137 Posting Whiz in Training

We can't use the optimizer (managerial decision, because people don't know how to use volatile, a different discussion). This is the first time I've ever seen this and I'm interested in any reasoning why we shouldn't just remove it to eliminate code bloat.

It sounds like you might be doing some parallel work here, perhaps. "Guaranteeing" the state of a register also sounds like some sort of a hack to avoid a race condition, perhaps. In serial code, the !!someVar should have no logical effect (especially in the case of native types where, regardless of the type, it's underlying bits are just getting flipped twice). For some reason, this idea is ringing a bell, though I can't place it.

Still, it seems like a hack no matter what. Ensuring thread safety should always be done explicitly using thread-safe constructs provided by the language for that specific purpose.

I would suggest that you create some unit tests for a piece of code using this convention and assure yourself that double negating a byte is indeed semantically null.

dusktreader 137 Posting Whiz in Training

OK I've tried to change my logic. Is this closer to what I'm trying to achieve.

#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main()
{
	string str1;
	string::reverse_iterator str2;
	stack<int> s1;
	stack<int> s2;

	cout << "This program will determine if a given string is a palindrome." <<endl;
	cout << "Enter a string of characters here:." << endl;
	cin >> str1;
	for( size_t i = 0; i < str1.length(); i++)
		s1.push(str1[i]);

	/*bool is_palindrome(const s1&, const s2&)
	{
	for ( str2=str1.rbegin() ; str2 < str1.rend(); str2++ )
	s2.push(str2);
	return s1 == s2
	}
*/
	/*

	if (is_palindrome = 0)
	cout << "It is a palindrome." << endl;
	else
	cout << "It is NOT a palindrome." << endl;*/

	system("PAUSE");
	return 0;
	}

The logic here will work, but it's hardly efficient. You're making an entire copy of the input string in reverse and then comparing the elements of each. For the copy and compare logic, you should only copy half of the input and check. This is still not best. There really is no reason to copy the data. You can simply with an index to the front and back, stepping each toward the middel, and if you find a single missmatch, you are done.

Of course this breaks the requirement for using stacks to solve the problem. Because you have to use stacks, I would concentrate on figuring out how you can use two stacks to compare the two halves of the input string.

dusktreader 137 Posting Whiz in Training

That's fine. I'll wait a while as well (perhaps until you post your solution).

It is is an interesting problem. In particular, the partial equivalence of the '0' and ' ' character poses a nice brain tickler.

dusktreader 137 Posting Whiz in Training

The pop() command does not return the value popped, so first you need to put the top element of stack1 onto stack2, then pop it from stack 1

Still, your logic won't work at all, because you are simply moving everything from one stack to the other. You need to think about how you can determine if the two halves of the word are the same but reversed and how you can use stacks to solve the problem.

dusktreader 137 Posting Whiz in Training

Did you know that asking someone else to do your homework for you is cheating? Did you know that you will learn nothing by cheating on your homework? Did you know you are flushing your money down the toilet if you cheat on a college class that you are paying to take? I hope to god you aren't a Computer Science major.

Also, read this: http://www.daniweb.com/forums/announcement8-2.html

dusktreader 137 Posting Whiz in Training

Look at <stringstream> in the stl. You know how you can pass any standard numeric type to cout and it knows how to print it? Well, stringstream knows how to convert any standard numeric type to a string. Furthermore, stringstreams allow iomanip formatting, so you can pad numbers and other such manipulations.

dusktreader 137 Posting Whiz in Training

My preliminary solution works, though there's one logical step that I'm whittling down. Did you want us to post our solution here, or leave the question unanswered for others?

dusktreader 137 Posting Whiz in Training

You need to use virtual functions:

Class Base{
     int val;
    ....
     virtual int doIt(){
          return val;
    }
};

Class Derived: public Base{
    ....
    virtual int doIt(){
        return val + val;
    }
}

Look up virtual functions and do some reading. Virtual functions are important and a powerful part of c++

dusktreader 137 Posting Whiz in Training

I am in a c++ class and I am doing a program which requires me to read in a text file and do change it. I need to know if something is in " " or ' ' to do this program. I can get the " " by doing

if(char == '"'){}

but when I try the other one it looks like

if(char == '''){}

and I gets errors because I think the compiler thinks the second ' is the closing one and the third is just a mistake or something.

Can someone please help.

you need to use an escaped character

if( someChar == '\'' ){}
dusktreader 137 Posting Whiz in Training

The second line is a constructor. Constructors are allowed to have initialization lists. This simply means that since val is a member of Day, it val be set to d by the initialization call. Initialization lists follow this fomat:

Struct Generic{
    int a;
    float b;
    char c;
   Generic( int x, float y, char z ) : a( x ), b( y ), c( z ){
        //any other setup that needs to be done
    }
};

So, the colon indicates that an intialization list follows.

dusktreader 137 Posting Whiz in Training

i do my set precision like...

cout.setf(fixed::ios);
cout.setprecision(3);
cout<<"the mean is: "<<mean<<endl;

this should make it only 3, to change it to 2, change the number 3 to 2.

I think you meant ios::fixed . This is also how I handle number formatting.

dusktreader 137 Posting Whiz in Training

Hello my name is roman I have this project to do that involves the following:
I need to take a text document full of numbers and output the lowest of those numbers and the highest of those numbers but they first have to be put into an array then outputted... I have all the code for locating and outputting the text file...I also have outputted the highest and lowest values using if statements but could someone share how I can put them into an array?

First, think about how you would normally create and put numbers into an array. How will you know how big to make the array so that it can hold all the numbers you read in? You should probably dynamically allocate the array with the new operation. However, if you don't give the array enough memory, you will have to reallocate. This isn't particularly clean or easy. You could consider using a vector from the standard template library, but it doesn't sound like you can use one for this assignment. What you should probably do is set a maximum number of values that can be read in, and then allocate your array to that size: int* inputValues = new int[MAX_INPUTS]; ( don't for get to delete [] inputValues when you are done with the array ).

How will you know where to put the incoming numbers into the array? You should probably use a counter that keeps track of where new items should be …

dusktreader 137 Posting Whiz in Training

lol no its not that is there a way that i can put up a picture to show you how many emails i have on my iphone for this fourm

Is there a way I can put up a picture to show you how to edit your email notification options?

Oh, yeah, there is...

dusktreader 137 Posting Whiz in Training

hello, i just had a very simple question about float, so i am not going to post the full coding, only what matters in this instance.

my output of program shows the computed number as 4, instead of 4.00, even though it is declared as float

Here is the example:

int sum, num1, num2, num3, num4;
float mean;

sum = num1 + num2 + num3 + num4;
mean = sum / 4.0;


The 4 nums are integers entered by the user in my code and the output shows:

"The mean is 4" when i want it to be the mean is 4.00, or rounded to the nearest 2 decimals.

any ideas what the problem is?

lookup the <iomanip> library. In particular, you will be interested in the setprecision() and setw() functions.

dusktreader 137 Posting Whiz in Training

Why??

I'm pretty convinced that I moronically did someone's homework for them, and they want the thread deleted so that they can use the code without an instructor finding out.

dusktreader 137 Posting Whiz in Training

Here's a compileable solution. It will grade a test of any length with any sort of single letters as answers. It should be somewhat fault tolerant, though I'll leave it to you to add in extra protection. Hope this helps:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

double gradeTest( const string& key, const string& studentTest ){
    double score = 0.0;
    for( unsigned int i=0; i<key.size(); i++ )
        score += key[i] == studentTest[i];
    score /= key.size();
    return score;
}

bool readTest( const string& fileName, string& answers ){
    char answer;
    ifstream fin( fileName.c_str() );
    if( !fin.good() )
        return false;
    fin >> answer;
    while( !fin.eof() ){
        answers.push_back( answer );
        fin >> answer;
    }
    return true;
}

int main()
{
    string key, test0;
    readTest( "key.txt", key );
    readTest( "test0.txt", test0 );
    double grade = gradeTest( key, test0 );
    cout << "grade: " << grade << endl;
    return 0;
}
WaltP commented: DT, PLEASE stop doing homework for others. Give them code that POINTS to an answer, not THE answer -2
dusktreader 137 Posting Whiz in Training

I got excited for a chance to share my love of Qt. Then I saw what the OP wrote... I don't know that he meant to be rude. Perhaps it is a language barrier thing? He did say please....

Anyway, your questions for this forum need to be specific and they need to show that you've tried on your own already. I suggest that before you try to write a game, you should try to write a "Hello World" dialog. You've got a lot of learning to do before you try to hook into OpenGL with the QGraphics* model/view.

dusktreader 137 Posting Whiz in Training
class HARD_SPHERE_COORDS 			// Class to contain all system's spheres and operate on them
{
        ...
	COORD_STRUCT *COORDINDATES;		// Pointer to array to hold system's coordinates
        ...
}

HARD_SPHERE_COORDS::~HARD_SPHERE_COORDS()	// Cleanup memory

	delete [] COORDINATES;
}

First check spelling:
COORDINDATES
COORDINATES

dusktreader 137 Posting Whiz in Training

One more note on the rotate function:

Because the bitshift operators can take negative numers as the rvalue aruments, there is not really a need for two macros. You can simply use a negative index to rotate in the opposite direction:

#include <iostream>
#include <climits>

#define UINT_BITS ( CHAR_BIT * sizeof(unsigned int) )
#define rotateleft(x,n)  ( (x << n) | ( x >> (UINT_BITS - n) ) )
#define rotateright(x,n) ( (x >> n) | ( x << (UINT_BITS - n) ) )

using namespace std;

int main()
{
   unsigned int value = 123;
   unsigned int a = rotateleft(value, 7);
   cout << "after rotate left: " << a << endl;
   a = rotateright(value, -7);
   cout << "after negative rotate right: " << a << endl;
   return 0;
}

output"

after rotate left: 15744
after negative rotate right: 15744

Of course, there is no harm in having both declared, in fact, it may improve readability to have both. I just felt compelled to but in and add the extra info.

dusktreader 137 Posting Whiz in Training

I have an example of a bubble sort, but I dont' understand how to appy it to my program because of the STRUCTURE. I don't know how to name the items using the dot operator. I would appreciate any assistance given.

If you don't know how to access members of a struct yet, then you shouldn't be trying to implement any sort of sorting algorithm. You need to learn the ultra basics first. The dot operator is a good place to start.

Say you have this struct

struct SomeContainer{
    int integerVal;
    double decimalVal;
};

Then, accessing its elements is quite trivial:

int main(){
    SomeContainer box = { 31, 56.96124843 };
    int theInteger = box.integerVal;  // This will now equal 31
    double theDecimal = box.decimalVal;  // This will now equal  56.96124843
    SomeContainer boxArray[3] = { { 1, 0.0 }, { 2, 0.6931 ), ( 3, 1.0986 } };
    theInteger = boxArray[1].integerVal;  // This will now equal 2
    theDecimal = boxArray[2].decimalVal;  // This will now equal 1.0986
    return 0;
}

That should get you started

dusktreader 137 Posting Whiz in Training

With the age of parallel computing dawning and the age of Moore's Law closing, it might behoove you to read up on parallelism. In particular, OpenMP is a nice approach to introducing parallelism into C++ without a lot of overhead ( if you're careful ).

Using constructs like:

#pragma omp parallel for
for( int i=0; i<n; i++ )
    doStuff( arr[i] );

is just awesome. I still get a charge every time I run a parallel process and watch the CPU meters for all of my processors max out.

dusktreader 137 Posting Whiz in Training

Glad to help!

dusktreader 137 Posting Whiz in Training
void addRecord(){
    fstream inventory("Inventory.dat", ios::in | ios::binary);
    //do stuff with the invetory stream
    inventory.close();
}

int main ()
{
    //do stuff
    switch (choice)
    {
    case '1':
        addRecord();
        break;
    //Rest of swtich
    }
    //Rest of main
    return 0;
}

That should get you started. You would just have a different function for each part of the switch.

dusktreader 137 Posting Whiz in Training

1. In general, you shouldn't/can't initialize any variables inside of a switch statement. This has caused me problems before as well. Try initializing your fstreams before of the switch statement.

2. The bool isDone is never initialized. You need to do this outside of the switch also

3. I would put all of the code from each branch of the switch statement into its own function. This will make it much easier to read your code. Also, if you do that, you won't have to initialize the fstreams before the switch (iirc). It never hurts to put all large functional sections ( big pieces of the code that do an independent action ) into functions. This will improve the appearance and readability of your code.

Try these suggestions out, and see if it helps.

dusktreader 137 Posting Whiz in Training

Glad you appreciated the reply. If you are a beginner, you should read up on everything that is available in the standard template library. There's a lot of really useful stuff there, and it can save you a lot of time!

dusktreader 137 Posting Whiz in Training

But since everybody is talking external libraries or other languages (in terms of other languages, if one were to attempt to come up with a worse language than C++ for this sort of work, one would be really up against it to find one. The only thing that comes to my mind would be assembler), I used PowerBASIC ( www.powerbasic.com ), which is my main programming language for desktop Windows.

[rant]
Wow....just, wow. You're really bringing a BASIC derivative into the discussion? While people are talking about power houses like python and perl you suggest a BASIC compiler from 1989? "Here's a nickel kid, go buy yourself a real language."

By the way, there are worse languages for parsing strings than C++. Like, C for starters. But then there are the functional languages: Erlang, Haskell, ML, etc... It may be easier for you, an experienced PowerBASIC programmer (stifling chuckles), to parse strings in this language, but, please, spare others the pain of having to look at code that utilizes constructs like Redim strArr(iLn-1) [/rant]

dusktreader 137 Posting Whiz in Training

I hate to rain on your parade, but as long as you are using classes from the standard template library (string), you might as well use methods from the library as well:

#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[]){
    string alphabet = "abcdefghijklmnopqrstuvwxyz";
    random_shuffle( alphabet.begin(), alphabet.end() );
    cout << "alphabet after shuffling: " << alphabet << endl;
    return 0;
}

As you can see, the shuffling can be done with a single line by invoking the random_shuffle algorithm from the <algorithm> library.

Ancient Dragon commented: You are right. +26
dusktreader 137 Posting Whiz in Training

I would actually unify the two base classes. Instead of implementing the Update() as a pure virtual function, make it a callable function that is essentially a no-op: virtual void Update(){} . Then, all classes that need to be updated will implement their own Update() function. Now, all of your objects should be able to call the Update() method, though only the ones that actually need to be updated will actually do anything.

dusktreader 137 Posting Whiz in Training

plz guide me i m having some error at line 28

1. Explain your problem more clearly. Saying "plz guide me" is not very helpful for us, and it's ridiculously presumptuous that we will respond with thorough help when you can't type more than one sentence.
2. Post the error that you are getting. We aren't psychics that just know what your compiler is saying.
3. Think about what you are trying to do. On line 28, you have a serious confusion that is pretty inexcusable. In particular, s is a char array member of this class. There is no ".t" member of a character array. You probably mean "t.s". If you actually thought about what you were typing, and had a better naming convention, you would probably have caught this as you wrote it.
4. Clean up your code before you post it. The indentations and extra blank lines are infuriating. I truly hope your code doesn't look like this in your IDE
5. Write better code. Your class is named str, but two of your functions (including the one on line 28) return a string. There is a string type in the standard template library, and I doubt you want your char array wrapper class to return a 3rd type of string representation. If you are studying computer science in school, you have a very long way to go. You should learn to write careful code first. Even ridiculously simple classes like these …

Agni commented: I agree !! +3
dusktreader 137 Posting Whiz in Training

Here are a couple of functions I designed to convert between numeric types and strings

/** Converts a number to a string
  * @param  number - The number to convert
  * @param  prec   - Floating point precision to use
  * @param  w      - Width of the string
  * @return A string representation of the number
  */
template <class T>
std::string num2str( T number, int prec=2, int w=0 ){
    std::ostringstream ss;
    ss.setf( std::ios::showpoint | std::ios::fixed );
    ss.precision( prec );
    ss.fill( ' ' );
    ss.width( w );
    ss << number;
    return ss.str();
}

/** Converts a string to a number
  * @param  str    - The string to convert
  * @param  number - The storage for the number
  */
template <class T>
void str2num( std::string str, T &number ){
    std::istringstream ss( str );
    ss >> number;
}

So to convert a string to a float:

float f;
string s="1234.5678";
str2num( s, f );  // Now f should equal 1234.5678

Since these are templated they should work for all standard numeric types.

Note the prec and w argument in num2str. The prec argument will control precision ( # of decimal places shown) for doubles and floats. The w argument pads the number out with spaces to a desired width.

dusktreader 137 Posting Whiz in Training

If those variables are truly defined externally, you should really uncomment line 24 & 25. Declaring an extern variable isn't helpful if the declaration is in a comment.