WolfPack 491 Posting Virtuoso Team Colleague

It also fails for other stuff like:

STRING b("there");
STRING a = "hello" + b;

Like I said these are not defined. if you want to use the assignment operator like this you will have to declare it. I am not sure if you will be able to get "hello" + b to work. You should be able to get b + "hello" to work but not the other way around.

WolfPack 491 Posting Virtuoso Team Colleague

One other thing wolfie. It doesn't seem to work for this case.

int main( )
{
    STRING s1;
    s1 = "hello";
    cout << s1;
    cin.get();
    return 0;
}

Any ideas? Would you have to overload the equals operator or something?

Yes you will have to overload the equals operator. If you have not declared one, the compiler generates one implicitly in the form of

String& operator=(const String& );

. So even though

s = someotherstringobject;

will work,

s = "somecharacterstring"

will not work.

WolfPack 491 Posting Virtuoso Team Colleague

That is a copy constructor. The standard says that if a copy constructor is not explicitly declared, a copy constructor is implicitly declared. So it is not necessary. Similar for the copy assignment constructor.

WolfPack 491 Posting Virtuoso Team Colleague

Here is a link which shows you how to configure OpenGL under windows.

WolfPack 491 Posting Virtuoso Team Colleague

The OpenGL.dll and glu.dll is distributed with the Windows OS. The header files are usually distributed with the compiler. But you will have to get the GLUT header and dll files yourself.

Just tell me the error messages you are getting.

WolfPack 491 Posting Virtuoso Team Colleague

Lerner's solution gave some runtime errors. Here is a modified version of the OPs class. I passed most of the parameters by reference so that a local copy of the parameter (thereby cluttering the output) is not called everytime a function is called.

#include <iostream>
#include <cstring>
using namespace std;

class STRING
{
      char *str;
      int len;

 public:

       STRING( ) {   cout<<"*** Default Constructor called. ***"<<endl;   str = NULL, len = 0; }
       STRING( const char *s );
       STRING( const STRING& );
       ~STRING( );

       friend ostream& operator<<( ostream &os, const STRING&  s );
       STRING& operator+( const STRING &s );
};


STRING::STRING( const char *s )
{
     cout<<"*** String constructor called. ***\n";
     len = strlen( s );
     str = new char[len+1];
     strcpy( str, s );
}

STRING::STRING( const STRING& s )
{
     cout<<"*** Copy constructor called. ***\n";
     len = s.len;
     str = new char[len+1];
     strcpy( str, s.str );
}

STRING::~STRING( )
{
     cout<<"*** Destuctor called. ***"<<endl;
     delete[] str;
     len = 0;
}

ostream& operator<<( ostream &os, const STRING& s )
{
     if( s.len == 0 )
         cout<<"(Empty)\n";
    else
        os<<s.str<<endl;
    return os;
}

STRING& STRING::operator+( const STRING &s )
{
    len = len + s.len;
    char* temp = new char[len+1];
    strcpy( temp, str );
    strcat( temp, s.str );
    if (str )
        delete []str;
    str = temp;
    return (*this);
}

int main( )
{
    STRING s1("String1");
    cout << "Created s1\n" << s1;
    STRING s2(s1);
    cout << "Created s2\n" << s2;
    STRING s3 ;
    cout << "Created s3\n" << s3;
    s3 = s1+s2; …
WolfPack 491 Posting Virtuoso Team Colleague

What are the error messages? Have you configured the OpenGL and DevC++ environments properly?

WolfPack 491 Posting Virtuoso Team Colleague

Yes it will work. Try and see for yourself.

WolfPack 491 Posting Virtuoso Team Colleague

There must be some documentation in the assignment that was given to you. Read it. We can't guess what a non-standard function is supposed to do just by looking at how it is called.

WolfPack 491 Posting Virtuoso Team Colleague

Can anyone tell wat does this do?? -

_FOpen(Time_File,"r",fp_time);

_Fread(&st_Time,sizeof(TimeHead),1,fp_time,TimeFile);

Thankx
jazz

Where did you find these functions?

WolfPack 491 Posting Virtuoso Team Colleague

can any one guide me how to remove these errors

Usually just including

#define FAR

in a common header file should do the trick. The common header file should be after all your other include files.

where can i find this old vc++ 1.52.

I think if you have an MSDN subscription you can download the old compilers. But stick with the new one. Much better if you can get a newer version than VC6.

WolfPack 491 Posting Virtuoso Team Colleague

Yeah it would be nice. The only problem is I don't know that much of C. So I will pass. Good luck.

WolfPack 491 Posting Virtuoso Team Colleague

Okay. Let's hope someone starts a thread like that.

WolfPack 491 Posting Virtuoso Team Colleague

We don't give Programming Lessons here. You can search for tutorials such as this in the internet.

WolfPack 491 Posting Virtuoso Team Colleague

I'm the Queen of DaniWeb, aren't I?

God Save the King

WolfPack 491 Posting Virtuoso Team Colleague

Where are the variable declarations for treeInsert, leftchild and the such?

WolfPack 491 Posting Virtuoso Team Colleague

thanks a lot.. i'll try it.. by the way, what does std mean? i havent encountered that yet...

cin , cout , endl and the such are members of the std namespace. So in new compilers, you have to tell it to look inside the std namespace, otherwise you will get a compile error. Since it maybe tedious to write std:: all the time, you can use

using namespace std;

after before the main function and you can just type cout , cin , endl . Read this for more information. You can search for "C++ Namespaces std" in google too.

Also in new compilers #include <iostream.h> will give you an error. The correct way is #include <iostream> . Without the .h .

WolfPack 491 Posting Virtuoso Team Colleague

The following code gives a crude Triangle like output. It gets uglier when the number of line increases.

#include <iostream>
int main()
{
  int n;
  std::cin >> n;
  for (int y = 0; y < n; y++)
  {
    int c = 1;
    std::cout.width(n - y );// Added only this.
    for (int x = 0; x <= y; x++)
    {
      std::cout << c << " ";
      c = c * (y - x) / (x + 1);
    }
    std::cout<<std::endl;
  }
  std::cout<<std::endl;
  return 0;
}
WolfPack 491 Posting Virtuoso Team Colleague

Think of it not as alligning to the center. Think of it as outputing a certain number of spaces and then the numbers of a line in the triangle.
For example
7 Spaces+1 8 28 56 70 56 28 8 1
4 Spaces + 1 9 36 84 126 126 84 36 9 1
0 Spaces + 1 10 45 120 210 252 210 120 45 10 1
will give you the output something like

1 8 28 56 70 56 28 8 1
    1 9 36 84 126 126 84 36 9 1
1 10 45 120 210 252 210 120 45 10 1

The best thing to do in my opinion will be to count the length of characters output in the last row, and then use the width method to format the above rows with respect to the last row.

WolfPack 491 Posting Virtuoso Team Colleague

Hello everyone,
im new here and dont know yet most of the policies..

Hello and welcome. Start learning the policy that we only give homework help to those who show effort.

You will have to post what you have done upto now.

emoskirt commented: pls help me of c++ programs +0
WolfPack 491 Posting Virtuoso Team Colleague

You are not doing the calculation for m after getting the value for y from the user.Put m =y*12; after the cin >> y; part.

WolfPack 491 Posting Virtuoso Team Colleague

Looks like I am getting a bit rusty.
You Passed 8th Grade Math

[IMG]http://images.blogthings.com/couldyoupasseighthgrademathquiz/passed.jpg[/IMG]

Congratulations, you got 8/10 correct!

Could You Pass 8th Grade Math?

http://www.blogthings.com/couldyoupasseighthgrademathquiz/

WolfPack 491 Posting Virtuoso Team Colleague

Wait and see.

WolfPack 491 Posting Virtuoso Team Colleague

u can write in anyone c or c++ ..whichever is comfortable to you ..

Remember one thing. Nobody writes code for you. If you have a problem with code you have written, post it, and someone may point out the errors for you. Other than that, asking someone to write code in C/C++ whichever is comfortable will be a waste of time in your part.

WolfPack 491 Posting Virtuoso Team Colleague

That is because you have declared the second arguments of loadArray and printArray as a long array but you are inputing an int array.

Change the declaration of idArray from int to long , or just use int in the function declarations. I dont think you will want it to use long arrays. The range of int should be enough.

WolfPack 491 Posting Virtuoso Team Colleague

You don't need anything complex. You will only have to use the <string>, <fstream> and <iostream> libraries. You will have to read some file input tutorials in C++. Even that is not that complex.

WolfPack 491 Posting Virtuoso Team Colleague

That is because it is going only upto the old string length. You must update the search string length too. Put

len = tmp.length();

Inside the if block after the replace.

WolfPack 491 Posting Virtuoso Team Colleague

It seems you have to increment it by the index where the first repeat occurs.

You have to increment it by the "maximum index where '-' occurs in the replacement string".
For " - " increment is 1. : Maximum Index = 1
For " zzzz--zzz " increment is 6, Maximum Index = 6
For " zzzz--zz - z " increment is 13, Maximum Index = 13

Edit:
But the easiest will be to increment it from length of replacement string - 1. Because you are sure that there is no need of searching inside that part again.

WolfPack 491 Posting Virtuoso Team Colleague

I KNow WC is over, but I just wanna get this out there:

Brasil must've been paid bank to play like they did against France, because I think we all agree that Brasil is a better team than France, but their performance left much to whish for in their game. I mean, they didn't even make it to the Quarters.

None of the teams played like they were supposed to. Teams that were given no chance of winning made it to the final, and those that were the favourites were out halfway through the tournament. That is how any sport is. Sometimes overconfidence can keep you from giving your best. Even the slightest suggestion that there was money involved is unfair and is just pure trolling.

WolfPack 491 Posting Virtuoso Team Colleague

Where is a good source for learning Design Patterns?

Google perhaps.

Has anyone heard of what is called "Gang of 4" and "Model via Control"?

You can find Gang of 4 in one of the resulting webpages above.
Model via Control..hmm. Maybe you mean model View Controller

WolfPack 491 Posting Virtuoso Team Colleague
WolfPack 491 Posting Virtuoso Team Colleague

We don't do school homework, and I am not joking either.
http://www.daniweb.com/techtalkforums/announcement8-2.html

Edit.
You are always ahead of me Dave.

Edit:
But I think I deleted the email first :cheesy:

WolfPack 491 Posting Virtuoso Team Colleague

I think it is not a problem with replace as such, but it is a problem with your algorithm. Since you are replacing "-" with " - ", the next character after the original "-" will become "-". So your code will become an infinite loop. Try replacing "-" with " x ", and then your code should replace characters properly.

WolfPack 491 Posting Virtuoso Team Colleague

Congratulations.

WolfPack 491 Posting Virtuoso Team Colleague

On the contrary, I find them pretty useful. Both as a communicating tool, since pseudocode can differ according to the person, and as a tool to understand the algorithm better. For example I couldn't make head or tail out of the OP's pseudocode, since I am not used to pseudocode like that. But the flowchart was easier to understand. But this may depend on personal preferrence.

@aeinstein :- Glanced at the flow chart and it looked okay to me. What was the tool you used to draw it? Was it a free tool?

WolfPack 491 Posting Virtuoso Team Colleague

Ok I done some more testing it only happens after I add inline code tags as well as normal code tags in the post.

This is a very good observation. I get the same thing at my end too. Both at Work and Home. Well Done. :!: :idea:

hollystyles commented: Alone we are week together we are mighty! +2
WolfPack 491 Posting Virtuoso Team Colleague

Okay what about removing the last cin.get() ? The program should wait till you press enter.

WolfPack 491 Posting Virtuoso Team Colleague

ok.

WolfPack 491 Posting Virtuoso Team Colleague

Maybe this is what you are looking for.

WolfPack 491 Posting Virtuoso Team Colleague

Welcome to Daniweb. This is how this forum works.

There are several sections like software development, web development, etc. these sections are further divided to more specific areas like C/C++, PHP,Web Site Management etc. It is your responsibility to select the most appropriate section where you should post your question. After that if there is someone who knows the answer for your question (s)he will answer.

Read this on how to ask questions the smart way.
Also if by any chance you decide to answer someone else' question read this first. More specifically make sure that it is not answered by someone else in an earlier reply. I have seen useless replies for threads that have got much better answers by a previous reply.

Hope you enjoy your stay at Daniweb.

WolfPack 491 Posting Virtuoso Team Colleague

I cant see no given web page,

I mean this web page.

WolfPack 491 Posting Virtuoso Team Colleague

Looks like a linker error. Do you have this problem for my example only or for the example given in the link I posted also?

WolfPack 491 Posting Virtuoso Team Colleague

If you use the radix 10, you will get a string of the an integer in base 10.
For radix 16, you will get a hexadecimal string.
You can try the example in the given web page or the one below.
e.g

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
	char name[10]="stephen";
	char buffer[21]="";
	char *pbuffer = buffer;
	int len = strlen( name );
	for( int i = 0; i < len ;i++ )
	{
		itoa (name[i],pbuffer,16);
		pbuffer +=2;
	};
	printf( "%s\n", buffer );
    return 0;
}
WolfPack 491 Posting Virtuoso Team Colleague

You can pass character by character to itoa with radix 16.
If you only want to display the hex values, you can use printf with format specifiers %x or %X.

WolfPack 491 Posting Virtuoso Team Colleague

But thanks anyway :)

You are welcome :)

WolfPack 491 Posting Virtuoso Team Colleague

That will be mikeandike22 methinks...

that will be you methinks...

WolfPack 491 Posting Virtuoso Team Colleague

cool. :cheesy:

WolfPack 491 Posting Virtuoso Team Colleague

^ is right! :cheesy:

WolfPack 491 Posting Virtuoso Team Colleague

I am
STRENGTH!

Now what? Is that good?

WolfPack 491 Posting Virtuoso Team Colleague

Use code tags when posting code.