yup, you are correct, they do not encourage to code...and their motive is mainly to teach students how to use syntax of the language...It does not encourage to code imo. Same with all indian authored books including "Let Us C".
I strongly advice beginners to stay away from these as there are better materials and books out there.
"Head First C" is the best example.
yup, you are correct, they do not encourage to code...and their motive is mainly to teach students how to use syntax of the language...
however i feel that indian authors are more relevant for most of the students.. you see the level of english they use for explaining is kinda tough for most of the indian students while the indian authors write in plain english only few students can understand foreign authors easily or else they are very elaborate and most of the students don't have time for that much research ...this is the case for many books like physics/chem/electronics etc.
BTW have you read "C++ object oriented programming by debasis jana"... i am currently reading it along with "thinking in C++"... its a good read although a bit technical approach has been followed in former one...
ok...
thanks for help.
ordered head first C from flipkart...
yes!!
& which IDE should I use?
dev c++ or code blocks or any other?
In our college, they still use TC but it's not supported in my windows 8 and also it is very old.
which should i use?
& if i use notepad++, then how to compile & run c program?
TC is vintage.....code::blocks is the best one out there and i use it myself... In fact my college now recommend code::blocks due to excessive lobbying by me ... actually they used devC++ and i literally forced them to move out of that though devc++ is fine enough for semester exams.yes!!
& which IDE should I use?
dev c++ or code blocks or any other?
In our college, they still use TC but it's not supported in my windows 8 and also it is very old.
which should i use?
& if i use notepad++, then how to compile & run c program?
can someone please explain me operator overloading with a simple program...i mean explain the program too as how it is working...
#include <iostream>
class a
{...}; //skipping the class definition
class b
{...}; //skipping the class definition
int main()
{
a obj1;
b obj2;
cout << obj1 + obj2;
return 0;
}
#include <iostream>
class a
{public:
int num;
friend int operator +(b obj2);
};
class b
{public:
int num;
};
int operator +(b obj2
{
return (this.num + obj.num);
}
int main()
{
a obj1;
b obj2;
cout << obj1 + obj2;
return 0;
}
thanx.Do you understand the concept of function overloading? Operator overloading is similar to that, but with a few constraints:
> You cannot define new operators.
> You cannot change the precedence and priority of operators.
> You cannot change the arity of operators.
Just like a function call, a reference to the object which invokes the operator is implicitelly passed to the operator bosy. This reference is called the 'this' operator and it can be used to access the object which invoked the operator.
this will return an error because no definitation of the plus operator is defined for class a and class b;
Code:#include <iostream> class a {...}; //skipping the class definition class b {...}; //skipping the class definition int main() { a obj1; b obj2; cout << obj1 + obj2; return 0; }
Code with overloaded operator
Code:#include <iostream> class a {public: int num; friend int operator +(b obj2); }; class b {public: int num; }; int operator +(b obj2 { return (this.num + obj.num); } int main() { a obj1; b obj2; cout << obj1 + obj2; return 0; }
Here, 'a' is invoking the 'operator +'. However, the if I wrode b+a instead of a+b, it would still crash as it would be 'b''s responsibility to invoke the + operator, but no definition of + exists for class b.
#include <stdio.h>
int main()
{
char C [3][3];
int C1[3][3];
int i, j; int m[8];int n=0; int k=0;
int trigger=0;
void check()
{
for(i=0;i<9;i++)
{
m[i]=0;
}
for(i=0;i<3;i++)//ACROSS ADD
{
for(j=0;j<3;j++)
{
m[i]=m[i]+C1[i][j];
}
}
for(i=0;i<3;i++)//DOWN ADD
{
for(j=0;j<3;j++)
{
m[i+3]=m[i+3]+C1[j][i];
}
}
//DIAGONALS ADD
m[6]=C1[0][0]+C1[1][1]+C1[2][2];
m[7]=C1[0][2]+C1[1][1]+C1[2][0];
for(i=0;i<8;i++)
{
if(m[i]==3)
{trigger=1;
}
if(m[i]==6)
{trigger=2;
}
}
}
void display()
{
printf("\nState of Game:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%c ",C[i][j]);
}
printf("\n");
}
}
printf("Welcome to my Tic Tac Toe game\n");
while(k<9)
{ if(n%2==0)
{
printf("\nPlayer 1 Input : X at desired index location");
printf("\ni:");
scanf("%d",&i);
printf("\nj:");
scanf("%d",&j);
C[i][j]='X';
C1[i][j]=1;
//CHECK
display();
check();
n++;
if(trigger==1)
{
printf("Player 1 wins");
break;
}
}
if(n%2==1)
{
printf("\nPlayer 2 Input : X at desired index location");
printf("\ni:");
scanf("%d",&i);
printf("\nj:");
scanf("%d",&j);
C[i][j]='O';
C1[i][j]=2;
//CHECK
display();
check();
n++;
if(trigger==2)
{ printf("Player 2 wins");
break;
}
}
k++;
}
return(0);
}