KEMBAR78
l1-introduction_to_computers_and_c_programming.pptx
Introduction to Computers
and C++ Programming
Lecture 1
Outline
Main Components of a Computer
Input device(s)
CPU
Main memory
Secondary memory
Output device(s)
00011111
10101100
11100011
• Main memory is divided into numbered locations called
bytes.
• The number associated with a byte is called its address.
• A group of consecutive bytes is used as the location for a
a data item, such as a number or letter.The address of the
first byte in the group is used as the address of this larger
memory location.
Bytes and Addresses
Computer Systems
Software
Operating
System
Programs
Haedware
PCs Workstations Mainframes
• A program is set of instructions for a computer to follow
• Whenever we give a computer both a program to follow
and some data for the program, we are said to be
running the program on the data, and the computer is
said to execute the program on the data.
What is a program?
High Level Languages
 C++
 Java
Low Level Languages
 Assembly Language
• Add XY Z
 Machine Language
• 00011101
Languages
Programs that translate a high-level language like C++ to
a machine-language that the computer can directly
understand and execute.
Compilers
C++ program
Source Code
Compiler
Object code for C++
program Linker
Object code for
other routines
Preparing a C++ program for Running
Problem-solving phase Implementation phase
Start
Problem
definition
Algorithm
design
Desktop
testing
Translating
to C++
Testing
Working
Program
Program Design Process
1. Specify the problem requirements.
2. Analyze the problem.
Input:
Output:
Formulas:
3. Design the algorithm to solve the problem.
4. Implement the algorithm.
5.Test and verify the completed program.
6. Maintain and update the program.
The Software Development
Method
1. Analysis and specification of the task (problem
definition)
2. Design of the software (algorithm design)
3. Implementation (coding)
4. Testing
5. Maintenance and evolution of the system
6. Obsolescense
The Software Life Cycle
BCPL
B programming language
C programming language
C++
• Dennis Ritchie
• 1970s
• Bjarne Stroustrap
• 1980s
Introduction to C++
#include <iostream>
using namespace std;
int main()
{
Variable_Declarations
Statement_1
Statement_2
…
Statement_Last
return 0;
} Program ends here
Program starts here
Layout of a C++ Program
#include <iostream>
using namespace std;
int main()
{
Variable_Declarations
Statement_1
Statement_2
…
Statement_Last
return 0;
}
include directive
standard namespace
main function
return statement
executable statements
Layout of a C++ Program
#include <iostream>
using namespace std;
int main()
{
int number1, number2, sum;
cout << "Enter first number: ";
cin >> number1;
cout << "Enter second number: ";
cin >> number2;
sum = number1 + number2;
cout << "Sum = " << sum << “n”;
return 0;
}
Sample C++ Program
Compiling and Running a C++
Program
Bug
A mistake/error in the program
Debugging
The process of eliminating bugs in a program
Testing and Debugging
• Types of program errors:
• Syntax errors
• Violations of the rules of the programming language
• Run-time errors
• Detected by computers when the program is run (numeric
calcualtions)
• Logic errors
• Mistakes in the underlying algorithm or translating the
algorithm into C++ language
Testing and Debugging
Try this:
Write a program that
displays the product
of two integers
#include <iostream>
using namespace std;
int main()
{
int number1, number2, product;
cout << "Enter first number: ";
cin >> number1;
cout << "Enter second number: ";
cin >> number2;
product =…………………..?
cout << “Product = " << product << “n”;
return 0;
}
Sample C++ Program
ThankYou

l1-introduction_to_computers_and_c_programming.pptx

  • 1.
    Introduction to Computers andC++ Programming Lecture 1
  • 2.
  • 3.
    Main Components ofa Computer Input device(s) CPU Main memory Secondary memory Output device(s) 00011111 10101100 11100011
  • 4.
    • Main memoryis divided into numbered locations called bytes. • The number associated with a byte is called its address. • A group of consecutive bytes is used as the location for a a data item, such as a number or letter.The address of the first byte in the group is used as the address of this larger memory location. Bytes and Addresses
  • 5.
  • 6.
    • A programis set of instructions for a computer to follow • Whenever we give a computer both a program to follow and some data for the program, we are said to be running the program on the data, and the computer is said to execute the program on the data. What is a program?
  • 7.
    High Level Languages C++  Java Low Level Languages  Assembly Language • Add XY Z  Machine Language • 00011101 Languages
  • 8.
    Programs that translatea high-level language like C++ to a machine-language that the computer can directly understand and execute. Compilers
  • 9.
    C++ program Source Code Compiler Objectcode for C++ program Linker Object code for other routines Preparing a C++ program for Running
  • 10.
    Problem-solving phase Implementationphase Start Problem definition Algorithm design Desktop testing Translating to C++ Testing Working Program Program Design Process
  • 11.
    1. Specify theproblem requirements. 2. Analyze the problem. Input: Output: Formulas: 3. Design the algorithm to solve the problem. 4. Implement the algorithm. 5.Test and verify the completed program. 6. Maintain and update the program. The Software Development Method
  • 12.
    1. Analysis andspecification of the task (problem definition) 2. Design of the software (algorithm design) 3. Implementation (coding) 4. Testing 5. Maintenance and evolution of the system 6. Obsolescense The Software Life Cycle
  • 13.
    BCPL B programming language Cprogramming language C++ • Dennis Ritchie • 1970s • Bjarne Stroustrap • 1980s Introduction to C++
  • 14.
    #include <iostream> using namespacestd; int main() { Variable_Declarations Statement_1 Statement_2 … Statement_Last return 0; } Program ends here Program starts here Layout of a C++ Program
  • 15.
    #include <iostream> using namespacestd; int main() { Variable_Declarations Statement_1 Statement_2 … Statement_Last return 0; } include directive standard namespace main function return statement executable statements Layout of a C++ Program
  • 16.
    #include <iostream> using namespacestd; int main() { int number1, number2, sum; cout << "Enter first number: "; cin >> number1; cout << "Enter second number: "; cin >> number2; sum = number1 + number2; cout << "Sum = " << sum << “n”; return 0; } Sample C++ Program
  • 17.
    Compiling and Runninga C++ Program
  • 18.
    Bug A mistake/error inthe program Debugging The process of eliminating bugs in a program Testing and Debugging
  • 19.
    • Types ofprogram errors: • Syntax errors • Violations of the rules of the programming language • Run-time errors • Detected by computers when the program is run (numeric calcualtions) • Logic errors • Mistakes in the underlying algorithm or translating the algorithm into C++ language Testing and Debugging
  • 20.
    Try this: Write aprogram that displays the product of two integers #include <iostream> using namespace std; int main() { int number1, number2, product; cout << "Enter first number: "; cin >> number1; cout << "Enter second number: "; cin >> number2; product =…………………..? cout << “Product = " << product << “n”; return 0; } Sample C++ Program
  • 21.