Introduction to C++

Introduction to C++

INTRODUCTION

C++ improves on many of C’s features.
C++ provides object-oriented programming (OOP).
C++ is a superset to C.
No ANSI standard exists yet (in 1994).
In C,
/* This is a single-line comment. */
In C++,
// This is a single-line comment.
In C,
printf(“Enter new tag: “);scanf(“%d”, &tag);printf(“The new tag is: %d\n”, tag);
In C++,
cout << “Enter new tag: “;cin >> tag;cout << “The new tag is : “ << tag << ‘\n’;

EXAMPLE

// Simple stream input/output
#include

main()
{
cout << « Enter your age: « ; int myAge; cin >> myAge;

cout << « Enter your friend’s age: « ; int friendsAge; cin >> friendsAge;
if (myAge > friendsAge)
cout << « You are older.\n »;
else
if (myAge < friendsAge)
cout << « You are younger.\n »;
else
cout << « You and your friend are the same age.\n »;

return 0;
}

DECLARATIONS

In C++, declarations can be placed anywhere (except in the condition of a while, do/while, for or if structure.)
An example
cout << “Enter two integers: “; int x, y; cin >> x >> y;
cout << “The sum of “ << x << “ and “ << y
<< “ is “ << x + y << ‘\n’;
Another example

for (int i = 0; i <= 5; i++)
cout << i << ‘\n’;

Cours gratuitTélécharger le cours complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *