Escolar Documentos
Profissional Documentos
Cultura Documentos
Department
Computer Programming
(MEng 1052)
Lecture 2
Introduction to C++
February, 2015
any sort of program, but its success and popularity are closely
tied to the UNIX operating system.
The C language is peculiar because it is a high-level language
with many of the features of a low-level language.
C is somewhere in between the two extremes of a very highlevel language and a low-level language, and therein lies both
its strengths and its weaknesses.
C is not as easy to understand as other languages; also, it does
not have as many automatic checks as some other high-level
languages.
is moving. The arrows, << and >>, are called insert and
extract, or put to and get from, respectively.
For example, consider the line:
11
12
14
15
16
int main( )
{
These two lines simply say that the main function of the
18
19
SELF-TEST EXERCISES
If the following statement were used in a C++ program,
what would it cause to be written on the screen?
cout << "C++ is easy to understand.";
2. What is the meaning of \n as used in the following
statement?
cout << "Enter the number of peas in a pod:\n";
3. What is the meaning of this directive?
#include <iostream>
4. What, if anything, is wrong with the following #include
directives?
a) #include <iostream >
b) #include < iostream>
c) #include <iostream>
1.
20
21
22
Exercises
Write a C++ program that reads in two integers and then
outputs both their sum and their product.
2. Write a program that allows the user to enter a time in
seconds and then outputs how far an object would drop if it
is in free fall for that length of time. Assume that the object
starts at rest, there is no friction or resistance from air, and
there is a constant acceleration of 32 feet per second due to
gravity. Use the equation:
1.
End of Lecture 2
Next Lecture
24