Programming Fundamentals Lecture #1, Slides of Software Engineering

The first lecture of a programming fundamentals course. It covers the history of C++ and its relationship with C, the C++ standard library, and basic programming concepts such as input/output and functions. The lecture also includes sample code for a 'Hello World' program and an 'Add Integer' program.

Typology: Slides

2021/2022

Available from 11/16/2022

razaroghani
razaroghani 🇵🇰

4.5

(4)

151 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
programming Fundamentals
Lecture # 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Programming Fundamentals Lecture #1 and more Slides Software Engineering in PDF only on Docsity!

programming Fundamentals

Lecture # 1

Contents of Today’s Lecture

Welcome Course Syllabus Tentative Schedule An Important Note to the Students Introduction

OOP – Object Oriented Programming

  • Programming Languages
    • Procedural
    • Object Oriented
  • Procedural Programming Languages (action oriented) LOAD D MUL E ADD C STOR Y LOAD A SUB B DIV Y STOR Y - Non-Procedural Programming Languages int main() { int a, b, c, d, e, y; …. y=(a-b)/(c+d*e); } C DE A B Y

C++ History

  • BCPL (1967)
    • Martin Richards
    • Language for writing OS & compilers
  • B (1970)
    • Ken Thompson
    • Used to create early version of UNIX @ Bell
  • C
    • Dennis Ritchie @ Bell
    • Hardware Independent
  • C++ (1980)
    • Bjarne Stroustrup
    • OO Extension of C

BCPL B

C

C++

C++ Std Library

  • C++ programs consist of classes & functions
  • Programmers can also use existing classes and

functions provided in the C++ standard library

(for saving time)

  • How to learn C++? 2 Aspects:
    • Learn how to code in C++
    • Learn how to use the C++ standard library
  • A Note on Standard Libraries
    • Some are released by compiler vendors
    • Others are released by independent vendors
  • Reference: Plauger’s Standard C Library

C++ Development Environment

  • C++ System Parts
    • Development Environment
    • Language
    • Standard C++ Library
  • Phases:
    • Edit
    • Pre-Process
    • Compile
    • Link
    • Load
    • Execute
      • Development Tools:
        • Borland C++ Builder
        • Microsoft Visual C++
        • GNU C++

Other details

  • What If Scenario’s:
    • A Program fails?
    • Divide by Zero? (Illegal operation)
  • Input/Output
    • cin
      • standard input stream
      • normally keyboard but c. b. changed
    • cout
      • Standard output stream
      • normally screen but c. b. changed
    • cerr
      • Standard error stream
      • Display error messages (on screen)

Down to Business

  • Sample Hello World 1 // Fig. 1.2: fig01_02.cpp 2 // A first program in C++. 3 #include 4 5 // function main begins program execution 6 int main() 7 { 8 std::cout << "Welcome to C++!\n"; 9 10 return 0 ; // indicate that program ended successfully 11 12 } // end function main Welcome to C++!

Function main returns an

integer value.

Statements end with a semicolon ; Pre-processor directive is excluded \ is an escape sequence \n new line \t tab \r cursor to beginning of current line \a sound alert \ used to print backslash character \’ single quote character \” double quote character

Name cout belongs to

namespace std.

Keyword return is one of

several means to exit function;

value 0 indicates program

terminated successfully.

1 // Fig. 1.6: fig01_06.cpp 2 // Addition program. 3 #include 4 5 // function main begins program execution 6 int main() 7 { 8 int integer1; // first number to be input by user 9 int integer2; // second number to be input by user 10 int sum; // variable in which sum will be stored 11 12 std::cout << "Enter first integer\n"; // prompt 13 std::cin >> integer1; // read an integer 14 15 std::cout << "Enter second integer\n"; // prompt 16 std::cin >> integer2; // read an integer 17 18 sum = integer1 + integer2; // assign result to sum 19 20 std::cout << "Sum is " << sum << std::endl; // print sum 21 22 return 0 ; // indicate that program ended successfully 23 24 } // end function main Declare integer variables. Use stream extraction operator with standard input stream to obtain user input. Stream manipulator std::endl outputs a newline, then “flushes output buffer.”On some systems where outputs accumulate in the machine until there are enough to make it display on the screen.It forces any accumulated aoutput to be displayed at that moment Concatenating, chaining or cascading stream insertion operations. Calculations can be performed in output statements: alternative for lines 18 and 20: std::cout << "Sum is " << integer1 + integer2 << std::endl;

Reading Material

  • Week 1
    • From Chapter 1
      • Software engineering case study: Introduction to object technology and UML, 5

th

Edition, pp

  • History of C and C++, pp
  • C++ standard library, pp
  • Typical C++ development environment, pp