siddhant3s 1,429 Practically a Posting Shark

Yes, I tried that, it works fine.
Here is the code that I used:

#include <iostream>
using namespace std;
int main()
{
    int month,day,year,date;
    cout<<"Enter a date:";
    cin>>date;
    month = date / 1000000;
    day = (date % 1000000)/10000;
    year = date % 10000;

    cout<<"Date Entered:"<<date<<endl
    <<"Month:"<<month<<endl
    <<"Day:"<<day<<endl
    <<"Year:"<<year<<endl;
}

And this was the interaction at the terminal:

siddhant3s@x10n:~$ ./test
Enter a date:03081991
Date Entered:3081991
Month:3
Day:8
Year:1991
siddhant3s@x10n:~$
siddhant3s 1,429 Practically a Posting Shark

The above post (#10) contains a fairly `nice' code. Though it, too is looping unnecessarily throughout the whole array. Stepping out of the loop once we know that the current character is null '\0' will be better: (modifying the above code)

#include <iostream>
#include <iomanip>  // <- because of setw()
using namespace std;

int main()
{
  // The size of the array, note: 'const'
  const int array_size = 30;

  int count = 0;

  // !! Attention !!
  // Initialize the whole array to '\0'
  char str[array_size] = "";

  cout << "enter a word: " << endl;

  // Safely get the input, no fear of buffer overflow
  cin >> setw(array_size) >> str;

  for (int x = 0; x < array_size; x++)
    if(str[x])
    {
      count++;
    }
    else break;


  cout << count;

  return 0;
}

This code can however be shortened considerably which would eliminate the need of many redundant variables. Here is a possibility:

#include <iostream>
#include <iomanip>  // <- because of setw()
using namespace std;
int main()
{
  // The size of the array, note: 'const'
  const int array_size = 30;
  char str[array_size];

  cout << "enter a word: " << endl;
  // Safely get the input, no fear of buffer overflow
  cin >> setw(array_size) >> str;

  int count;
  for (count = 0; str[count]; count++) ;

  cout << count;
}
kvprajapati commented: Helpful! +9
siddhant3s 1,429 Practically a Posting Shark

Any character in single quote has type of char.
Double quotes are used for string. They have type const char* that is pointer to char (whole values can't be changed).
So, "a" is actually an array of two elements : 'a' and '\0'

siddhant3s 1,429 Practically a Posting Shark

>it's working but the code is very complex to me
Do not know about the complex part, but the code is wrong, do not follow it.

caut_baia, you were wrong in two ways: first, you tried to give the OP a direct answer which can spoil his fun of `getting' towards the answer. It's not the answer which is important but it's the path to the answer which is.

Secondly, you failed to allocate any memory allocation to str, it is pointing to some random memory location and because you are cin-ing to that location, you are invoking undefined behaviour. Please allocate enough memory to str before using it.

I think the no one understood the point that Ancient_Dragon wanted to make about the 50 character limit. He wanted the OP to consider the std::strings. They will make the program flexible to accept any length long input string.

Ancient Dragon commented: Excellent comments +28
siddhant3s 1,429 Practically a Posting Shark

The easiest way, which is in fact the more elegant way to do things would be to declare a struct or class of a card. Create a vector of such 52 cards and use the standard library's random_shuffle() [http://www.cppreference.com/wiki/stl/algorithm/random_shuffle] to shuffle it.

siddhant3s 1,429 Practically a Posting Shark

>>little ugly
Is it?
This is the correct way to the thing what you want.
You create a class template when you want to separate the implementation of the whole class according to the template parameter. But here, this is not what you want to do.
In fact, you could templatize the class along with a different function template:

#include <iostream>

using namespace std;
template<typename C>
class A
{
public:
	A() { }
	template<typename T>
	void Print(T a) { cout<<a<<endl; }
};
int main()
{  
	A<int> t;
	t.Print(3.1415f); //implicitly
	t.Print<unsigned int>(100); //explicitly

	return 0;

}

Here we are using two templates: one for the whole class (with C as the parameter) and other for the particular function only.

StuXYZ commented: class+function templates together are too often overlooked. +6
siddhant3s 1,429 Practically a Posting Shark

>can u plz explain that when is the order of precedense will be right to left?
Are you deaf?
Look at the post #2 and try to accept that what ever niek has said is actually true.
Your program is suffering from undefined behaviour. All that means to you is that 'anything' can happen when you run the program.
There is a FAQ on Bjarne Stroustrup's FAQs(http://www.research.att.com/~bs/bs_faq2.html#evaluation-order) and also on Marshal Cline's FAQs(http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.15)

Try to read and understand them.
In simple term:
1. Sequence point is a point of time while executing your code at which all the variables have defined values.
2. Any operation done which alter the value of a variable more than once in between only a pair of consecutive sequence point leads to undefined behaviour.

No doubt, there are teachers who put forward these kinds of question trying to show off how tricky their questions are . Actually, all they are doing is teaching their student to depend on studying implementation specific behaviour.

Regarding, the use of void main, conio.h and clrscr(), read http://siddhant3s.elementfx.com/

kvprajapati commented: Great explanation. +17
siddhant3s 1,429 Practically a Posting Shark

>Got exam tomorrow
So you've been screwed.
Now did you remember when your instructor told you to read a text book?

>Anyone know that c program got wat type of error?
Yes.

tux4life commented: I've exams tomorrow, can you help me? :P +21
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

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

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

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

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

>>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
siddhant3s 1,429 Practically a Posting Shark

>On the downside: no more time for office-sword-fighting
This reminds me about the cover of the Dragon Book
[img]http://www.stewart.cs.sdsu.edu/cs524/spr08/bookCover_51XtGJ64tZL._SS500_.jpg[/img]

Nick Evan commented: Haha +19
siddhant3s 1,429 Practically a Posting Shark

VernonDozier, here is a sweet link : http://www.codecogs.com/components/equationeditor/equationeditor.php

@jephthah
I got the exact formula. But I thought if I could somehow get a closed term for that summation.
This formula will surely be O(sqrt(N)).
But hey, I think that there cannot be a closed form of this. (If it was, it must have been so obvious)

VernonDozier commented: Nice link +17
iamthwee commented: yes good link +21
siddhant3s 1,429 Practically a Posting Shark

Always use the size_t type for indexing a container, or for container size.
That means
-> instead of for ( int j = 0; j < item.length(); j++) use for (size_t j = 0; j < item.length(); j++) -> instead of

int size= 5;
int* x= new int[size];

use:

size_t size=5;
int* x= new int[size];

size_t is the alias name for a unsigned integer type depending on your platform.
size_t may be unsigned int or unsigned long etc.
Using size_t indicates that your code will be more portable,

tux4life commented: The actual thread solver! Including some valuable information in his post as well :) +10
siddhant3s 1,429 Practically a Posting Shark

Cheesey,
You sure need to have a reading on this page. It is written by one of the most profound hacker, Eric S Raymond : How to ask question the smart way.
Please go and read it first before attempting to seek any help.
I specially like to quote a paragraph :

Never assume you are entitled to an answer. You are not; you aren't, after all, paying for the service. You will earn an answer, if you earn it, by asking a substantial, interesting, and thought-provoking question — one that implicitly contributes to the experience of the community rather than merely passively demanding knowledge from others.

You do not have any excuse that you didn't knew about code-tags. Information about code-tag is posted all over the website :
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) Even on the background of the box you actually typed your message in

tux4life commented: Agreed! +9
Salem commented: Well said! +36
iamthwee commented: hi chicken, I think u need ta work on yer grammer, or if u r having problems get someone ta read over your work, especially if ur gonna post it on the internet! tnx +21
siddhant3s 1,429 Practically a Posting Shark

iamthwee@reputaion box of post#7>O! ALMIGHTY! Like ALBERT EINSTIEN, Make Me Bright, So that I am Able to Kill >Dark, And Make This World Full Of Light

So? What was your point? That was the ending verse of a poem I wrote when I was nearly 12. Sure it is the published at writing dot com if you go and search my name on google.
But what are you trying to convey? Just picking up my random posts and giving infractions. Is it not a means of harassing me?
Other day, I was discussing with a DaniWeb member about your behavior and I told him that you've improved, but I guess I was wrong.

If there was an option to give infraction on your comments on the reputation box, I (and perhaps more people around) would love to. Those comments are to be written so that the person you are giving infraction knows what he did wrong, not to quote random thoughts.
So please, get a life.

Salem commented: The "iamthwee is a douche" supporters club +35
siddhant3s 1,429 Practically a Posting Shark

Oh no please. Not Sams teach X in Y days. I hate it.
Read this : Teach Yourself Programming in Ten Years by Peter Norvig
. An excellent article to reply Sams

tux4life commented: Great link, I'm not a SAMS fan too :) +9
siddhant3s 1,429 Practically a Posting Shark

Okay. I had enough!
It had been 11 posts in this thread and I cannot belive no one told OP to use code tags.
To the OP, it doesn't mean you shouldn't be knowing about code-tags. You should be posting the code using code-tags. Information about code-tag is posted all over the website :
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) Even on the background of the box you actually typed your message in

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

>Please bear in mind that Daniweb is no remote compiler service or something
What a good idea. I have started to think to write one :-)
Bloody who will support the webhosting services :(

tux4life commented: You are really unbelievable ! First you write an excellent guide, now siddhant is designing a remote compiler service :P +9
WaltP commented: Nice idea, but it already exists... +20
siddhant3s 1,429 Practically a Posting Shark

So you have your home-made String class and want it to implicitly convert to C-string(a zero-terminated character array).
You would have to overload the operator char*()
Read http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=24
And always search the web before posting.

chaines51 commented: Thanks for the help! +1
siddhant3s 1,429 Practically a Posting Shark

Oh please. Micro-optimization is not cool. Adhere to the philosophy that "Developers time is far far more important than machine time"
Small optimization won't make significant changes in the execution but will drastically increase your head ache.
I find Salem post to be extremely right in this regard. Very well said.
My advice is : use the one which will save you headache while debugging a month( or perhaps a fortnight) later.


>if it's around 10 minutes, then a few minutes either way won't get them back
>from the coffee break any time sooner.
I can have two cups in those 10 minutes. :)

Salem commented: Yes, a wasted week of every users' time changes the calculation a hell of a lot! +35
siddhant3s 1,429 Practically a Posting Shark
Sky Diploma commented: Thanks :) +3
siddhant3s 1,429 Practically a Posting Shark

>Better open this specifically in input mode mode as
He is doing fine: he declared the object of ifstream hence it is fine not to mention ios::in

To OP:
a. You coding is what use to be 15 years ago. I think it is time to change. Read this.
If your school forces you to use iostream.h and other deprecated coding style, you can do what they want in school but practice standard coding otherwise.
b. You should be posting the code using code-tags. Information about code-tag is posted all over the website :
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) Even on the background of the box you actually typed your message in
So don't tell us that "you didn't knew about code-tags"

c. Please read How to ask questions the smart way and learn that it is yourproblem that you have to submit the assignment till 18th, not ours.

Salem commented: Lots of good points +35
siddhant3s 1,429 Practically a Posting Shark

>thanks brother for your knowledge
Thank him for his experience:)

csurfer commented: Ya his experience !!! Well said !!! +2
siddhant3s 1,429 Practically a Posting Shark

Okay, You know what is function overloading in C++, do you?
Lets say you create a function named int greater(int a, int b) which returns the greater of the two integer of either a and b.
You define it as

int greater(int a, int b)
{ if( a> b) return a;
  return b;
}

Now you feel that you also need a function which can check which of the two floats are greater. So you again write another greater() function, this time for float:

float greater(float a, float b)
{ if( a> b) return a;
  return b;
}

Note that this function is exactly similar to the previous one except that it works on float.
Also note that the compiler will automatically call the appropriate function, no matter if you passed two ints as the parameter or two floats. Compiler knows which one to call.
The story doesn't ends here, now you decide that you should perhaps write a similar function for doubles:

double greater(double a, double b)
{ if( a> b) return a;
  return b;
}

So now, you had to write 3 different functions each time for different data types.
The things get worst when you use custom classes since now, you have to write a function greater for them too.

The solution are templates. In this technique (sorry for using such a term, it is not really a technique) you tell the compiler itself to write functions for …

tux4life commented: Always superb explanations :) +9
siddhant3s 1,429 Practically a Posting Shark

I was to be with adatapost if he would have added a line such as ``This is what you want but please stop using a pre-historic compiler".

The fact is that the graphic.h header file won't never give OP, the curses look. The only thing it will do is to make the code Huge and un-tangible ( of course making it unportable too). Do think we should create our own rectangles and squares to create windows and buttons?

I know this character here which mostly posts Turbo C++ compatible code. I don't care what you do when you are with you: use turbo C ++ or any other older non standard compiler. But when you are in a community, please (at least try to) obey standards.

The point I want to highlight is ( which has now become difficult to prove) that the suggestion of graphic.h was not given after reading the OP's "I am on turbo C++" but was to be the default answer by him anyways (I told you it is difficult to prove this now.) Furthermore, the use of graphic.h won't do any good on Turbo C++ either.

I know the Green rep to him (after 3 red one) must be a matter of sympathy. If it was not, there was no need to neutralize the red dot.

> Then stop replying posts you have no intention of of adding constructive responses to!
>Adatapost, you do not have to use a …

tux4life commented: There you've got a good point :) You're just the kind of person we need on this forum. +8
jephthah commented: thanks +10
siddhant3s 1,429 Practically a Posting Shark

>As C++ developer - stop finding ready-made code or solution otherwise you will
>mess up your work.
"Good programmers know what to write. Great ones know what to rewrite (and reuse)."
He is not looking for "homework helps". He is trying to exercise what is one of the well known good programming methodology "Code reuse".

To OP:
boost::asio is perhaps the most standard way to implement sockets. It is cross-platform and obviously free. Boost also have many library for IPC methods. Try to find them and use them. Boost libraries are the most expertly designed .

iamthwee commented: yep, gotta love the boost libraries. +21
siddhant3s 1,429 Practically a Posting Shark

Try not to confuse people. Those who knows python does not necessarily know bash. The same way you know bash but do not know python.
BTW, here is your code:

s="dani_web_needs_better_OP"
print s.split("_")[1]

One more advice, try to read a book. These things are covered in the introductory chapters.

scru commented: yes +6
siddhant3s 1,429 Practically a Posting Shark

I won't have to.
When you create an object of class C, both get_a, get_b will be available for calling.
If however, both function was named get(), then it would cause ambiguity.

class A
{
	protected:
		int no;

	public:
		void get(void)
		{
		cout<<"Class";
		}

};
class B
{
	protected:
		int no1;
	public:
		void get_a(void)
		{

		cout<<"Class";
		}

};
class C : public A,B
{
	private:
		int no;


};

//inside main
C c;
c.get() //error. which get()?
c.A::get() //oh, so you mean A' get. No problem
Nick Evan commented: Signing off for today, so here's a wave goodbye. See you in a year! +18
siddhant3s 1,429 Practically a Posting Shark

>i am usin turbo C in window XP
I am sorry, your code is rusted. That is not a surprise since you are using such a crappy compiler.
I have written a guide to help people like you in long run. Although it is not complete, but it will serve you good. Read it at:
http://siddhant3s.googlepages.com/how_to_tell_rusted_cpp.html

Ancient Dragon commented: ++ link to excellent blog :) +36
Salem commented: Nice link, but Stroustrup needs better spelling in several places. +33
tux4life commented: There was need to something like this +8
siddhant3s 1,429 Practically a Posting Shark

Take a paper, take a pen.
Scribble something until it makes sense.
Posting without trying is not wise,
It just show your ignorance.

Although we are here to solve your queries,
We, can't work until we have some berries.
Those berries are your tries,
So, don't post before attempting, it makes us cry.

One more thing I tell you my friend,
There is a page by Eric S Raymond.
Which you should read, here we pray,
and that page is "How to ask question the Smart way"
(Applause)
Thank You. Thank You.

This is revenge: you irritate me with your post and I irritate you with my poetry.

tux4life commented: Nice poetry :P +8
siddhant3s 1,429 Practically a Posting Shark

Now this is an interesting case of ignorance.
But first, I must give OP the answer:
Look at the definition of atoi. It wants a cstring. Which is a null-terminated character array. Tell me, are you giving it a null terminated character array? No you aren't. You are giving him just a pointer to char. The output would be machine dependent. It was just your luck that the address just next to q and a have the value zero in your memory. So change your program as this:

#include<iostream>
#include<cstdlib>//<stdio.h> for old compiler
#include<cstring>//<string.h> for old compiler
using namespace std; //remove this line for old compiler
int main()
{
char a[5],q[5];//this will support only upto 4 digits
cout<<"Enter a char\n";
cin>>a;
strcpy(q,a);
cout<<atoi(a)<<",";
cout<<atoi(q);
return 0;
}

---------------------------------------------------------
Now. The funny part. I was pretty much sure that Ancient got the output correct because his complier had laid the memory in a different way. While the OP's Compiler used heap storage, q had a greater address than a (greater means had more value). Hence, when OP said cout<<atoi(&a), he got the output 2 (if the input was 2, say) because the next block of memory had zero value. But when he said cout<<atoi(&q), he got the value 22 because the next block was not zero but had the value 2 ( this block was the variable a itself). The memory representation was like this:

.
.
q:   |  2  |  <-- 0x000015 
a:   |  2 …
Ancient Dragon commented: Great explanaton :) +36
tux4life commented: Agreed with Ancient Dragon :) +7
siddhant3s 1,429 Practically a Posting Shark

>>EDIT: ALSO USE CODE-TAGS
You can use the noparse tag to tell him that. Use them like this

[noparse] every thing you write here will not be parsed even the [code] [/code] tags [/noparse]

Sky Diploma commented: Thanks :) +3
siddhant3s 1,429 Practically a Posting Shark

>USE AN ARRAY!
One of the baddest advice that can be given to a beginner.
Don't you know that arrays are evil?
>efficiency before sophistication.
Err. The better way to saying is : 'Clarity before efficiency".
As Donald Knuth puts up very beautifully:"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."

Besides, you should ``show" the user the ``path" rather than showing him just the direction-posts.

Ancient Dragon commented: Excellent :) +36
tux4life commented: Excellent! +7
siddhant3s 1,429 Practically a Posting Shark

Wow, I really like kid playing with men's tools.
So you want to become a cracker?
Good Good.
Didn't your mother told you that cracking isn't sexy?
In my advice, be a hacker. Read : How to become a Hacker

Salem commented: Nice link +32
siddhant3s 1,429 Practically a Posting Shark

Now I have really got mad upon iamthwee. What was the cause of infraction for my post #4. Just because I gave an infraction to him, he gave me an infraction. Isn't it kiddish?
iamthwee, I was not spoon feeding, but you were. It is noway to behave in this forum.
I will surely get to some moderator about your 'spoon feeding' behavior.
One thing is that a man makes a mistake. The second thing that he doesn't realize it. The worst thing is that he don't want to.

You are really having some superiority complex. As you keep showing it with your pathetic coding style. Now who would have been though that a simple procedural problem would have included OOP?

The worst part is that you are featured poster. Does Daniweb has no criteria to give that tittle?

I don't want keep this thread dirty. Any agreement or disagreement from anyone else iamthwee are subjected to the reputation counter of this post. Any further discussion should be directed to my PM box with the reference of this thread.

Thank You

tux4life commented: I agree :) +6
siddhant3s 1,429 Practically a Posting Shark

>It serves the same purpose as endl

Not likely. There is a difference between std::endl and \n.
(To the OP: The following explanation may not suited for you. The answer of your question was well given in the posts above)
To understand lets see what happens you do a cout.
When you issue a std::cout statement, the data you passed is stored in the stream buffer and is displayed only when there is appropriate time and space to do so. Displaying the stream buffer on to the standard output is proceeded flushing the buffer stream(that is to empty the stream). Once the data has been sent to the standard output, the stream is automatically flushed. Alternatively, you can force a stream flush by using the .flush() member function.

'\n' is a escape sequence but std::endl is a stream manipulator. When you issue a std::endl, it does two jobs

  • Prints a new line and
  • Forces the stream to standard output and flushes the stream.

Hence, when you use std::endl, you are sure that it would print the result to the output device immediately.

amrith92 commented: Great Info... :) +1
tux4life commented: Right! +6
siddhant3s 1,429 Practically a Posting Shark

Tux, you should also tell him to place the conditional compilation preprocesor directive so that his files are not included more than once:

#ifdef MYHEADER_H
#define MYHEADER_H
//content of the files
#endif

This will make sure that this header file will be included only once even if you issue two #include directive.

tux4life commented: Right, I forgot :P +5
siddhant3s 1,429 Practically a Posting Shark

Implementation looks pretty fine. Post the declaration too.
BTW, the declaration should be

class student{
public:
        student();
        ~student();
        //other stuff
}
siddhant3s 1,429 Practically a Posting Shark

To the OP: Please read Why shouldn't you use an old compiler and What should main() return


>>BTW, your code is in C, though it's valid C++ code the C++ way of I/O is
>>preferred over the I/O from stdio.h
May be not. As you already said the OP is using void as the return value of main; this makes it a invalid C and C++ code.

>>Sorry siddhantes I didn't see your post
I don't mind as long as you spell my name right :)

tux4life commented: How do I spell your name right? +4
siddhant3s 1,429 Practically a Posting Shark

>>.i will user ur code as a reference code and will write my own code after
>>undertanding it
You know, first I thought I should believe your on this. But then my 6th sense told me not to. I am sorry.

tux4life commented: LOL, He'll use it as a "reference", where he copies all the code from I believe :P +4
siddhant3s 1,429 Practically a Posting Shark

Yeah, Yeah thats true.
because arr[0] is read as *(arr+0) which will change the value of the memory pointed by arr+0 directly.

Good.

NathanOliver commented: you have cleared up arrays for me thanks +1
siddhant3s 1,429 Practically a Posting Shark

The God has sent me to say "C++ compiler is not a pocket calculator."

tux4life commented: ROFL :P +4