MIT 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
● By the end of this course, you should be able to:
○ develop proficiency in computer programming concepts and principles.
○ enhance your problem-solving skills through coding and algorithm development.
○ cultivate a strong foundation in programming languages such as Java, C++, and Python.
○ explore software development methodologies and best practices.
○ prepare yourself for advanced programming courses and real-world applications in the field of computer
programming.
4
Course Objectives
● At the end of the course, you should be able to:
○ understand fundamental programming concepts such as variables, loops, functions, and data structures.
○ apply programming principles to solve problems and write efficient code.
○ practice coding in different programming languages and develop proficiency in at least one language.
○ learn about software development processes, including debugging and testing techniques.
○ engage in hands-on programming projects to demonstrate understanding of concepts and skills acquired in
the course.
5
Week 2
Basic Data Types and Variables
Data types (int, float, string, boolean)
Assignment statements and operators
Expressions in programming
6
Learning Outcomes
● Identify and differentiate between basic data types used in programming
● Declare and initialize variables in a programming language
● Understand and use assignment statements and operators
● Write and evaluate expressions in computer programming
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
● Arithmetic operators are used to perform mathematical calculations on numerical values.
○ Addition (+): Adds two numbers.
■ Example: sum = 10 + 5;
○ Subtraction (-): Subtracts one number from another.
■ Example: difference = 10 - 5;
○ Multiplication (*): Multiplies two numbers.
■ Example: product = 10 * 5;
○ Division (/): Divides one number by another.
■ Example: quotient = 10 / 5;
○ Modulus (%): Returns the remainder of a division.
■ Example: remainder = 10 % 3;
11
Boolean Operators
● Boolean operators compare values and produce a True or False result.
● These are essential for making decisions in programming.
● Comparison Operators:
○ Equal to (==): x == y
○ Not equal to (!=): x != y
○ Greater than (>): x > y
○ Less than (<): x < y
● Logical Operators:
○ AND (&&): Returns True if both conditions are true.
■ Example: if (age > 18 && age < 60)
○ OR (||): Returns True if at least one condition is true.
■ Example: if (age == 18 || isMember == True)
○ NOT (!): Reverses the logical value.
■ Example: if (!isMember)
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
● Assignment Statements: An assignment statement assigns a value to a variable.
○ Syntax: variable_name = value;
○ Example: int x = 10;
○ Multiple Assignments:
■ Assigning the same value to multiple variables:
■ Example: x = y = z = 10;
● Assignment Operators: Assigns a value to a variable (=).
○ Example: x = 5;
○ +=: Adds a value to the variable and assigns the result.
■ Example: x += 5; (equivalent to x = x + 5)
○ -=: Subtracts a value from the variable and assigns the result.
■ Example: x -= 3; (equivalent to x = x - 3)
○ *=: Multiplies the variable by a value and assigns the result.
■ Example: x *= 2; (equivalent to x = x * 2)
○ /=: Divides the variable by a value and assigns the result.
■ Example: x /= 2; (equivalent to x = x / 2)
14
Example: Calculating the Area of a Rectangle
● Problem: Write a program to calculate the area of a rectangle using variables.
● Steps:
○ Declare two variables: length and width.
○ Initialize the variables with values.
○ Use the formula area = length * width.
○ Output the result.
● Code Example: python
length = 5
width = 3
area = length * width
print("The area of the rectangle is:", area)
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
● Key Concepts Covered:
○ Basic data types: integer, float, string, boolean.
○ How to declare and initialize variables.
○ Using arithmetic and boolean expressions.
○ Assignment statements and operators.
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