I presume that Pramod was being sarcastic here, and threw in a
number of errors intentionally, since we aren't here to do
people's homework for them.
I didn't have conio on my system (should I?)
No. It's not standard, and I don't know of any system which has
it. (Windows usually still has a <conio.h>, which is, however,
mainly there for historical reasons---it was an MS-DOS standard
header.)
IMHO you should probably should make this lower case for ease
of typing, i.e. ob_marks
There are two widespread conventions: separating names using an
_, and mixed case, e.g.: ob_marks, or obMarks. However, the
homework requirements said that the name must be Ob_marks.
(It's rather unusual to find a convention in which a variable
name starts with an upper case, too.)
there are 2 constructors defined here - that maybe legal, I leave that
to others more knowledgeable than me, but it would not compile on my
system. Also you should define the default values here - see below.
There is only one constructor declared here. The first is not a
constructor (case is significant in C++), but a function
declaration, and it is missing the return type.
The actual constructor is, shall we say, "interesting". To call
it, you need a variable of type char---an array will not work,
it must be a single variable.
missing semi-colon
Typo here - C++ is case sensitive. You are trying to use student (lower
case 's') when you defined Student (upper case 'S'). Anyways, this whole
block should be done away with
not needed, use sizeof(name)
Not at all the same thing! name is an uninitialized pointer.
sizeof(name) gives defined behavior, returning the size of a
pointer on his system (usually 4 or 8, today). Calling strlen
with an uninitialized pointer causes undefined behavior. A lot
more fun to throw at a learner who is too lazy to even try to do
his own homework.
name=new char[len+1];
ob_marks=0;
doesn't match the Ob_marks defined earlier (case sensitive)
Student::Student(string n, int om)
It's generally more common practice to pass strings by
reference, i.e.:
Student::Student( string const& n, int om )
See above for my comment on the constructor's signature.
{
int len=strlen(n);
name=new char[len+1];
strcpy(name,n);
Ob_marks=om;
}
just about this whole block should be re-worked
Actually, it's about the only thing that's correct in the entire
program. Or would be correct, if the signature were the
expected:
Student::Student( char const* n, int om )
Of course, in well written code, the members would be
initialized in an initializer list, and not in the body of the
constructor.
case sensitive
total_marks? you mean otal_marks? (as defined above), otherwise
total_marks was never defined.
That's part of the fun of it, no?
no semi-colon goes here - remove it
have to use std:: for cout and endl since you didn't declare your
namespace earlier
Now here is a working version (at least on my system):
I think the point was not to provide a working version.