Lecture 1
Lecture 1
COMPUTING
Personal Information
• Nida Aziz
• BE Mechatronics (DE 25)
• MS Intelligent Systems and Robotics, University
of Essex, UK
• Email: [email protected]
[email protected]
Course Objectives
• This is a basic course in Mechatronics which is offered to all
students in the college.
• The course aims to
– introduce the students to programing languages,
– To formulate algorithms and
– proficiently program in C++.
• All basic topics including but not limited to input/output
statements, selection statements, repetition structures,
indirect addressing methods, arrays, hardware, etc are
covered in this course and are practiced in the labs.
• It will give you enough knowledge to proficiently develop
software in C++.
Prerequisites
• None
Course Outline
• Language syntax • Arrays & Strings
• Algorithm formulation • Pointers
• Operators • Structures
• Selection • File handling
• Repetition • Classes & Objects
• Functions
Resources
• C++ How to program (5th Ed): Deitel and Deitel
• Object oriented programming in C++ (4th Ed):
Robert LaFore
Course Details
• Credit Hours: 3-1
• Modes of Teaching: Lectures, Labs and Demos
• Grading (100% of 75%)
– Finals 40%
– Mid-Terms 25%
– Projects 2 x 10%
– Quizzes 15%
Please Note:
• All correspondence will be done via your
official yahoo group DE 34 MTS. Please join it
and check it regularly!
• Plagiarism is strictly not allowed and will be
dealt with seriously!
What constitutes PLAGIARISM??
• Plagiarism is when you
– Copy code (from a fellow or the internet)
– Share code (working together)
– Borrow code (even just for an idea)
– Take or give help in coding (from your fellows, the
internet or anyone else)
• Consequences:
– Your assignment will be cancelled. Both parties will
get ZERO marks.
– Further disciplinary action might be taken if need be.
What does not constitute
PLAGIARISM??
• Discussions
– You may discuss the strategies of solving a
problem without sharing any piece of code.
EC-100 - Algorithm and
Computing
Lecture 1
Introduction to Computers
• A computer is a device capable of
– performing computations and
– making logical decisions
– at speeds millions (even billions) of times faster than
human beings can (Deitel and Deitel).
• Many of today's personal computers have
frequencies in GHz range.
• What is the speed of the fastest computer in the
world??
• What is the speed of your computer??
Introduction to Computers
• A computer is a device capable of
– performing computations and
– making logical decisions
– at speeds millions (even billions) of times faster than
Trivia:
human beingscan
A supercomputer cando[Deitel and
in a day Deitel].
what a dual-core personal
• computer
Many would
of today's personal
take 160 years computers
to complete have
[techradar.com]
frequencies in GHz range.
• What is the speed of the fastest computer in he
world??
• What is the speed of your computer??
Introduction to Computers
• Computers process data under the control of
sets of instructions called computer programs.
• A computer consists of various devices
referred to as hardware (e.g., the keyboard,
screen, mouse, hard disk, memory, DVDs and
processing units).
• The programs that run on a computer are
referred to as software.
Computer Organization
1. Input unit
• It obtains data and computer programs from input devices for
example, keyboards, mouse, camera, etc.
2. Output unit.
• It takes processed information and places it on various output
devices to make the information available for use outside the
computer. For example, monitors, screen, printer or can be used to
control other devices.
3. Memory unit.
• It stores computer programs while they are being executed.
However, the memory unit only stores information temporarily. RAM
is a part of the memory unit.
Computer Organization
4. Arithmetic and logic unit (ALU).
• It is responsible for performing calculations, such as addition, subtraction,
multiplication and division and for checking whether two numbers are
equal.
5. Central processing unit (CPU).
• It coordinates and supervises the operation of the other sections. The CPU
tells the input unit when information should be read into the memory unit,
tells the ALU when information from the memory unit should be used in
calculations and tells the output unit when to send information from the
memory unit to certain output devices.
6. Secondary storage unit.
• Programs or data not actively being used by the other units normally are
placed on secondary storage devices, such as CDs or DVDs until they are
again needed.
History of C/C++
BC Languages such as FORTRAN, COBOL, ALGOL,
Early
PL/I and others.An official C++ standard is
adopted.
1970 Brian Kernigham and Dennis Ritchie invent C.
The language they used for inspiration was
called “ B”
1980 Bjarne Stroustrup created “C with Classes.”
Lecture 2
A basic program
// ------------------------------------------------------------
// hello.cpp is a demonstration program
#include <iostream>
int main ( )
{
std::cout << "Hello C++ World"<<std::endl;
return 0;
}
A basic program
// ------------------------------------------------------------
// hello.cpp is a demonstration program
#include <iostream>
using namespace std;
int main ( )
{
cout << "Hello C++ World" << endl;
return 0;
}
A basic program
• Programs typically contain the following
elements:
– Descriptive comments (double forward slash // or /* … */)
– Include files
– Declarations: function prototypes and global variables
– Functions including exactly one main function
{ operator
{ operator
• Declaration format:
– type name; //comment
– Examples:
– int sum; //stores ‘sum’ in int type variable
– float answer; //stores ‘answer’ in float type variable
Variable Declaration
• Once the variable has been declared, it can be
used in assignment statements
• Sum = 2457 + 5363;
• Answer = 2.456+3.2;
#include <iostream>
int main ( )
{
int num1 ;
int num2 ;
int sum; Standard input stream
• Nondestructive Process
– Whenever a value is read from a memory location,
the value of that variable in that memory location
remains unchanged.
Memory
• For example
sum = num1 + num2;
// add the nums and store result in sum
– The values of ‘num1’ and ‘num2’ will be read out
and used in the calculation of sum. So it will be a
nondestructive process.
– However, the result of the addition process will be
stored in the variable ‘sum’. So it will be a
destructive process.
• Thus, it is always best to declare a variable as null or
zero.
Operators
• “Operators are words or symbols that cause a program to do something to variables.”
OPERATOR TYPES:
Type Operators Usage
Arithmetic ‘+’ ‘-’ ‘*’ ‘/’ ‘%’ a+b a-b a*b a/b a%b
Arithmetic ‘+=’ ‘-=’ ‘*=’ ‘/=’ ‘%=’ a+=b is the same as a=a+b
assignment a-=b a*=b a/=b a%=b
Increment and ‘++’ ‘- -’ a++ is the same as a=a+1
decrement a-- is the same as a=a-1
Relational ‘<’ ‘>’ ‘<=’ ‘>=’ ‘==’ ‘!=’
Logical ‘&&’ ‘||’ ‘!’
Bitwise ‘&’ ‘|’ ‘^’ ‘~’ ‘<<’ ‘>>’
Operator Precedence
Polynomials in C++
• In algebra
𝑎+𝑏+𝑐+𝑑+𝑒
𝑚=
5
• In c++
𝑚 = (𝑎 + 𝑏 + 𝑐 + 𝑑 + 𝑒)/5
𝑦= 𝑎𝑥 2 + 𝑏𝑥 + 𝑐
2nd Degree Polynomial
𝑦= 𝑎𝑥 2 + 𝑏𝑥 + 𝑐
Summary
• By the end of this lecture, you should know
– how to write a basic program, declare variable and
input/output statements.
– the different number systems and their inter-
conversions.
– The basic concept of what memory is and how it is
used.
– Arithmetic Operators and their precedence