Introduction C++ (Download Tutorial Pdf)

C++ was developed by Bjarne Stroustrup of AT&T Bell Laboratories in the early 1980's, and is based on the C language. The "++" is a syntactic construct used in C (to increment a variable), and C++ is intended as an incremental improvement of C. Most of C is a subset of C++, so that most C programs can be compiled (i.e. converted into a series of low-level instructions that the computer can execute directly) using a C++ compiler.
C is in many ways hard to categorise. Compared to assembly language it is high-level, but it nevertheless includes many low-level facilities to directly manipulate the computer's memory. It is therefore an excellent language for writing efficient "systems" programs. But for other types of programs, C code can be hard to understand, and C programs can therefore be particularly prone to certain types of error. The extra object-oriented facilities in C++ are partly included to overcome these shortcomings.

Here is an example of a complete C++ program:

#include

int main()
{
int year_now, age_now, another_year, another_age;

cout << "Enter the current year then press RETURN.\n";
cin >> year_now;

cout << "Enter your current age in years.\n";
cin >> age_now;

cout << "Enter the year for which you wish to know your age.\n";
cin >> another_year;

another_age = another_year - (year_now - age_now);
if (another_age >= 0) {
cout << "Your age in " << another_year << ": ";
cout << another_age << "\n";
}
else {
cout << "You weren't even born in ";
cout << another_year << "!\n";
}

return 0;
}


More...
Download Tutorial

Comments

Leave a Reply

Awards

100 Blog Indonesia Terbaik


IP
Powered by Blogger.