Second Contact - Part 3 813
Second Contact - Part 3 813
Programming
Fundamentals
Dr. Barroon Isma’eel Ahmad
Department of Computer and Information Technology
Photo by Pexels
01 Study Session 1: Introduction to Computer Programming
Table of 02
03
Study Session 2: Basic Data Types and Variables
Study Session 3: Object-Oriented Concepts
Contents 04 Revision
05 Study Session 4: Program Organization and API Usage
06 Study Session 5: Event-Driven Programming
07 Study Session 6: Input/Output and Control Structures
08 Study Session 7: Recursive Algorithms and Inheritance
09 Revision
10 Study Session 8: Polymorphism
11 Study Session 9: Project Development
12 Revision
13 Revision
2
Introduction to Programming Fundamentals
● An overview of the core concepts of programming including variables, loops, and functions.
● Understand the importance of coding in modern-day technology and its applications in various industries.
● Explore the fundamentals of programming languages, syntax rules, and problem-solving strategies.
● Delve into the significance of structured programming and algorithmic thinking in software development.
● Discover the evolution of programming languages and the role of programming paradigms in shaping software
design.
● Learn about object-oriented programming and its advantages in creating reusable code.
● Understand the key principles of software testing, debugging, and version control.
● Explore common programming errors and methodologies to enhance code quality and maintainability.
● Reflect on the ethical considerations in software development and the importance of adhering to coding standards
and best practices.
● Explore the interdisciplinary nature of programming and its impact on innovation.
3
Course Aims
4
Course Objectives
5
Week 2
6
Learning Outcomes
7
Understanding Data Types in Programming
● Data types specify the kind of data that a variable can store, ensuring that the computer allocates the right amount of
memory and performs the correct operations on the data.
● Common Data Types
○ Integer: Represents whole numbers (both positive and negative).
■ Examples: int num = 10;, int count = -5;
■ Used for counting and indexing in loops.
○ Float/Double: Used to store numbers with decimal points.
■ Examples: float price = 10.99; double distance = 123.456; double d = -0.001;
■ Suitable for precision in calculations like currency or scientific measurements.
○ String: Represents text (a sequence of characters).
■ Examples: string name = ”Ahmad Umar";, char letter = 'A';
■ Useful for handling names, messages, or any character-based input/output.
○ Boolean: Represents logical values (True or False).
■ Examples: bool isAdult = True;, bool isMember = False;
■ Often used in decision-making and condition checks.
8
Variable Declaration and Initialization
● A variable is a named storage location in a program that can hold a value which may change during program execution.
● Declaring a Variable: Telling the computer to reserve space in memory for the variable.
○ Syntax: data_type variable_name;
○ Example: int age;
● Initializing a Variable: Assigning an initial value to the variable.
○ Syntax: data_type variable_name = value;
○ Example: int age = 25;
● Examples
○ Single Variable Declaration and Initialization:
■ int number = 10;
■ float temperature = 36.5;
■ string name = "Alice";
○ Multiple Variable Declaration:
■ Declaring multiple variables of the same type in one line: E.g. int x = 5, y = 10, z = 15;
○ Variable Without Initialization:
■ Declaring a variable without assigning a value:
■ Example: int count;
■ Note: Always initialize variables before using them in calculations.
9
Variable Declaration and Initialization
10
Arithmetic Operators
11
Boolean Operators
12
Working with Expressions in Programming
● An expression is a combination of values, variables, operators, and functions that are evaluated to produce a result.
● Expressions are the building blocks of computer programs that allow you to perform calculations, make decisions,
manipulate data, and call functions.
● Types of Expressions:
○ Arithmetic Expressions: Perform basic math operations.
■ Example: result = num1 + num2;
○ Boolean Expressions: Used for logical comparisons.
■ Example: isAdult = age >= 18;
○ String Expressions: Concatenate strings or manipulate text.
■ Example: fullName = firstName + " " + lastName;
○ Function Call Expressions: Call function(blocks of reusable code that perform specific tasks) in an expression
■ Example: Math.sqrt(25);
13
Assignment Statements and Operators
15
In-Class Activity - Using Variables and Operators
● Task: Write a simple program to calculate and display the result of an arithmetic expression using different
operators.
● Discussion:
○ How are different data types handled in expressions?
○ What happens if you mix data types in an expression (e.g., string + int)?
16
Summary
17
Recap: Key Takeaways
● Variables:
○ Variables are containers that store data.
○ Ensure variables are always initialized before use.
● Data Types:
○ Choosing the right data type is crucial for memory efficiency and accuracy.
○ String manipulation and boolean logic are key to many real-world programming tasks.
● Expressions and Operators:
○ Arithmetic and Boolean expressions form the core of logical and mathematical operations.
○ Assignment operators make code shorter and easier to understand.
● Assignment and Evaluation:
○ Practice how variables are assigned and manipulated using operators.
○ Test your understanding by writing simple programs to solve problems.
18
Assignment
● Write a program to calculate the average of three numbers provided by the user.
○ Use appropriate data types, variables, and arithmetic operators.
● Modify your program to accept any number of user inputs and calculate the average dynamically.
○ Use loops and arrays/lists to handle multiple inputs.
● Group Discussion: Discuss how different data types affect the outcome of operations and expressions in
programming.
19