AP Computer Science Workshop


C++ vs. Pascal

Types
int, double, char integer, real, char
(short, long, float)
apvector, apmatrix arrays
structs records
 
Definitions
char ch; ch : char;
int j, k=0; j, k : integer;
double x; x : real; ... k := 0;
apvector<int> a(100); a : array [0 . . 99] of integer;
 
Operators
+  -  *  /  % +  -  *  /  div  mod
= :=
&& , | | , ! and, or, not
< , <= , > , >= , == , != < , <= , > , >= , = , <>
+= , -= , *= , /= , ++ , --
 
Semicolon acts as
terminator separator
 
Compound statement
{} begin end
 
Selection
if ( <bool> )
      <stmt>;
else
      <stmt>;
if <bool> then
      <stmt>
else
      <stmt>
 
switch case
 
Loops
for (init; term; update) for lcv := init to/downto final do
 
while ( <bool> ) while <bool> do
 
do {
      } while ( <bool> );
repeat
      until <bool>
 
I/O
cout << x ; write(x);
cout << x << endl; writeln(x);
cin >> i; read(i);

Previous slide Mark Stehlik, Carnegie Mellon University Next slide