siddhant3s 1,429 Practically a Posting Shark

Re-factor the simplify function which finally converts a/-b to -a/b. This will maintain uniformity and thus the program will be unambiguous.

siddhant3s 1,429 Practically a Posting Shark

>You return a variable that ceases to exist after the function all (a
>variable local to the called function). Generally speaking, pass a
>pointer (to the start of the array) and then modify it in the called
>function.
Exactly. I know some other person could have given advice to return a pointer which has been dynamically allocated by using malloc. But then, such a advice would be inappropriate since it would lead to the overhead of free-ing the memory.

siddhant3s 1,429 Practically a Posting Shark

>Seriously? There's no options that do this for regular functions, the
>same way it can be done for the main function when it's handed
>command-line arguments? I thought it was possible to do

C++ supports function overloading in which you can have variable number or arguments:

int fold(int x,int f=2)
{
  return x*f;
}
.
.
.
std::cout<<fold(2)<<std::endl<<fold(2,3);
// prints 
// 4
// 6

C ( and thus C++ due to backward compatibility) supports variable number of argument in a function by including stdargs.h (read http://www.codersource.net/c++_variable_argument_functions.html)

siddhant3s 1,429 Practically a Posting Shark

>Recursive functions should be used as sparingly as possible as they
>are extremely slow
Yes. But looking at the other side of the coin, recursive function tend to be easy to model than iterative algorithms.
For say, fibonacci sequence, you can immediately model the function by applying the direct (recursive) definition while the iterative version will surely catch your brain for at least 2-3 minutes (if you are a beginner)

siddhant3s 1,429 Practically a Posting Shark

>>write a recursive function to convert integer into string.
Your function will work good for all positive integer but would fail when N=0.
IntToString(0)=""

siddhant3s 1,429 Practically a Posting Shark

>i'm a noob in C++ can any kind soul please help me
Not until you show any efforts.
Sorry.
Time out.
Best next article for you: http://www.daniweb.com/forums/announcement8-2.html

Salem commented: Well said +36
siddhant3s 1,429 Practically a Posting Shark

>it's me 4101
Oh yeah! Even my real name is 312515473215781215487451 but I let them call me Siddhant so that they remember me.

siddhant3s 1,429 Practically a Posting Shark

You really need to go down to the basics of inheritance - why we use it.
When you construct a base class, it is not really a base class but it is 'just a class'. It is when you use that class to derive a child class, the former becomes a base class.
The base class knows none about its derived class (because at the time of writing base class, the programmer didn't knew(or suppose to know) that there would be some derived class D which would be inherited from this class.
Such anomalous demands indicate a major flaw in design.
I agree with Laiq in that you should re-factor your design.
Think before you code or else you will be in deep _ _ _ _.

tux4life commented: Nice explanation :) +16
siddhant3s 1,429 Practically a Posting Shark

Have a close look on what are you doing.
In the loop at line 12, you read each line in one iteration to the std::string line.
Now you iterate a for loop nested inside the while loop and assign all the element of file[] the same content: line
You do not need two loops. You can eliminate the while loop. A for loop is enough.
Heres a hint:

for (int i=0; std::getline(inFileStream,line); i++)//reads the next line to the variable line till the end of the file.
siddhant3s 1,429 Practically a Posting Shark

One suggestion would be to build a html parsing program and then perhaps connect to http://primes.utm.edu/lists/small/10000.txt and read out the list of primes into the memory and write them down to a file.
Or you could choose this website but the you'll need HTTP/POST feature to get the prime.

PS: I was joking on your laziness above. You won't get any ready made cookies here. Only if you had read the Forum Rules and Announcement you would have found that we only help those who show efforts.
So, Best of Luck!!!
My advices:
1.Learn C++
2.Learn some prime number generating algorithm; there seems to be many and most of them find Sieve of Eratosthenes to be quite effective
3.Try to implement it in C++. If you get struck, get back here with the code you tried on.

siddhant3s 1,429 Practically a Posting Shark

>Any advice how to put each line in its own array element?
Not really but it would be better to apply brains and re-factor the code provided by twomers.
Declare an array of N std::strings and then iterate with a forloop to read one line by one with help of std::getline.
Try it out yourself first. If it doesn't work, come back here with the source-code of what you tried.

siddhant3s 1,429 Practically a Posting Shark

>I have not seen an 80-character width terminal in some 25+ years.
I have seen them neither since birth, But my text editor, my shell window, and best of all, daniwebs code tag formatter are all 80-width wide. You would ( atleast I ) find annoying if you were to see a code like this;

{ ...nested blocks
            {
                    {
                            std::transform(username.begin(), username.end(), username.begin(), ::tolower);
                    }
            }
}
/*Or codes with long  comments following the code line*/


	if (stCOMMA_LOC != string::npos){ //Check that the user included the comma.
		
		char cFirstLetter = strName[stCOMMA_LOC + 2]; //The first letter should appear 2 spaces after the comma.
		string strUsername;
		strUsername.push_back(tolower(cFirstLetter));

		int nCounter = 0;
		
		//Add the first seven letters to the username.
		while (nCounter < stCOMMA_LOC && nCounter < 7)
			strUsername.push_back(tolower(strName[nCounter++]));

		cout << "Your username is: " << strUsername << endl;
	}

>I think my problem is that I don't know many functions offered to me by the
>standard library. I think the only parts of the library I know about are string and
>cctype. Guess I'll be looking into that more next =).
Thats the whole idea. When you would do a drill to search out the library reference your vocabulary of the standard algorithms and data structure will increase which would help you the next time you code.

>If the user doesn't enter a comma between the last and first names, the
>program hangs (I guess the function is stuck trying to find the comma?) …

siddhant3s 1,429 Practically a Posting Shark

Well, another "criticize my code" question. Good.
Here are my advices:

  • Try not to implement the code which has been provided to you by the standard library. This way you will make shorter and elegant code.
  • Avoid magic number: stCOMMA_LOC + 2 , stCOMMA_LOC && nCounter < 7 . Rather, put them under some const variable with a intuitive name so that a month later when you debug your code, you don't come shouting "Why the hell that 2 is been put there"
  • Dumping everything in the global namespace by using namespace std; is not a good idea. Read this post for excellent review of what all options do you have,
  • And yes, try to squeeze your code in 80 character width as people like me ( who run your code in 80-sized terminals) often find it harassing when our text editor wraps the long lines . Use \ character for doing this.

Here is my code, way bit shorter (8 statements) for nearly the same error checking:

#include <iostream>
#include <string>
#include <algorithm>
int main(){

    const size_t endlength=7;//the length of the lastname to be taken
    std::string firstname,lastname;

    std::cout <<"Enter your full name in last, first " \
    "format to create a user ID:";

    //  read till the first encounter of comma
    std::getline (std::cin, lastname,',');
    //  read the rest of the name
    std::cin >> firstname;

    //construct the username
    std::string username=firstname.at(0)+lastname.substr(0,endlength);
    //convert username to lower charachter
    std::transform(username.begin(),    \
                   username.end(),      \
                   username.begin(),    \
                   ::tolower);

    std::cout …
csurfer commented: stupentous reform... I loved to read this reply... ;) +4
siddhant3s 1,429 Practically a Posting Shark

Spoon boy: Do not try and correct void main. That's impossible. Instead... only try to realize the truth.
Neo: What truth?
Spoon boy: There is no void main.
Neo: There is no void main?
Spoon boy: Then you'll see, that it is not the void main what you correct, it is only yourself.

siddhant3s 1,429 Practically a Posting Shark

>Even the delete operator is executed, the last two output statements are working
>same the first two output statements.
This is implementation specific. On my implementation the two outputs are different:

siddhant3s@Xion:~$ g++ tester.cpp -otester.exe &&./tester.exe
p's add is 0x804a008
value in p is100
p's add is 0x804a008
value in p is0

Actually, after you do the "delete ptr", you can never be assure about what is the value of the memory chunk, ptr was pointing to.
An interesting point to note is by considering the following :

int main()
{
int *ptr=new int (100);
cout<<"p's add is "<<ptr<<endl;
cout<<"value in p is"<<*ptr<<endl;

delete ptr; // deallocation of ptr;

cout<<"p's add is "<<ptr<<endl;
cout<<"value in p is"<<*ptr<<endl;

int* ptr2=new int(2);
cout<<"p2's add is "<<ptr2<<endl;
cout<<"value in p2 is"<<*ptr2<<endl;


//    siddhant3s:~$ g++ tester.cpp -otester.exe &&./tester.exe
//    p's add is 0x804a008
//    value in p is100
//    p's add is 0x804a008
//    value in p is0
//    p2's add is 0x804a008
//    value in p2 is2
}

So, look what my compiler did. As I said "delete ptr", it zero out the value pointed by the pointer but did not changed the ptr's value itself. It was still 0x804a008. Now when I requested him to allocate another memory chunk to ptr2, he smartly allocated that old chunk which I deleted.
If I hadn't deleted ptr, the output would come something like this:

p's add is 0x804a008
value in p is100
p's add is 0x804a008
value …
kvprajapati commented: Solid explanation. +7
siddhant3s 1,429 Practically a Posting Shark

>No it isn't because void main() is not allowed by either C or C++ standards. It
>never was, and never will be. There are compilers that will not allow void main().
>The program returns an integer whether you want it to or not.
I was arguing the same with Narue and found out that this is not true for freestanding environment: http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#2.1.2.1

Dave Sinkula commented: Great link! :icon_razz: +22
siddhant3s 1,429 Practically a Posting Shark

There you go.
You have finally done it.
And all these ^^ don't know about the conspiracy about making some crazy thread.
Oops.........
Yeah sure, void main is my favorite too. ^H^H^H^H^H^H^H^H^H

siddhant3s 1,429 Practically a Posting Shark

Google Knows

siddhant3s 1,429 Practically a Posting Shark

>If the size is determined at runtime you need a full fleged dynamic memory
>version. Something like

A full fledged dynamic memory version? Is that what you call your program you just posted.
It would be so much better to rely on the standard headers than your memory leaking program.

To OP: Apart from Tom Gun advice, you may want to consider an array of a structure:

#include <iostream>
struct myStruct{
    int firstVal;
    float secVal;
    char thirdVal;
    long fourthVal;
};
int main(){

    myStruct P[]= {{0,  1.1,  'a',  14554},
                   {2,  2.1,  'b',  14254},
                   {4,  4.1,  'c',  14254},
                   {1,  8.1,  'd',  14254},
                   {1,  1.5,  'e',  14154},
                   {0,  1.4,  'f',  14214},
                   {2,  1.4,  'g',  14224},
                   {9,  1.7,  'h',  13254}
                  };
    std::cout<<P[6].firstVal;
};

This would allow you to use heterogeneous data types.
PS: If you need dynamic allocation techniques, consider a std::vector rather than hacks such has post#2

siddhant3s 1,429 Practically a Posting Shark

Yes.
But the vice-versa works too because it flushes the stream anyways.
This one will do something like this :
send to buffer => flush => send to buffer => flush... and so on
while the former one would do:
flush => send to buffer => flush... and so on
Logically, the first approach (send to buffer => flush) is better than the second (flush => send to buffer)

siddhant3s 1,429 Practically a Posting Shark
siddhant3s 1,429 Practically a Posting Shark

>I want the vector to be of type 'this'
What do you mean by 'this'?
Do you want a vector of pointer to the same class you are in.
Or Do you want a vector of the same class you are in.

If you wan't the former one, look at post#3
If you are interested in the latter, read the code below:

#include <iostream>
#include <vector>

template <typename T>
class MyClass
{   public:
    T data;
    MyClass():data(0){} //default constructor
    MyClass(T t):data(t){} //one argument constructor
    std::vector< MyClass<T> > myvec; //vector of type same as *this
};

int main()
{
    MyClass<int> c;
    MyClass<int> d(5);
    c.myvec.push_back(d);
    std::cout<<c.myvec[0].data;
}
siddhant3s 1,429 Practically a Posting Shark

Even the use of standard C++ ( with int main, standard headers) would be nice.
Read http://siddhant3s.googlepages.com/how_to_tell_rusted_cpp.html sections 2.1, 2.2 and 2.3

siddhant3s 1,429 Practically a Posting Shark

>These can be fun to build! Start simply two operands, one operator! then work up!
Definitely not!! If you are building it for educational purposes fine; otherwise it is not recommended to hand code a lexer[1] yourself.

To OP: If you 'project' is whole about building a lexer, the above two posts would do. However if your 'project' needs a lexer, don't go about making one but use lex the lexer code generator. It is a program that reads the formal grammar and generates code for your lexer.
Here is the manual for lex.

[1] lexer: lexical analyzer

siddhant3s 1,429 Practically a Posting Shark

Learn a GUI library.
wxWidgets is a good one :http://zetcode.com/tutorials/wxwidgetstutorial/

siddhant3s 1,429 Practically a Posting Shark
siddhant3s 1,429 Practically a Posting Shark

True.

siddhant3s 1,429 Practically a Posting Shark

I remember me facing the same problem a year ago.
I used the following hack rather than calling on boosts serialization :
Lets say we have a string sring_to_be_written which I want to serialize:
1. I first write down the s.size() using fstream::write():

size_t size=string_to_be_written.capacity()+1;
    ofile.write(reinterpret_cast<char *>(&size),sizeof(size));

2.Next I write down the s.c_str() itself:

ofile.write(string_to_be_written.c_str(),size);

To unserialize, I correspondingly read the length of the upcoming string first:

size_t len=0;
    ifile.read(reinterpret_cast<char *>(&len), sizeof(len));

Then I make a cstring with help of new:

char *temp=new char [len];

Then I simply read the string into the cstring and assign it to a std::string.

I am posting those two function from my project as-is. You would definitely have to apt it according to you:

size_t writestring(string string_to_be_written,ofstream & ofile)
{
//This function will read the std::string passed as first parameter and will write it
//to the stream object supplied as second parameter. Returns number of bytes
//written
//Read Developer's Manual section 5.1.3
    size_t size=string_to_be_written.capacity()+1;
    ofile.write(reinterpret_cast<char *>(&size),sizeof(size));
    ofile.write(string_to_be_written.c_str(),size);
    return size+sizeof(size);//return bytes written
}
size_t readstring(string &string_to_be_read,ifstream & ifile)
{
//This function will read std::string from the stream object passed as second 
//parameter into the string reference of the first parameter. Returns number of
//bytes read.
//Read Developer's Manual section 5.1.4
    size_t len=0;
    ifile.read(reinterpret_cast<char *>(&len), sizeof(len));    
    char *temp=new char [len]; // allocate temp buffer for string_to_be_read
    ifile.read(temp, len); // copy name to temp, including '\0'
    string_to_be_read=temp; // copy temp to data member
    delete[] temp;
    return sizeof(len)+len; …
siddhant3s 1,429 Practically a Posting Shark

@Dave
I too was thinking about this catch; later only I read your post.
The solution would be this:

do std::cout << "Enter a number: ";
    while( std::cin >> tmp && tmp != -1 && (1 || (sum += tmp)) );

but as you said, neither me is a fan of squeezing Line of Codes; so I would do my job like this:

int main()
{
    int sum = 0;
    int tmp;
    while(std::cout << "Enter a number: "&&std::cin >> tmp)
    {
        if (tmp==-1) break;
        sum+=tmp;
    
    }
    std::cout << "\rSum     =       "<< sum << std::endl;
}

@Tux:
Great Tutorial. I liked it when you covered short-circuit operators.

siddhant3s 1,429 Practically a Posting Shark

http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.16
Read from 16.16 to 16.19 and then try to implement the `features' of what you are talking about. If in trouble, ask the specific question.

siddhant3s 1,429 Practically a Posting Shark

@adata
The first paragraph is about C, not C++. Clearly I mentioned that.

>If you have an empty argument list, you can declare it as func() in c++, which tells
>the compiler there are exactly zero arguments.
Right. But I never said this is not true. But in C, func() means "unspecified number of arguments".

@Tom
If you wan't to argue that it is not deprecated as 'it will remain in further version of C++', fine.
I agree that this style is not officially declared 'deprecated'. But when an authority such as one of the standard makers (Marshall and Stroustrup) deprecates it, you surely have less choice.
If you just wan't to prove my words wrong..... I really can't help it.
Fine?

(wondering where the OP is)

siddhant3s 1,429 Practically a Posting Shark

@Tom:
http://en.wikipedia.org/wiki/Deprecation
http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.4
http://www.research.att.com/~bs/sibling_rivalry.pdf point no. 2.5
Specially to quote:

2.5 From Early C++ and C89 to ARM C++
The Annotated C++ Reference Manual [ARM] was published in 1989 and became the base document for
the ANSI C++ standards effort†, starting with its first technical meeting in 1990. Before that, the various
drafts of the ANSI C standard had been available for years and I had been able to take the first steps to
increase C/C++ compatibility. The most important actions were simply to follow the draft C standard
wherever there were no considered decision to do something different. That way, C++ got the C89 rules for
u ns ig ne d, the v ol at il e keyword, etc. The ‘‘abomination’’
un si gn ed vo la ti le
i nt f vo id ;
in t f(v oi d) // f() takes no arguments
was re-incorporated and a redundant comma in declarations of varadic functions introduced into C89 was
also accepted:

@adatapost
Strictly you are right. Private members are 'inherited' but are not accessible to base class members.

#include <iostream>
using std::cout;
class Test{
    int i;
    public:
        Test():i(0){}
        void foo(){i=5;}
        int bar(){return i;}
};

class TestD:public Test{};

int main ()
{
  TestD t;
  t.foo();
  cout<<t.bar();
}
siddhant3s 1,429 Practically a Posting Shark

What a pity, you are still struck at a 18 year old compiler.
Read this to migrate to a better compiler.
Sorry, But I am on a social movement about "anti old compilers" so I won't/can't help you.

Tom Gunn commented: I hope somebody refuses to help you because you don't use their preferred compiler someday. Are you here to help, or are you here to bash people for your 'social movement'? -1
Salem commented: Works for me!!!!! +19
siddhant3s 1,429 Practically a Posting Shark

>Well, you could try using the derived maths functions:
Why would he when he already have asin and acos?
Besides why did you complicated the formula for acos(x) which is simply:
[tex]acos(x) = \frac{\pi}{2}-asin(x)[/tex]

siddhant3s 1,429 Practically a Posting Shark

>I just thought syntactically that it was incorrect
No it isn't. Syntactically it is fine but it is deprecated.
>because I just hadn't ever seen int main(void) before
Just because you have not seen a construct doesn't imply it doesn't exist.

>So then why are there compilers in C++ that accept this,
So as to provide backward compatibility with the old code

> even if it conflicts with C++'s overloading abilities?
It doesn't.

siddhant3s 1,429 Practically a Posting Shark

It is the old crappy rusted style which is embedded in programmers from C background.
In old C,
int fun(void) and int fun() had two different meanings. The former means "accept no arguments" while the latter meant "accept any number of arguments"

In C++, you cannot create a function which can accept "any number of argument" since it support function overloading.
This style of writing main is been deprecated long ago. But people still use it like they still use void main instead of int main though we have told them zillion times not to do so.


Read http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.4

siddhant3s 1,429 Practically a Posting Shark

Who will put the parenthesis, while calling a member function?
Change line 43 and 44 to

a1.exp1();
x1.exp2();

siddhant3s 1,429 Practically a Posting Shark

Read this if you are using a crap like Turbo C.

siddhant3s 1,429 Practically a Posting Shark

Did you ever thought of doing your work yourself?
Simply stating "I want this" do not work.
At least put an effort and then ask for help.
Read http://www.daniweb.com/forums/thread202628.html or this.

Hint: use recursive functions.

siddhant3s 1,429 Practically a Posting Shark

Don't keep bumping on your thread.
No one is free enough to help you if you don't show effort.
I have see many thread started by you stating "How do I do this" without any efforts.

Learn to ask question the smart way : Read this page http://www.catb.org/~esr/faqs/smart-questions.html

Also, read the guidelines mentioned on this thread http://www.daniweb.com/forums/thread202628.html

siddhant3s 1,429 Practically a Posting Shark

BTW, 100! is

93326215443944152681699238856266700490715968264381621468592963
89521759999322991560894146397615651828625369792082722375825118
5210916864000000000000000000000000

There is no fundamental integral datatype in C++ which can store this.

@Vernon
Good catch.

siddhant3s 1,429 Practically a Posting Shark

Everything is fine except that both of you missed an important point:
private members are not inherited.

And if you know or not, the default access code of a class is private.
Hence the
int a,b,c; in post#1 and the
void SayHello() in post#2 are declared as private.

They cannot be inherited.
Use the protected: access qualifier instead.

This is the corrected version:

#include<iostream>
using std::cout;using std::cin;
class abc
{
        protected: //added a inheritable access specifier
         int a,b,c;
          
         public:
                    void exp1();
};

class xyz: public abc
{
           public:
                     void exp2();
};

void abc::exp1()
{
             cout<<"Enter Value of a= ";
             cin>>a;
             cout<<"Enter Value of b= ";
             cin>>b;
             cout<<"Enter Value of c= ";
             cin>>c;
}

void xyz::exp2() //changed
{
             cout<<"a= "<<a;
             cout<<"b= "<<b;
             cout<<"c= "<<c;
}

int main()
{
          //   clrscr();
             abc a1;
             xyz x1;
             a1.exp1();//added parenthesis in function name
             x1.exp2();//added parenthesis in function name
}

To the OP:
Your code is very rusted. You are using all those deprecated header files, using void main, using getch(). All these are 'crimes' in C++. Please read this guide to migrate to standard C++ It is perhaps because your teacher told you like this. If you are a school goings student, you may write rusted code in school but practice the standard code otherwise.
If you think Daniweb helped you, please help us by using standard C++ and not the crappy turbo C++ accepted C++. Leave Turbo C++ like compilers which are two decades …

Ancient Dragon commented: Yes, I should have known better :) +36
siddhant3s 1,429 Practically a Posting Shark

Understand what exactly #include<header.h> does:
It simply copy-paste the content of header.txt and replaces it with the line containing #include<header.h>
Say, if you have a header.h with the following :

+--header.h---------------------------------+
+-------------------------------------------+
|   Sticks and Stones can break my bones.   |
|   But they can't break my soul.           |
|___________________________________________|

and now let the following file #include the above file:

+--myfile.cpp-------------------------------+
+-------------------------------------------+
|   The content of the file is:             |
|   #include "header.h"                     |
|___________________________________________|

The preprocessor will automatically output the following into the compiler:

+--myfile.cpp---after being fed into preprocessor---+
+---------------------------------------------------+
|   The content of the file is:                     |
|   Sticks and Stones can break my bones.           |
|   But they can't break my soul.                   |
|___________________________________________________|

If you are using g++ and have facility of grep, you can use the following commands to see the output of the preprocessor

$: g++ myfile.cpp -E | grep -v "#"

note that ``$:" is the prompt character of my shell.
Remember that the above examples are not valid C++ program and hence they cannot be fed into a compiler without producing errors.

When you write a header file or a library (say, a class), you usually divide it into two files:
1. First file containing the declarations (or as many people says, containing the `interface') of your class. This file is conventionally is suffixed by the `.h' header extention. This file is #included in your main cpp file, say `main.cpp'

2. And …

Salem commented: Excellent post, truly excellent. +36
Nick Evan commented: I agree... You've got too much free time :) +21
tux4life commented: Maybe not posting much (in you signature), but when your post, the result is always of high quality :) +13
siddhant3s 1,429 Practically a Posting Shark

Oh jazzman please. Stop posting rusted C++ code.
Read this http://siddhant3s.googlepages.com/how_to_tell_rusted_cpp.html to migrate to standard C++

siddhant3s 1,429 Practically a Posting Shark

file.write() methods write unformatted characters to the file.
That is, it do not work like a print statement.
When you issue a print statement, a new line is automatically appended. This is not the case with write().
write() performs as-is writing.

You could redirect your stdout to a file and then use the normal print statement to print formated text. http://stefaanlippens.net/redirect_python_print
Else, you could just add a space before writing to the file:

test = open("Hello World.txt", "a")
test.write(" hello world!")
siddhant3s 1,429 Practically a Posting Shark

Guidelines to OPs:
Before you start a thread:

Starting a thread is a critical task. It is so because it demands time and attention of other forum members. A thread should only be started when you have done enough drill to find your answer else where.
You should always be searching the answer with a help of a search engine (like Google) before you attempt to start a new thread. It is very unlikely that you won't find answers on the web. If you have not researched about a topic before hand, it is quite probable to get very uninviting response such as RTFM or STFW [1].
Sometimes, a search engine such as Google may not cache pages accurately and hence you should not hesitate to use the Site Search feature.

If the problem is actually a homework, you should honestly make an attempt first. Simply restating the question and demanding help just won't do.

Starting a thread:

Only after you are sure that you have rigorously and religiously searched the web and other resources, you should start a thread.
A thread should hold a meaningful title. Use of titles like "Help Me", "Urgent", "Homework Due" or perhaps, "Can you help me?" will tend to repel good respondent from your thread. Always create concise and meaningful titles like "Help regarding IPC mechanisms" or "Creating a standalone exe".

Describing the Problem:

Remember that, a nicely plotted problem will let other understand it …

jlm699 commented: Great post. Should be sticky/announcement... +5
tux4life commented: Excellent, indeed: they should replace their sticky thread by this thread :) +13
siddhant3s 1,429 Practically a Posting Shark

The std::vectors uses heap storage (dynamic memory management). When you declare an vector, vec1, all you do is instantiate a vector object. When you push_back elements in a vector, it automatically manages it and store it somewhere in the memory and stores pointers to those object with it. So now when you say sizeof(vec), you are actually getting the size of the vector object and not of the elements inside them.
Hence, size of vector is constant (which differs from implementation to implementation) no matter how many element you push.
You would never need to bother about those.

Even now, if you are not clear, consider the following class:

class myVector
{
    private:
    int* p;
    public:
    myVector(int size)
    {
        int* p= new int[size];
    }
};

Now, no matter if you print sizeof(myVector(100)) or sizeof(myVector(500), the system will print the same value.
Why? Because sizeof() will yeild sizeof(int*) that is the size of a pointer to int [1].

[1] This is actually not true in general. sizeof() operator will actually yield a value which would be at least the value of the sum of the size of all its member. It may yield more than that too, in case polymorphism is involved, but we can leave the details here.

Edit1: To jencas: Read my foot note above. sizeof can also yield a value more than the individual members.

Edit2: To mrinal.s2008: Regarding your second problem, g++ is correct. According the the ISO C++, …

siddhant3s 1,429 Practically a Posting Shark

In general, no. But you can wrap the clock() inside a class and simulate a reset method:

class Clock
{
    private:
        clock_t naught;
    public:
        Clock():naught(0){} //constructor
        void reset()
        {
            naught=clock();
        }
        clock_t operator()()
        {
            return clock()-naught;
        }
};
//demonstration:
int main()
{
    using std::cout;using std::endl;
    Clock stopwatch;
    while(stopwatch()<2 * CLOCKS_PER_SEC);   //wait for 2 seconds
    cout<<"Our Clock()"<<stopwatch()<<"\t\t";//print our Clock()
    cout<<"Standard Clock()"<<clock()<<endl; //print the standard clock()
    
    
    stopwatch.reset();
    cout<<"\tOur Clock Reseted....\n";
    
    
    while(stopwatch()<2 * CLOCKS_PER_SEC);   //wait again
    cout<<"Our Clock()"<<stopwatch()<<"\t\t";//print our Clock()
    cout<<"Standard Clock()"<<clock()<<endl; //print the standard clock()
}

This is more or less like post#5 but in an encapsulated way.

siddhant3s 1,429 Practically a Posting Shark

Epsilon test is a way to satisfy ourself to the incompetency of the computer system to process real numbers. It should be [can be] applied to every domain involving real numbers and real computer.
uVA Online Judge's website contains an excellent paper about Numerical Difficulties in Pre-University
Informatics Education and Competitions
which can be found on http://online-judge.uva.es/problemset/float-in-competition.pdf . Its a must read.
As far as your problem is concerned, ask the same old question to yourself, how much precision do you need?
I suggest you to code the epsilon test while you overload the operator== for your Vector.
One more thing: don't you think the Rotate function is too vague; shouldn't it take two arguments: the amount of rotation and about which axis should the rotation occur. In that case, Rotate should be Rotate(double m, Vector a) where m is the amount of rotation and a is the vector axis about which the rotation should occur.

siddhant3s 1,429 Practically a Posting Shark

>>Don't you love newbie questions??
Yes but not the trivial ones. Your question is quite trivial to even look at.
There were enough resources available only if you would STFW.
You wasted my minute to even look at your question.
You either enjoy sadistic pleasure or you are too lazy.
Whatever: you need a reading to this page.

Salem commented: ***applause!!!*** +36