Week 1 Programming Basics

Download Report

Transcript Week 1 Programming Basics

Programming Basics
• Aims of Programming:
– The aim of programming is to write programs to
accomplish complex tasks
• Programming method:
– functional decompositional programming method
– Tasks can be broken down into smaller tasks, and
further the smaller tasks can be broken down into the
smallest tasks, which is called the decompositional
programming method. A smallest task can be
represented and accomplished with a function in the
program, which is called the functional
decompositional programming method
– A function is a set of expressions or statements in C or
C++.
FD method example
FP and OOP
• FP means Functional Programming and OOP
means Object Oriented Programming.
• FP is a way to write programs with functions to
be manipulated top-down stepwise; while OOP
to classify the objects to set up classes with
variables and then represent the objects with
real figures under the classes.
• Programming in C or C++
– C was developed in 1984 and C++ in 1990. C is used
for FP. C++ can be used for both FP and OOP.
Software and Programs
• Software – a collection of programs.
• Program = data + algorithms +
programming syntax .
• System programs.
• Application programs.
• The following few slides will tell you how to
create a programming environment using
Microsoft Visual Studio 2008
When open the Visual studio C++ 2005, click on the new project will bring up
the dialogue above. Click on the General and select Empty Project in the left
Window. Give a name for your project.
Follow the instruction shows above to add a new item to your project.
You need to right click on the source files to get this.
Your added files should have a cpp extension. The name you assign to this
file should be same as your project file.
Hello.cpp – first c++ program
#include <iostream>
int main()
{
std::cout << "Hello,World!\n";
}
•
•
The first line of this source code is a preprocessor directive that tells the C++
compiler where to find the definition of the std::cout object that is used on the
third line. The identifier iostream is the name of a file in the Standard C++
Library. Every C++ program that has standard input and output must include
this preprocessor directive. Note the required punctuation: the pound sign # is
required to indicate that the word “include” is a preprocessor directive; the
angle brackets < > are required to indicate that the word “iostream” (which
stands for “input/output stream”) is the name of a Standard C++ Library file.
The expression <iostream> is called a standard header.
The second line is also required in every C++ program. It tells where the
program begins. The identifier main is the name of a function, called the main
function of the program.
Run your first program
•
•
•
•
On the Build menu, click Build Solution.
The Output window displays information about
the compilation progress, such as the location
of the build log and a message that indicates
the build status.
On the Debug menu, click Start without
Debugging.
If you used the sample program, a command
window is displayed that shows whether
certain integers are found in the set.