The Incredible
Ambassador of Buzz
mohit sharma said:well ' LET US C++ ' by yaswant kanitkar
Let me know abt da publisher.
Anindya
mohit sharma said:well ' LET US C++ ' by yaswant kanitkar
Quadratic eqn program#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float p,r,n,ci,amount;
cout<<"\nEnter principal:";
cin>>p;
cout<<"\nEnter rate:";
cin>>r;
cout<<"\nEnter time:";
cin>>n;
amount=p*pow((1+(r/100)),n);
ci=amount-p;
cout<<"\nThe compound interest is: "<<ci;
getch();
}
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float a,b,c,d,sqrtd,r1,r2;
cout<<"\nEnter values of a,b,and c for equation ax^2+bx+c:";
cin>>a>>b>>c;
d=(b*b)-(4*a*c);
sqrtd=sqrt(d);
r1=(-b+sqrtd)/(2*a);
r2=(-b-sqrtd)/(2*a);
cout<<"\nThe roots are: "<<r1<<","<<r2;
getch();
}
*www.cprogramming.com/tutorial.html
Lesson 1
#include <iostream>
using namespace std;
int main()
{
cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
cin.get();
}
#include <iostream>
using namespace std;
int main()
{
cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
cin.get();
return 1;
}
Here are some variable declaration examples:
int x;
int a, b, c, d;
char letter;
float the_float;
Here is a sample program demonstrating the use a a variable:
#include <iostream>
using namespace std;
int main()
{
int thisisanumber;
cout<<"Please enter a number: ";
cin>> thisisanumber;
cin.ignore();
cout<<"You entered: "<< thisisanumber <<"\n";
cin.get();
}
Here are a few examples:
a = 4 * 6; // (Note use of comments and of semicolon) a is 24
a = a + 5; // a equals the original value of a with five added to it
a == 5 // Does NOT assign five to a. Rather, it checks to see if a equals 5
For example:
a < 5 // Checks to see if a is less than five
a > 5 // Checks to see if a is greater than five
a == 5 // Checks to see if a equals five, for good measure
Lesson 2: If statements
Here are the relational operators, as they are known, along with examples:
> greater than 5 > 4 is TRUE
< less than 4 < 5 is TRUE
>= greater than or equal 4 >= 4 is TRUE
<= less than or equal 3 <= 4 is TRUE
== equal to 5 == 5 is TRUE
!= not equal to 5 != 4 is TRUE
The structure of an if statement is as follows:
if ( TRUE )
Execute the next statement
For example:
if ( TRUE ) {
Execute all statements inside the braces
}
if ( TRUE ) {
// Execute these statements if TRUE
}
else {
// Execute these statements if FALSE
}
#include <iostream>
using namespace std;
int main() // Most important part of the program!
{
int age; // Need a variable...
cout<<"Please input your age: "; // Asks for age
cin>> age; // The input is put in age
cin.ignore(); // Throw away enter
if ( age < 100 ) { // If the age is less than 100
cout<<"You are pretty young!\n"; // Just to show you it works...
}
else if ( age == 100 ) { // I use else just to show an example
cout<<"You are old\n"; // Just to show you it works...
}
else {
cout<<"You are really old\n"; // Executed if no other statement is
}
cin.get();
}
A. !( 1 || 0 ) ANSWER: 0
B. !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR)
C. !( ( 1 || 0 ) && 0 ) ANSWER: 1 (Parenthesis are useful)
Lesson 3: Loops
for ( variable initialization; condition; variable update ) {
Code to execute while the condition is true
}
Example:
#include <iostream>
using namespace std; // So the program can see cout and endl
int main()
{
// The loop goes while x < 10, and x increases by one every loop
for ( int x = 0; x < 10; x++ ) {
// Keep in mind that the loop condition checks
// the conditional statement before it loops again.
// consequently, when x equals 10 the loop breaks.
// x is updated before the condition is checked.
cout<< x <<endl;
}
cin.get();
}
while ( condition ) { Code to execute while the condition is true }
Example:
#include <iostream>
using namespace std; // So we can see cout and endl
int main()
{
int x = 0; // Don't forget to declare variables
while ( x < 10 ) { // While x is less than 10
cout<< x <<endl;
x++; // Update x so the condition can be met eventually
}
cin.get();
}
do {
} while ( condition );
Example:
#include <iostream>
using namespace std;
int main()
{
int x;
x = 0;
do {
// "Hello, world!" is printed at least one time
// even though the condition is false
cout<<"Hello, world!\n";
} while ( x != 0 );
cin.get();
}
Lesson 4: Functions
For example:
#include <cstdlib> // Include rand()
using namespace std; // Make rand() visible
int a = rand(); // rand is a standard function that all compilers have
The general format for a prototype is simple:
return-type function_name ( arg_type arg1, ..., arg_type argN );
int mult ( int x, int y );
Lets look at an example program:
#include <iostream>
using namespace std;
int mult ( int x, int y );
int main()
{
int x;
int y;
cout<<"Please input two numbers to be multiplied: ";
cin>> x >> y;
cin.ignore();
cout<<"The product of your two numbers is "<< mult ( x, y ) <<"\n";
cin.get();
}
int mult ( int x, int y )
{
return x * y;
}
cout<<"The product of your two numbers is "<< x * y <<"\n";
Lesson 5: switch case
switch ( <variable> ) {
case this-value:
Code to execute if <variable> == this-value
break;
case that-value:
Code to execute if <variable> == that-value
break;
...
default:
Code to execute if <variable> does not equal the value following any of the cases
break;
}
int a = 10;
int b = 10;
int c = 20;
switch ( a ) {
case b:
// Code
break;
case c:
// Code
break;
default:
// Code
break;
}
#include <iostream>
using namespace std;
void playgame();
void loadgame();
void playmultiplayer();
int main()
{
int input;
cout<<"1. Play game\n";
cout<<"2. Load game\n";
cout<<"3. Play multiplayer\n";
cout<<"4. Exit\n";
cout<<"Selection: ";
cin>> input;
switch ( input ) {
case 1: // Note the colon, not a semicolon
playgame();
break;
case 2: // Note the colon, not a semicolon
loadgame();
break;
case 3: // Note the colon, not a semicolon
playmultiplayer();
break;
case 4: // Note the colon, not a semicolon
cout<<"Thank you for playing!\n";
break;
default: // Note the colon, not a semicolon
cout<<"Error, bad input, quitting\n";
break;
}
cin.get();
}
ashu888ashu888 said:Hey Mach bro ! Mr.Incredible already said tat he didnt get any help from the site that u mentioned..
The Incredible said:C'mon Guys!
i'm not having time to read da buks n uderstand da logics.
i've already mentioned that my compu exams r on 30th.
man do u all want that i shud only concentrate on comp. man this is cbse board i hav other subjects too. this yr only joined this school.
n abt gaining knowledge let me tel u there's a institute around 2 km from my house for learning programming languages such as BASIC C++ COBOL and JAVA. but currently i'm not having time to read n understand them. from 20th my exams r beginning.
also, in case of reading e-buks electricity needs to b there. if u don't trust just join my city nthemn u'll cum to know da condition of electricity.
my ups remains only upto 5 min.
i don't hav any inverter nor generator.
plz let me solve these progs now.
if i ever ask again after my exams like then i requests da administrator to ban me.
PS: If any 1 having code plz provide me.
Anindya
Mr.Incredible said this mach broHi ashu bro..
i havnt yet mentioned a site be4 i posted the tutz.. and i also dont see where mr incredible say he didnt find it useful
Look at the starting page of this thread buddy..neways i completely agree that we all r saying our point..BTW i've tried cprogramming.com provided by digit in three incredibly useful sites sectiond but didn't found anything helpful.