|
|
|
|
|
Identifier |
|
Variable declare and use |
|
Assignment statements |
|
Basic Data Type |
|
int |
|
double |
|
char |
|
|
|
|
Arithmetic operations |
|
Safe I /O operations |
|
Visual C++ IDE |
|
Graphic functions |
|
Examples |
|
|
|
|
|
|
|
Integer(int) and real number(double) can be
added, subtracted, multiplied, and divided. |
|
The operators used for arithmetic operations are
called arithmetic operators. |
|
Addition + |
|
Subtraction - |
|
Multiplication * |
|
Division / |
|
Modulus Division % |
|
|
|
|
|
|
|
In C++, the fractional part of the result
obtained when dividing two integers is dropped(truncated) |
|
15 / 2 = 7
// instead of 7.5 |
|
15.0 / 2 = 7.5 |
|
15 / 2.0 = 7.5 |
|
Modulus Operator (%) : capture the remainder of
an integer division |
|
9 % 4 =
1 |
|
17 % 3 = 2 |
|
14 % 2 = 0 |
|
The Modulus Operator can be used only with
integers |
|
|
|
|
|
|
C++ requires certain rules be followed when
writing arithmetic expressions containing more than one operators |
|
Two binary arithmetic operator symbols must
never be placed side by side |
|
5 * % 6
// Wrong ! |
|
Parentheses should be used to form grouping and
all expressions enclosed within parentheses are evaluated first. |
|
( 6 + 4 ) / ( 2 + 3 ) |
|
= 10 / 5 |
|
= 2 |
|
|
|
|
|
Sets of parentheses may also be enclosed by
other parentheses and expressions in the innermost parentheses are always
evaluated first. |
|
(2 * (3 + 7) ) / 5 |
|
= ( 2 *
10 ) / 5 |
|
= 20 /
5 |
|
= 4 |
|
Parentheses can not be used to indicate
multiplication |
|
( 3 + 4 ) ( 5 + 1) // Wrong ! |
|
( 3 + 4 ) * ( 5 + 1) // OK ! |
|
|
|
|
|
In the absence of parentheses, expressions
containing multiple operators evaluated by the priority, or precedence, of
the operators |
|
(high->low) |
|
Unary – |
|
* / % left to right |
|
+ - left to right |
|
Example |
|
8 + 5 * 7 % 2 * 4 |
|
= 8 +
35 % 2 * 4 |
|
= 8 + 1
* 4 = 8 + 4 = 12 |
|
|
|
|
|
|
· Microsoft
Visual C++ 6.0 with its Integrated Development Environment ( IDE ) is a
part of the Visual Studio 98 suite of development tools. |
|
· Visual
Studio 98 also includes Visual Basic, Visual J++, and a development tool
for FoxPro database programs. |
|
· Visual
C++, Visual Basic and Visual J++ each have their own distinct IDE. |
|
· Visual
Studio simplifies the care and feeding of projects. |
|
|
|
|
|
|
All applications developed using IDE are
maintained as project workspaces. |
|
A workspace can contain multiple projects, but
usually does not. Thus, we will use the terms workspace and project
interchangeably. |
|
In Visual C++, even simply programs consisting
of one source code file are maintained as project. |
|
|
|
|
|
|
|
A project consists of a number of files. Some of
them are created and maintained by the IDE, and others are developed and
maintained by the programmer. |
|
.cpp ( source code file) |
|
.dsp ( project file) |
|
.dsw ( workspace file) |
|
.ncb ( supports ClassView) |
|
.opt ( contains workspace configuration) |
|
.plg ( log file of the build process) |
|
|
|
|
|
|
|
|
Workspace window -- This window displays information about the workspace that
is currently open. Included are pages for the ClassView, the FileView, and
the ResourceView, which permits one to navigate through the project
contents from a class, file, and a resource point of view, respectively. |
|
|
|
|
Editor window -- This window provides a
color-coded editor for source code and a WYSIWYG editor for application
resource, such as menus, dialogs, and bitmaps. |
|
|
|
|
|
|
Tool bars – These bars provide shortcuts to a
variety of tasks that one perform while building an application. The bars
can be customized completely. |
|
Output window – This window displays output
information from various operations. The most common use for this window is
to view complier and linker messages. |
|
|
|
|
|
|
|
Install VC++ 6.0 |
|
Download and Install Visual studio service pack
3 |
|
Download and install Winzip 7.0 |
|
Download a shell project from www.ccs.neu.edu/course/com1100/Resource |
|
ShellProject.exe |
|
builds a Shell project ready to be used to
make new project. |
|
It is a self-extracting archive and should be
expanded in the folder where you want the work to go. Accept the suggestion
to put the files in the specified folders. |
|
|
|
|
|
|
Raw input |
|
Verified input |
|
Verified Input with Default |
|
|
|
|
|
The built-in input functions/statements in most
programming languages support this mode of input. |
|
cin >> |
|
Example |
|
int x; |
|
cout << “Please enter a number : “ ; |
|
cin >> x; |
|
// what happened if I enter a letter instead
of a number |
|
cout << “The number you entered is : “
<< x << endl; |
|
|
|
|
string myName; |
|
cout
<< “Please enter your name : “ ; |
|
cin
>> myName; |
|
//
what happened if I enter a number instead of a string |
|
// what
happened if I enter : Elice Brown |
|
cout
<< “The name entered is : “ << myName << endl ; |
|
|
|
|
|
|
It is not part of C++. It is developed by Prof.
Rasala |
|
int x; |
|
x =
RequestInt(“Please enter a number :"); |
|
Double y; |
|
y =
RequestDouble(“Please enter a real num :"); |
|
String myName; |
|
RequestString(“Enter your name: ”,myName); |
|
|
|
|
The only difference from the verified input is
that the program supplies a default value. The default value is displayed
after the prompt, to alert the user to its availability and to inform the
user of the default value. The statements have the format: |
|
x = RequestInt(“Enter a number:", 3); |
|
RequestString("Type in your name",
“Yuhong”, myName); |
|
|
|
|
|
|
|
Raw Read provides no error checking. Two
statements are needed - an output statement that prints the prompt to the
user and a basic input statement. |
|
int x; |
|
cout << “Please enter a number : ”; |
|
cin >> x; |
|
|
|
|
|
|
|
|
|
Verified Read is uses a function that prints the
given prompt, reads the input, and verifies that the input is of correct
type. It repeats the request for input until valid input is supplied. |
|
int x; |
|
x = RequestInt(“Please enter a number :”); |
|
|
|
|
|
|
|
Verified Read with Default uses a function that
prints the given prompt as well as the given default value and awaits
input. If the input is not correct, the function repeats the request and
gives the user another chance to type in the data. If the user enters no
data, the default value is used instead. |
|
int x; |
|
x = RequestInt(“Enter a number:”, 3); |
|
|
|
|
|
|
|
|
It is a left-handed coordinate system. |
|
What this means is that the origin of the screen
lies at the upper left corner. |
|
The Y axis increases towards the bottom of the
screen, the X axis increases towards the right. |
|
|
|
|
|
|
|
|
SetForeColor(R,G,B); |
|
SetForeColor(255,0,0); // red |
|
SetForeColor(0,255,0); // green |
|
SetForeColor(0,0,255); // blue |
|
PaintRect(left,top,right,bottom); |
|
PaintRect(10,10,100,100) |
|
PaintCircle(xcenter,ycenter,radius); |
|
PaintCircle(200,200,10) |
|
PaintOval(left,top,right,bottom); |
|
InvertOval(left,top,right,bottom); |
|
|
|
|
|
|
Arithmetic operations |
|
Safe I /O operations |
|
Visual C++ IDE |
|
Graphic functions |
|
Examples |
|
|
|
|
|
|
Functions |
|
Safe I /O operations |
|
More Graphic functions |
|
|
|
|
|