MPD445 - Lecture 01 - 252
MPD445 - Lecture 01 - 252
DEPARTMENT
4th year Production
MDP445
Computer in Planning,
Analysis and Control
Lecture: 1
Introduction to computer applications
Processing Decision
Looping Connection
Branched algorithm
Arrows
Software Development
Write Source
Source Code File
Object
Compile File
Errors
Executable
Link File
Errors
Test
Errors
Program Stages
other code
from libraries,
etc.
Simplest C++ Program
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main (void)
{
return 0;
}
C++ Data Types
Simple
Address
Structured
char short int long enum
float double long double array struct union class
Examples:
What Does a Variable Declaration Do?
A declaration tells the compiler to allocate enough memory to hold a
int age; value of this data type, and to associate the identifier with this location.
float tRate;
char middle;
4 bytes for tRate 1 byte for Middle
Program Example
int main ()
{
float a;
a=m*d;
cout << “a= “ << a << endl;
return 0;
}
Variable Declaration by array:
4000 4002 4004
int bp1, bp2, bp3;
int total;
bp1 bp2 bp3
cin >> bp1 >> bp2 >> bp3;
total = bp1 + bp2 + bp3;
Base Address
indices or subscripts
Assigning values to individual array elements
float temps[ 5 ] ; // allocates memory for array
int m=4;
temps[ 2 ] = 98.6 ;
temps[ 3 ] = 101.2 ;
temps[ 0 ] = 99.4 ;
temps[ m ] = temps[ 3 ] / 2.0 ;
temps[ 1 ] = temps[ 3 ] - 1.2 ; // what value is
assigned?
7000 7004 7008 7012 7016
40 13 20 19 36
Examples:
int x[3][4];
float m[5][5]
EXAMPLE -- To keep monthly high temperatures for
all 50 states in one array.
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]
[0]
[1]
[2]
row 2, 66 64 72 78 85 90 99 105 98 90 88 80
.
col 7
might be . stateHighs [2] [7]
Arizona’s .
high for [ 48 ]
August [ 49 ]
Input/Output Statements
Input Statement:
return 0 ;
} //end of main
Sequential Programming
TRUE FALSE
expression
6 Relational Operators
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equal to
!= Not equal to
NESTED if statements
if ( Expression1 ) {
StatementList1
} else if ( Expression2 ) {
StatementList2
} else if
...
} else if ( ExpressionN ) {
StatementListN
} else {
StatementList N+1
}
For loops
It is very good for definite loops
All the parts (priming, testing and updating) are in one place.
format:
for (prime expression; test expression; update expression)
SYNTAX
}
initialization
For Loop diagram
false
Expression update
true
Body of loop
Example: Nested For Loops
#include <iostream>
#include <iomanip>
Using namespace std;
Output:
main ()
{ *
Outer Loop
int rows, columns; **
***
for (rows=1; rows<=5; rows++)
****
{
for (columns=1; columns<=rows; columns++) *****
cout<<"*";
Inner Loop
cout<<endl;
}
return 0;
}
While Statement
SYNTAX
while ( Expression )
{
.
. // loop body
.
}
SYNTAX
do
{
Statements;
} while ( Expression ) ;
Excel window
Review for the Spreadsheet (MS Excel)
Excel Functions Review
Excel function is a special type of formula that produces, or “returns” a specific result.
Function Elements
All functions are made up of two elements:
Function name
Argument list
Max. 30