0% found this document useful (0 votes)
5 views41 pages

Lecture 1-Overview-1

The document outlines the structure and grading system for the IT 8113 Object Oriented Programming course at Mbeya University of Science and Technology. It introduces key concepts of object-oriented programming, such as classes, objects, encapsulation, and polymorphism, and emphasizes the use of C++ for practical implementation. Additionally, it covers C++ features, standard libraries, basic input/output operations, data types, and programming rules, along with examples and assignments for students.

Uploaded by

piresmboye
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)
5 views41 pages

Lecture 1-Overview-1

The document outlines the structure and grading system for the IT 8113 Object Oriented Programming course at Mbeya University of Science and Technology. It introduces key concepts of object-oriented programming, such as classes, objects, encapsulation, and polymorphism, and emphasizes the use of C++ for practical implementation. Additionally, it covers C++ features, standard libraries, basic input/output operations, data types, and programming rules, along with examples and assignments for students.

Uploaded by

piresmboye
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/ 41

Mbeya University of Science and

Technology
IT 8113: OBJECT ORIENTED PROGRAMMING

Facilitator: Mr. Magemo A


Email: [email protected]
Grading System

Test #1 ( Week 6/7) -------------15%

Test #2 (Week 11/12)------------15%

Quiz---------------------------------5%

Assignments -----------------------5%

University Examination -----------60%

4/4/2024
IT 8113: Object oriented programming 2
Introduction

Object oriented programming


➢ Object oriented programming Is a type of programming which uses
objects and classes.

➢ The object oriented programming is based on real world entities like


inheritance, polymorphism, data hiding, etc.

➢ It aims at binding together data and function work on these data sets
into a single entity to restrict their usage.

4/4/2024
IT 8113: Object oriented programming 3
Introduction

Some basic concepts of object oriented programming are −

CLASS
OBJECTS
ENCAPSULATION
POLYMORPHISM
INHERITANCE
ABSTRACTION

4/4/2024
IT 8113: Object oriented programming 4
Introduction

What are object oriented programming languages?


Python, java, C++, Ruby, C#, PHP, etc

➢ In this lecture we are going to use C++ Programming to implement


the concepts of object oriented programming.

➢ C++ is an object-oriented programming language. It is an extension to


C programming

4/4/2024
IT 8113: Object oriented programming 5
Introduction

C++ Standard Libraries


Standard C++ programming is divided into three important parts:

1. The core library includes the data types, variables and literals, etc.
2. The standard library includes the set of functions manipulating
strings, files, etc.
3. The Standard Template Library (STL) includes the set of methods
manipulating a data structure.

4/4/2024
IT 8113: Object oriented programming 6
Introduction

Usage of C++
➢ By the help of C++ programming language, we can develop different
types of secured and robust applications:

1. Window application
2. Client-Server application
3. Device drivers
4. Embedded firmware etc

4/4/2024
IT 8113: Object oriented programming 7
Introduction

C++ Features
1. Simple
➢ C++ is a simple language because it provides a structured approach (to
break the problem into parts)
2. Abstract Data types
➢ In C++, complex data types called Abstract Data Types (ADT) can be
created using classes.
3. Portable
➢ C++ is a portable language and programs made in it can be run on
different machines.

4/4/2024
IT 8113: Object oriented programming 8
Introduction

4. Structured programming language


➢ C++ is a structured programming language. In this we can divide the
program into several parts using functions.
5. Rich Library
➢ C++ provides a lot of inbuilt functions that make the development
fast. Following are the libraries used in C++ programming are:
<iostream>
<cmath>
<cstdlib>
<fstream>

4/4/2024
IT 8113: Object oriented programming 9
Introduction

6. Pointer
➢ C++ provides the feature of pointers. We can use pointers for
memory, structures, functions, array, etc.
7. Recursion
➢ In C++, we can call the function within the function. It provides code
reusability for every function.
8. Reusability
➢ With the use of inheritance of functions programs written in C++ can
be reused in any other program of C++
9. Errors are easily detected: It is easier to maintain a C++ programs
as errors can be easily located and rectified

4/4/2024
IT 8113: Object oriented programming 10
Introduction

C++ Program
➢ Open the C++ console and write the following code:

#include <iostream>
Using name space std:
int main() {
clrscr();
cout << "Welcome to C++ Programming.";
return(0);
}

4/4/2024
IT 8113: Object oriented programming 11
Introduction

#include<iostream> includes the standard input output library functions.


It provides cin and cout methods for reading from input and writing to
output respectively.

void main() The main() function is the entry point of every program in
C++ language. The void keyword specifies that it returns no value.

4/4/2024
IT 8113: Object oriented programming 12
Introduction

cout << "Welcome to C++ Programming." is used to print the data


"Welcome to C++ Programming." on the console.

getch() The getch() function asks for a single character.

4/4/2024
IT 8113: Object oriented programming 13
Introduction

Basic Input/Output
I/O operation is using the stream concept. Stream is the sequence of
bytes or flow of data. It makes the performance fast.

➢ If bytes flow from main memory to device like printer, display


screen, or a network connection, etc, this is called as output
operation.

➢ If bytes flow from device like printer, display screen, or a network


connection, etc to main memory, this is called as input operation.

4/4/2024
IT 8113: Object oriented programming 14
Introduction

Basic Input/Output

Header File Function and Description

<iostream> It is used to define the cout, cin and cerr objects, which
correspond to standard output stream, standard input
stream and standard error stream, respectively.

<iomanip> It is used to declare services useful for performing


formatted I/O, such as setprecision and setw.

<fstream> It is used to declare services for user-controlled file


processing.

4/4/2024
IT 8113: Object oriented programming 15
Introduction

Standard output stream (cout)


➢ The cout is a predefined object of ostream class.
➢ It is connected with the standard output device, which is usually a
display screen.
➢ The cout is used in conjunction with stream insertion operator (<<) to
display the output on a console

4/4/2024
IT 8113: Object oriented programming 16
Introduction

Example of standard output stream (cout):

#include <iostream>
using namespace std;
int main( ) {
char ary[] = "Welcome to C++ tutorial";
cout << "Value of ary is: " << ary << endl;
}

Output:
Value of ary is: Welcome to C++ tutorial
4/4/2024
IT 8113: Object oriented programming 17
Introduction

Standard input stream (cin)


➢ The cin is a predefined object of istream class.
➢ It is connected with the standard input device, which is usually a
keyboard.
➢ The cin is used in conjunction with stream extraction operator (>>) to
read the input from a console.

4/4/2024
IT 8113: Object oriented programming 18
Introduction

Example of standard input stream (cin):


#include <iostream>
using namespace std;
int main( ) {
int age;
cout << "Enter your age: ";
cin >> age;
cout << "Your age is: " << age << endl;
}
Output:
Enter your age: 22
Your age is: 22
4/4/2024
IT 8113: Object oriented programming 19
Introduction

Standard end line (endl)


➢ The endl is a predefined object of ostream class.
➢ It is used to insert a new line characters and flushes the stream.
#include <iostream>
using namespace std;
int main( ) {
cout << "C++ Tutorial";
cout << " Java language"<<endl;
cout << "End of line"<<endl;
}

4/4/2024
IT 8113: Object oriented programming 20
Introduction

Variable
➢ A variable is a name of memory location. It is used to store data. Its
value can be changed and it can be reused many times.

syntax to declare a variable:


type variable_list;
Example:
int x;
float y; Here, x, y, z are variables and int, float,
char are data types.
char z;

4/4/2024
IT 8113: Object oriented programming 21
Introduction

Variable cont…..
➢ We can also provide values while declaring the variables as given
below:

int x=5,b=10; //declaring 2 variable of integer type


float f=30.8;
char c='A';

4/4/2024
IT 8113: Object oriented programming 22
Introduction

Rules for defining variables


1. A variable can have alphabets, digits and underscore.
2. A variable name can start with alphabet and underscore only. It
can't start with digit.
3. No white space is allowed within variable name.
4. A variable name must not be any reserved word or keyword e.g. char,
float etc.

4/4/2024
IT 8113: Object oriented programming 23
Introduction

Rules for defining variables cont….

Valid variable names: InValid variable names:

int a; int 4;
int _ab; int x y;
int a30; int double;

4/4/2024
IT 8113: Object oriented programming 24
Introduction

Data Types
There are 4 types of data types

Types Data Types

Basic Data Type int, char, float, double, etc

Derived Data Type array, pointer, etc

Enumeration Data Type enum

User Defined Data Type structure

4/4/2024
IT 8113: Object oriented programming 25
Introduction

Basic Data Types


➢ The basic data types are integer-based and floating-point based.
➢ C++ language supports both signed and unsigned literals.
➢ The memory size of basic data types may change according to 32 or
64 bit operating system.
➢ Let's see the basic data types. It size is given according to 32 bit
OS.

4/4/2024
IT 8113: Object oriented programming 26
Introduction

Basic Data Types

4/4/2024
IT 8113: Object oriented programming 27
Introduction

Operators
An operator is simply a symbol that is used to perform operations
The following are types of operators to perform different types of
operations.
❖ Arithmetic Operators
❖ Relational Operators
❖ Logical Operators
❖ Bitwise Operators
❖ Assignment Operator
❖ Unary operator
❖ Ternary or Conditional Operator
❖ Misc Operator
4/4/2024
IT 8113: Object oriented programming 28
Introduction

Identifiers
➢ Identifiers in a program are used to refer to the name of the
variables, functions, arrays, or other user-defined data types created
by the programmer.
➢ Every language has its own rules for naming the identifiers.

4/4/2024
IT 8113: Object oriented programming 29
Introduction

Rules that are common in both C and C++


1. Only alphabetic characters, digits, and underscores are allowed.
2. The identifier name cannot start with a digit, i.e., the first letter
should be alphabetical. After the first letter, we can use letters,
digits, or underscores.
3. In C++, uppercase and lowercase letters are distinct. Therefore, we
can say that C++ identifiers are case-sensitive.
4. A declared keyword cannot be used as a variable name.

4/4/2024
IT 8113: Object oriented programming 30
Introduction

Rules that are common in both C and C++


The following are the examples of valid identifiers are:
1. Result
2. Test2
3. _sum
4. power

4/4/2024
IT 8113: Object oriented programming 31
Introduction

Rules that are common in both C and C++


The following are the examples of invalid identifiers:
Sum-1 // containing special character '-'.
2data // the first letter is a digit.
break // use of a keyword.

4/4/2024
IT 8113: Object oriented programming 32
Introduction

simple example to understand the concept of identifiers.


#include <iostream>
using namespace std;
int main()
{
int a;
int A;
cout<<"Enter the values of 'a' and 'A'";
cin>>a;
cin>>A;
cout<<"\nThe values that you have entered are : "<<a<<" , "<<A;
return 0;
}

4/4/2024
IT 8113: Object oriented programming 33
Introduction

➢ In the above code, we declare two variables 'a' and 'A'. Both the
letters are same but they will behave as different identifiers.
➢ As we know that the identifiers are the case-sensitive so both the
identifiers will have different memory locations.
Output

4/4/2024
IT 8113: Object oriented programming 34
Introduction

Expression
➢ Expression consists of operators, constants, and variables which are
arranged according to the rules of the language.
➢ It can also contain function calls which return values. An expression
can consist of one or more operands, zero or more operators to
compute a value.

Examples of C++ expression:


1. (a+b) - c
2. (x/y) -z
3. 4a2 - 5b +c
4. (a+b) * (x+y)

4/4/2024
IT 8113: Object oriented programming 35
Introduction

Expression
➢ Expression consists of operators, constants, and variables which are
arranged according to the rules of the language.
➢ It can also contain function calls which return values. An expression
can consist of one or more operands, zero or more operators to
compute a value.

Examples of C++ expression:


1. (a+b) - c
2. (x/y) -z
3. 4a2 - 5b +c
4. (a+b) * (x+y)

4/4/2024
IT 8113: Object oriented programming 36
Introduction

Expression
An expression can be of following types:
1. Constant expressions
2. Integral expressions
3. Float expressions
4. Pointer expressions
5. Relational expressions
6. Logical expressions
7. Bitwise expressions
8. Special assignment expressions

4/4/2024
IT 8113: Object oriented programming 37
Introduction

Simple program containing constant expression:


#include <iostream>
using namespace std;
int main()
{
int x; // variable declaration.
x=(3/2) + 2; // constant expression
cout<<"Value of x is : "<<x; // displaying the value of x.
return 0;
}
➢ In the above code, we have first declared the 'x' variable of integer type.
After declaration, we assign the simple constant expression to the 'x'
variable.

4/4/2024
IT 8113: Object oriented programming 38
Introduction

Simple example of integral expression:


#include <iostream>
using namespace std;
int main()
{
int x; // variable declaration.
int y; // variable declaration
int z; // variable declaration
cout<<"Enter the values of x and y";
cin>>x>>y;
z=x+y;
cout<<"\n"<<"Value of z is :"<<z; // displaying the value of z.
return 0;
}
4/4/2024
IT 8113: Object oriented programming 39
ASSIGNMENT

Write the program for the following expression


1. Float expression
2. Pointer expression
3. Relation expression
4. Logical expression

4/4/2024
IT 8113: Object oriented programming 40
Thank you for Listening! Questions

4/4/2024 41
IT 8113: Object oriented programming

You might also like