( Week 2-2)
Programming Process
1.
2.
3.
4.
Develop a Solution
Algorithm: the exact steps used to solve a
problem
Algorithm is usually defined at high level, then
refined to detailed lower levels
Structure level diagrams may be used to represent
the levels of analysis
Two most common planning tools:
Flowcharts
Pseudocode
Compile the
program
List of syntax
error messages
Executable
program
Program
Output
Documentation
Many documents may be required, including
Program description
Algorithm development and changes
Well-commented program listing
Sample test runs
Users manual
Maintenance
Maintenance includes
Ongoing correction of newly discovered bugs
Revisions to meet changing user needs
Addition of new features
Backup
Backup: process of making copies of program
code and documentation on a regular basis
Backup copies = insurance against loss or
damage
Consider using off-site storage for additional
protection
CS001P
Week3
C++
PROGRAMMING
LANGUAGE
C++
History of C++
1980- began the development of the C++
language, that would receive formally this
name at the end of 1983
C++ lived a great expansion in its use and
today is the preferred language to develop
professional applications on all platforms.
Bjarne Stroustrup
-a computer scientist
DEFINITION OF TERMS
BUG is a term used to refer for a program
mistake or error.
C++ LIBRARY provides a set of common
classes and interfaces that greatly extend the
core C++ language.
COMPILER is a program that converts your
program to low-level machine instructions.
DEBUG is a process of correcting program
mistakes.
DEFINITION OF TERMS
EDITOR is software that enables the typing of the
programs where you can easily type, change and save
programs.
IDENTIFIER is a sequence of one or more letters, digits
or underscores characters (_).
LINKER is a program that supplies needed runtime
information to the compiled program and it is also used
to combine multiple programs into one executable
program.
LOADER is a program that loads an executable
program into main memory.
DEFINITION OF TERMS
NAMESPACE is an abstract container providing
context for the items (names, or technical terms, or
words) it holds and allowing disambiguation of items
having the same name.
OBJECT CODE is the code produced by a compiler
from the source code, usually in the form of machine
language that a computer can execute directly.
PREPROCESSOR reads a programs preprocessor
directives to control the compilation.
PROGRAM is a list of detailed instructions that tells
the computer what to do.
DEFINITION OF TERMS
PROGRAMMING is the act or process of creating a
program.
SOURCE CODE is code written by a programmer in
a high-level language and readable by people but
not computers.
SYNTAX is the rules governing the formation of
statements in a programming language, usually a
typing error.
VARIABLE is an example of an identifier, it is a
location where you can store a piece of information.
C++
Click Start
Choose All Programs
Select Microsoft Visual Studio 6.0
Highlight Microsoft Visual C++
Go to File then New
Click the Files tab
Select C++ Source File
Type the filename of your work
Check the location
Then ok.
F5- Compile
Or
Ctrl + F5 To compile and run
{
cout<<Hello World";
return 0;
}
OUTPUT:
Hello World
DIRECTIVE
int main()
MAIN FUNCTION
Start of a block
cout<<Hello World";
return 0;
}
End of a block
OUTPUT:
Hello World
OUTPUT:
Hello
Malayan Colleges
OUTPUT:
Hello
Malayan Colleges
Data
Type
Variable Name
int a;
a = 5;
cout << a;
return 0;
}
NOTE: Whenever we
use a value or a
variable, we will
declare it and its data
type
Data Types
Numeric Data Types
Real
Floating point
Integral
Character
String
Range of Values
char
256 characters
bool
int
-2,147,483,648 to +2,147,483,647
short int
long int
-2,147,483,648 to +2,147,483,647
0 to 65,535
0 to 4,294,967,295
float
1.40129846432481707e-45 to
3.4028234663858860e+38
4.94065645841246544e-324 to
1.79769313486231570e+308
Naming Variables
The name of variable can be called identifier or variable name in a friendly
way. It has to follow rules:
FIRSTNAME
FIRST_NAME
NAME2
_NAME
Data
Type
Variable Name
Int a;
a = 5;
cout << a;
return 0;
}
OUTPUT:
5
Variable Name
int num1;
cout << Enter a number: ;
cin>>num1;
return 0;
}
OUTPUT:
Enter a number: 5
OUTPUT:
Enter two numbers separated by spaces: 5 7
int main()
{
cout << Enter two numbers separated by spaces: ;
cin>>num1>>num2
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int myAge;
cout << "My age is " << myAge << endl;
return 0;
}
NOTES!
#include <iostream>
using namespace std;
int main()
{
int myAge=20;
cout << "My age is " << myAge << endl;
return 0;
}
Practice 1:
#include <iostream>
using namespace std;
int main()
{
int sum;
sum=12;
sum= sum + 5;
cout << Sum is: " << sum << endl;
return 0;
}
return 0;
}
Output:
The sum is: 60
The difference is: 14
The product is: 851
The quotient is: 1
MACHINE PROBLEM 1
FILENAME: MP1
CREATE A PROGRAM
THAT ADD TWO
INPUT NOS. AND
SHOW THE RESULT
MACHINE PROBLEM 2
FILENAME: MP2
CREATE A PROGRAM
THAT CALCULATE AND
DISPLAY THE SUM AND
AVERAGE OF THREE
QUIZZES
LABORATORY
EXERCISES
2 01,02,
& 04
SEMI-QUIZ#1
PART 1: General Instructions. Write A if only
Statement (a) is correct, B If only Statement
(b) is correct, C if both Statements are correct,
otherwise, write D
1-5
(a) Selection is also termed as loop structure
(b) Selection Structure follows a sequence of instructions
(a) Pseudo means False
(b) Pseudocode follows a strict standardized structure
(a) Mnemonics use 0s and 1s
(b) Assembly language uses 0s and 1s
(a) Any programming language has its own compiler
(b) A compiler translates the program into machine language
(a) Sequence structure iterates as long as the condition is true
(b) Iteration structure loops as long as the condition is true
6-10
(a) Variables should be declared with data type
(b) 1x is a valid variable
(a) Hexagon is a flowchart symbol for input
(b) Circle is a flowchart symbol for start or stop
(a)
(b)
(a)
(b)
(a)
(b)
11-15
(a) int accepts negative numbers
(b) int y =5 is valid
(a) Equal sign is an assignment symbol
(b) Keyword can be used as variable
(a) Decision symbol in flowchart has 2 entry points and 1 exit point
(b) Long flowchart can be extended using connector
(a) Cout is a keyword from iostream
(b) Iostream is a library
(a) Square is the flowchart symbol for process
(b) Parallelogram is the flowchart symbol for preparation
Sequence
Number
Pseudocode Statements
area = length * width
input length, width
display area, perimeter
perimeter =
2*(length+width)
display instructions asking
users to input length and
width
Program
include <iostream>
using namespace std;
int main();
{
int n, sum=0;
Cout<<Enter an integer
value: ;
cin>>n;
sum = n(n+1)/2;
cout>>The summation of
number from 1 to<< n is:
<<sum;
return;
{
Corrected
Statement