 |
Department of Engineering |
 |
 |
Next: Comments
Up: C++ Summary
Previous: C++ Summary
A simple C++ program may have the following form:
#include <iostream>
#include "myheader.h"
using namespace std;
const int c1 = ...; // c1, c2 are the names of
const float c2 = ...; // constants
struct s1 {...}; // s1, s2 are the names of
struct s2 {...}; // user-defined structures
class x1 {...}; // x1, x2 are the names of
class x2 {...}; // user-defined classes
int main()
{
int v1, v2; // v1, v2 are variables of predefined type int
s2 v3; // v3 is a variable of user-defined type s2
cin >> v1; // program body is a sequence of
......; // statements separated by semicolons
......;
v2 = v1 + c1;
......;
cout << v1 << " becomes " << v2 << endl;
return 0; // main program always returns 0 if successful
}