0% found this document useful (0 votes)
78 views51 pages

BUE Lecture 1 Intro

Uploaded by

ahmed osa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views51 pages

BUE Lecture 1 Intro

Uploaded by

ahmed osa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

23COMP02C

PROGRAMMING AND
SOFTWARE DESIGN/
23ECE12C
LECTURE 1 COMPUTER
PROGRAMMING

1
Module Logistics
Module Leader
– Dr. Sally Saad
Lecturer in Faculty of Computer and Information Sciences -Ain Shams University
• Contact: [email protected]
• Office hours availability:
– On Wednesday 11:00 am – 12:30 pm at externals room Building A last floor
» (Set an appointment before it at least with 24 hrs)
– Via email [email protected]
– Via messenger: https://www.facebook.com/Sally.S.Ismail
• Online Office hours:
– Sunday @ 2pm via link
https://us04web.zoom.us/j/8293143395?pwd=SE11djNMWjBKQmZYR0dUWmV
5VGt2UT09
Meeting ID: 829 314 3395
Passcode: 052872 2
Module Logistics
• Teaching Assistant
– TA\ Ameera Amer
[email protected]
• Ask her for her office hours.
• Office: E106

– Module Materials via BUE E-Learning.

3
Module Logistics
– Introduce yourself.
– Please let the SR contact me.

4
Module Logistics
• Class meets:
– 2-hours lecture
– 2-hours lab
– Tutorial
• Assessment (100 points)
Final Examination 60
In Campus Assignment 1 (W5) 10
In-Class Examination (W8) 20
In Campus Assignment 2(W10) 10
----------------------------------------------------
TOTAL 100
5
Module Logistics – Textbook
Available References:
• Starting Out with C++: Early Objects, 9e Edition
,Tony Gaddis, Judy Walters, Godfrey Muganda ISBN:
9781292157313,Pearson, 2016.
• C++ How to Program, 5th edition, Deitel & Deitel,
Prentice Hall- Pearson Education International, 2005.
Other References
• Problem Solving with C++, 8th edition, Walter Savitch,
Addison Wesley-Pearson Education International, 2012.
• Any online reference/tutorial/video explaining
the topic is accepted.
6
EXPECTED CODE OF CONDUCT

7
Note : A problems’ sheet will be available weekly via E-Learning for practicing.
Intended Learning Outcomes (ILOs)

8
WHY DO ELECTRIC ENGINEERS NEED TO
LEARN PROGRAMMING?

9
WHY DO
COMPUTER
ENGINEERS
NEED TO LEARN
PROGRAMMING?

10
Programming Applications
PROGRAMMING APPLICATIONS

11

Reference
FUN FACTS

12
Module Logistics – Outline
1. Introduction to Programming: Review on previous concepts.
2. Control Structures: Sequential, Conditional, Iterative.
3. 1D Array + Searching.
4. Sorting 1D Array + 2D array
5. Functions 1 (by value) + built-in Functions.
6. Functions 2 (By Ref) + Passing arrays.
7. Problem Solving I
8. Pointers I.
9. Pointers II and dynamic 1D Array.
10. OOP Concepts 1: Abstract Data Type, Classes and Objects,
Encapsulation, and Access modifiers.
13

11. Revision + Problem Solving II.


Lecture Agenda

1. Introduction to Programming Languages.


2. Review on :
– C++ Identifiers.
– Types of Errors.

14
Revision

15
Problem Solving

17
Problem Solving
Steps of Solving a Problem:
1. Define the problem
2. Design a solution
– How to reach output from input
– Plan a solution
Analysis
– List steps of solution

Algorithm
18
Problem Solving – (cont.)
• An algorithm is simply the sequence of steps
taken to solve a problem.
• The steps are normally “sequence”,
“selection”, or “iteration”, statements.
• An algorithm is written as a pseudo code
which is a kind of structured English for
describing algorithms. It allows the designer to
focus on the logic of the algorithm without
being distracted by details of language syntax
(language independent).
19
Problem Solving – (cont.)

Example 1: Student pass? (Design) Start


1. GET Grade
Get
2. IF Grade is greater than or Grade
equal to 40 THEN
3. Print "passed" Yes Grade No
>=40
4. ELSE Print Print
“Passed” “Failed”
5. Print "failed"
6. ENDIF
End

(a) Pseudocode (b) flowchart 20


Problem Solving – (cont.)
Steps of Solving a Problem:
1. Define the problem.
2. Design a solution.
3. Test on sample data → trace
4. Implement the “algorithm” Programming
Language
5. Test on real data → run
Logical and Runtime Errors- Syntax Errors-
Your duty using debugger
Compiler duty

6. Modify your solution / algorithm and Enhance


your code to utilize less resources. 21
Code
Optimization
Programming Techniques & Languages

• Talking to your Computer

22
2 Programming Techniques & Languages

• Talking to your Computer

Java C++ Python

23
Developing a Program Steps:
• C++ Development Environment
1- Creating Program
- Source code
- Popular IDEs: Microsoft® Visual Studio, Dev
C++, NetBeans, Code Blocks, Eclipse.
2- Preprocessing
- Automatically
- Preprocessor directives (#include, #define)
24
Developing a Program Steps:
• C++ Development Environment
3- Compiling
- Create Object code
(detecting syntax errors)

4- Linking
- executable code

25
Developing a Program Steps:
• C++ Development Environment
5- Loading
- With other needed libraries.

6- Executing
- One instruction at a time.
26
Developing a Program Steps:
• C++ Created Files/Folders
Project Folder include:
Debug folder
•Includes .exe file
(Application itself)
•Includes other files
related to the debug
or the release of the
project
.sdf
*.sln file database file
Opens the whole
Beyond our scope ☺
solution on the IDE

Solution Folder
•Includes different Project(s) within your solution
•Includes Source file(s).cpp file(s)
•Includes other projects files like .h file(s)
27
•Includes other files like log files
Programming Techniques
1. Unstructured Programming
2. Procedural (Structured)Programming
3. Modular (Object Oriented) Programming
4. Logic Programming

28

PROGRAMMING TECHNIQUES &


LANGUAGES
2. STRUCTURED PROGRAM VIEW

Main Program

Data

Procedure1 Procedure2 Procedure3

29
3. OBJECT-ORIENTED PROGRAMMING

Main Program(Also a module)

Data

Module1 Module2

Data + Data1 Data + Data2

Procedure1 Procedure2 Procedure3


COMPUTER PROGRAMMING [email protected]

30
31

C++
PROGRAM
C++ Programming
Libraries and
namespaces
void
functions

Variables

Input/output

Control
Structure
32
Namespaces

• Namespaces defined:
– Collection of name definitions
• For now: interested in namespace "std"
– Has all standard library definitions we need
• Examples:
#include <iostream>
using namespace std;
• Includes entire standard library of name definitions
#include <iostream>
using std::cin;
using std::cout;
• Can specify just the objects we want 33

• Let’s try it on visual studio ☺


34

IDENTIFIERS
AND
LITERALS
IDENTIFIERS TYPES (FYI)

35
Variables – Exercise
(Pre and Post Increment/Decrement)
Example: Evaluate the following

36
Variables
ASSIGNING DATA: SHORTHAND
NOTATIONS

37
Variables
 Compatibility of Data Assignments
 Type mismatches
 General Rule: Cannot place value of one type
into variable of another type
 int Var = 2.99; // 2 is assigned to Var!

 Only integer part "fits", so that’s all that goes


 Called "implicit" or "automatic type
conversion" 38
VARIABLES – TYPE CASTING

 Two types
 Implicit—also called "Automatic"
 Done FOR you, automatically
17 / 5.5;
This expression causes an "implicit type cast" to
take place, casting the 17 → 17.0

 Explicit type conversion


 Programmer specifies conversion with cast operator
(double) 17 / 5.5;
Same expression as above, using explicit cast
(double) myInt / myDouble;
More typical use; cast operator on variable

39
LITERALS

 Literals
 Examples:
 2 // Literal constant int
 5.75 // Literal constant
double
 ‘Z’ // Literal constant char
 "Hello World" // Literal constant string

 Considered constants: Cannot change values


during execution
 Called "literals" because you "literally typed"
them in your program!

40
Defining Constants:
const Vs. #define

41
Defining Constants:
const Vs. #define

42
Defining Constants:
const Vs. #define

const #define
 Should specify data type  No data type
 Takes space in memory  No memory used
 Should have initialization statement ending  No semicolon
with a semicolon
 Can Not be modified
 Can not be modified later
 Replaces the const name with the value
 Preferred name in capital letters. beside it.
 Placed anywhere in the program preferably  Uses preprocessor directive and is placed
after the function header (main()) after #include
 E.g  E.g.
const int SIZE=10; #define SIZE 10

43
Operators
Operators Precedence

44
Arithmetic Operators
• Standard Arithmetic Operators
– Precedence rules – standard rules
– Parentheses?

Evaluate: z= 2 * 10 % 3 + 6 / 2 – 1; 45
TYPES OF ERRORS

1.Syntax 2. Logical 3. Runtime


Errors Errors Errors

46
I. SYNTAX ERRORS
Example: Syntax Error:
identifier name can
 They are errors in code void main() not start with a
structure (Syntax) or { number
grammar (Semantics). int 0product = 1;
for (int i = 1; i <= 15; i++)
 Easily detected in product *= i;
Compilation process. cout << "Product: " << product
<< endl
 Easily fixed. }
 Program does NOT run Syntax Error:
till all syntax/semantic missing semi-colon
errors are fixed.
47
2. LOGIC ERRORS
Example: Syntax Error: Logical
 They are errors in the logic error, += instead of
of the code. void main() *=
{
 Might be the designer int product = 1;
mistake or a typing for (int i = 1; i >= 15; i++)
mismatch by the developer. product += i;
 Can NOT be detected in cout << "Product: " << product
Compilation process. << endl;

 Needs debugging to trace, }


detect and fix. Logical Error:
 Program runs normally but > instead of <
gives wrong results.
48
3. RUNTIME ERRORS
Example: Runtime Error:
 They are errors occurring in Infinite loop due to
void main()
runtime, due to not handling all incrementing j not i
{
cases, or mismatch in
int product = 1,j=0;
development.
for (int i = 1; i <= 15; j++)
 Can NOT be detected in product *= i;
Compilation process. cout << "Product: " << product
<< endl;
 Needs debugging to trace, detect
j=0;
and fix.
float result=product/j;
 Program runs normally but gives }
unexpected results, halting the run
Syntax Error: Logical error, += instead of *=
process.

49
EXERCISES SHEET
WILL BE
RELEASED
WEEKLY VIA E-
LEARNING FOR
THOSE WHO
WANT BETTER
CAREER ;-)

50
HOW TO STUDY THIS MODULE?

Every week you need to do the following (2-4 hrs. studying):


1. Attend the Lecture.
2. Read the lecture.
3. Understand every single slide.
4. Think, Design and implement every single problem on
the Visual Studio IDE.
5. Edit and update the code with your own ideas and see
the difference in the run.
6. Repeat for the labs.
7. Solve extra exercises, from sheets, books, any online
resources.
Got Stuck?
51
The Module Leader and the assistant are available weekly in
office hours or via contacting them (check their contacts).
Please revise this
lecture pretty well
before attending
next lecture ☺

52

You might also like