Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
BATRA COMPUTER CENTRE
ISO CERTIFIED 9001:2008
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
 C is a programming language developed in the 1970's alongside
the UNIX operating system.
 C provides a comprehensive set of features for handling a wide
variety of applications, such as systems development and
scientific computation.
 C++ is an “extension” of the C language, in that most C
programs are also C++ programs.
 C++, as opposed to C, supports “object-oriented programming.”
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
// Program description
#include directives
int main()
{
constant declarations
variable declarations
executable statements
return 0;
}
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
 Keywords appear in blue in Visual C++.
 Each keyword has a predefined purpose in the language.
 Do not use keywords as variable and constant names!!
 The complete list of keywords is on page 673 of the
textbook.
 We shall cover the following keywords in this class:
bool, break, case, char, const, continue, do, default,
double, else, extern, false, float, for, if, int, long,
namespace, return, short, static, struct, switch, typedef,
true, unsigned, void, while
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
Peter: Hey Frank, I just learned how to add two numbers
together.
Frank: Cool!
Peter : Give me the first number.
Frank: 2.
Peter : Ok, and give me the second number.
Frank: 5.
Peter : Ok, here's the answer: 2 + 5 = 7.
Frank: Wow! You are amazing!
 after Frank says “2”, Peter has to keep this number in his mind.
 after Frank says “5”, Peter also needs to keep this number in his mind.
2 5 7First number: Second number: Sum:
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
The Corresponding C++ Program
#include <iostream>
using namespace std;
int main()
{
int first, second, sum;
cout << "Peter: Hey Frank, I just learned how to add”
<< “ two numbers together."<< endl;
cout << "Frank: Cool!" <<endl;
cout << "Peter: Give me the first number."<< endl;
cout << "Frank: ";
cin >> first;
cout << "Peter: Give me the second number."<< endl;
cout << "Frank: ";
cin >> second;
sum = first + second;
cout << "Peter: OK, here is the answer:";
cout << sum << endl;
cout << "Frank: Wow! You are amazing!" << endl;
return 0;
}
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
#include <iostream>
using namespace std;
int main()
{
int number_of_pods, peas_per_pod, total_peas;
cout << "Press return after entering a number.n";
cout << "Enter the number of pods:n";
cin >> number_of_pods;
cout << "Enter the number of peas in a pod:n";
cin >> peas_per_pod;
total_peas = number_of_pods * peas_per_pod;
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
cout << "If you have ";
cout << number_of_pods;
cout << " pea potsn";
cout << "and ";
cout << peas_per_pod;
cout << " pea in each pod, then n";
cout << "you have ";
cout << total_peas;
cout << " peas in all the pods.n";
return 0;
}
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
Identifiers appear in black in Visual C++.
 An identifier is a name for a variable, constant, function, etc.
 It consists of a letter followed by any sequence of letters,
digits, and underscores.
 Examples of valid identifiers: First_name, age, y2000, y2k
 Examples of invalid identifiers: 2000y
 Identifiers cannot have special characters in them. For
example: X=Y, J-20, ~Ricky,*Michael are invalid identifiers.
 Identifiers are case-sensitive. For example: Hello, hello,
WHOAMI, WhoAmI, whoami are unique identifiers.
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
• Comments appear in green in Visual C++.
• Comments are explanatory notes; they are ignored by the
compiler.
• There are two ways to include comments in a program:
// A double slash marks the start of a //single line
comment.
/* A slash followed by an asterisk marks the start of a
multiple line comment. It ends with an asterisk followed
by a slash. */
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
• Compiler directives appear in blue in Visual C++.
• The #include directive tells the compiler to include some already
existing C++ code in your program.
• The included file is then linked with the program.
• There are two forms of #include statements:
#include <iostream> //for pre-defined files
#include "my_lib.h" //for user-defined files
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
C++ is a free-format language, which means that:
• Extra blanks (spaces) or tabs before or after identifiers/operators
are ignored.
• Blank lines are ignored by the compiler just like comments.
• Code can be indented in any way.
• There can be more than one statement on a single line.
• A single statement can continue over several lines.
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
In order to improve the readability of your program, use the following
conventions:
• Start the program with a header that tells what the program does.
• Use meaningful variable names.
• Document each variable declaration with a comment telling what the
variable is used for.
• Place each executable statement on a single line.
• A segment of code is a sequence of executable statements that belong
together.
– Use blank lines to separate different segments of code.
– Document each segment of code with a comment telling what the
segment does.
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
• Writing Code without detailed analysis and
design
• Repeating trial and error without understanding
the problem
• Debugging the program line by line, statement by
statement
• Writing tricky and dirty programs
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com
ADDRESS:
SCO -15, Dayal Bagh,
Near Hanuman Mandir
Ambala Cantt-133001
Haryana
Ph. No.: 9729666670, 8222066670 &0171-4000670
Email ID: info.jatinbatra@gmail.com
Website: www.batracomputercentre.com
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: info.jatinbatra@gmail.com

C++ Programming Language Training in Ambala ! Batra Computer Centre

  • 1.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com BATRA COMPUTER CENTRE ISO CERTIFIED 9001:2008
  • 2.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com  C is a programming language developed in the 1970's alongside the UNIX operating system.  C provides a comprehensive set of features for handling a wide variety of applications, such as systems development and scientific computation.  C++ is an “extension” of the C language, in that most C programs are also C++ programs.  C++, as opposed to C, supports “object-oriented programming.”
  • 3.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com // Program description #include directives int main() { constant declarations variable declarations executable statements return 0; }
  • 4.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com  Keywords appear in blue in Visual C++.  Each keyword has a predefined purpose in the language.  Do not use keywords as variable and constant names!!  The complete list of keywords is on page 673 of the textbook.  We shall cover the following keywords in this class: bool, break, case, char, const, continue, do, default, double, else, extern, false, float, for, if, int, long, namespace, return, short, static, struct, switch, typedef, true, unsigned, void, while
  • 5.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com Peter: Hey Frank, I just learned how to add two numbers together. Frank: Cool! Peter : Give me the first number. Frank: 2. Peter : Ok, and give me the second number. Frank: 5. Peter : Ok, here's the answer: 2 + 5 = 7. Frank: Wow! You are amazing!  after Frank says “2”, Peter has to keep this number in his mind.  after Frank says “5”, Peter also needs to keep this number in his mind. 2 5 7First number: Second number: Sum:
  • 6.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com The Corresponding C++ Program #include <iostream> using namespace std; int main() { int first, second, sum; cout << "Peter: Hey Frank, I just learned how to add” << “ two numbers together."<< endl; cout << "Frank: Cool!" <<endl; cout << "Peter: Give me the first number."<< endl; cout << "Frank: "; cin >> first; cout << "Peter: Give me the second number."<< endl; cout << "Frank: "; cin >> second; sum = first + second; cout << "Peter: OK, here is the answer:"; cout << sum << endl; cout << "Frank: Wow! You are amazing!" << endl; return 0; }
  • 7.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com #include <iostream> using namespace std; int main() { int number_of_pods, peas_per_pod, total_peas; cout << "Press return after entering a number.n"; cout << "Enter the number of pods:n"; cin >> number_of_pods; cout << "Enter the number of peas in a pod:n"; cin >> peas_per_pod; total_peas = number_of_pods * peas_per_pod;
  • 8.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com cout << "If you have "; cout << number_of_pods; cout << " pea potsn"; cout << "and "; cout << peas_per_pod; cout << " pea in each pod, then n"; cout << "you have "; cout << total_peas; cout << " peas in all the pods.n"; return 0; }
  • 9.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com Identifiers appear in black in Visual C++.  An identifier is a name for a variable, constant, function, etc.  It consists of a letter followed by any sequence of letters, digits, and underscores.  Examples of valid identifiers: First_name, age, y2000, y2k  Examples of invalid identifiers: 2000y  Identifiers cannot have special characters in them. For example: X=Y, J-20, ~Ricky,*Michael are invalid identifiers.  Identifiers are case-sensitive. For example: Hello, hello, WHOAMI, WhoAmI, whoami are unique identifiers.
  • 10.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com • Comments appear in green in Visual C++. • Comments are explanatory notes; they are ignored by the compiler. • There are two ways to include comments in a program: // A double slash marks the start of a //single line comment. /* A slash followed by an asterisk marks the start of a multiple line comment. It ends with an asterisk followed by a slash. */
  • 11.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com • Compiler directives appear in blue in Visual C++. • The #include directive tells the compiler to include some already existing C++ code in your program. • The included file is then linked with the program. • There are two forms of #include statements: #include <iostream> //for pre-defined files #include "my_lib.h" //for user-defined files
  • 12.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com C++ is a free-format language, which means that: • Extra blanks (spaces) or tabs before or after identifiers/operators are ignored. • Blank lines are ignored by the compiler just like comments. • Code can be indented in any way. • There can be more than one statement on a single line. • A single statement can continue over several lines.
  • 13.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com In order to improve the readability of your program, use the following conventions: • Start the program with a header that tells what the program does. • Use meaningful variable names. • Document each variable declaration with a comment telling what the variable is used for. • Place each executable statement on a single line. • A segment of code is a sequence of executable statements that belong together. – Use blank lines to separate different segments of code. – Document each segment of code with a comment telling what the segment does.
  • 14.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com • Writing Code without detailed analysis and design • Repeating trial and error without understanding the problem • Debugging the program line by line, statement by statement • Writing tricky and dirty programs
  • 15.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com
  • 16.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com ADDRESS: SCO -15, Dayal Bagh, Near Hanuman Mandir Ambala Cantt-133001 Haryana Ph. No.: 9729666670, 8222066670 &0171-4000670 Email ID: info.jatinbatra@gmail.com Website: www.batracomputercentre.com
  • 17.
    Website: www.batracomputercentre.comPh. No.:8222066670, 4000670 Email: info.jatinbatra@gmail.com