CSC 3 S2

Cards (23)

  • <iostream> : Contains function prototypes for the C++ standard input and standard output functions. This header file replaces header file <iostream.h>
  • <iomanip> : Contains function prototypes for stream manipulators that format streams of data. This header file replaces header file <iomanip.h>
  • <cmath> : Contains function prototypes for math library functions. This header file replaces header file <math.h>
  • <cstdlib> : Contains function prototypes for conversions of numbers to text, text to numbers, memory allocation, random numbers and various other utility functions. This header file replaces header file <stdlib.h>.
  • <ctime> : Contains function prototypes and types for manipulating the time and date. This header file replaces header file <time.h>
  • Important Component/Features of C++ Language
    1. Comment
    2. Header file & preprocessor directive
    3. Function
    4. Body
  • Comment:
    //Author-ICT Lecturer /* My first program in C++ and there will be more programs after this"/
  • Header file : #include <iostream> using namespace std;
  • Function :
    int main ()
    {
  • Body: cout <<"Hello World!";
    cout <<"\n";
    system ("PAUSE");
    return 0;
    }
  • The purpose to insert a comment: 1. To document a program
    2. To improve the program readability
  • Line comment : discards everything from where the pair of slash signs (//) are found up to the end of that same line @ normally used for single line comment
  • Block comment discards everything between the /* and the first appearance of the */ with the possibility of including multiple lines @ possibly containing many lines
  • Header file is a text file containing small bits of program code, which is used to describe the contents of the main body of code to other modules
  • Header file:
    1. <iostream>
    2. <cmath>
  • Preprocessor directive
    1. #include
  • #include <iostream> : declare objects that control reading from and writing to the standard streams
  • #include <iostream> : cin, cout, DLL
    cin : console input
    cout : console output
  • #include<cmath> : Mathematical declarations to perform calculations
  • #include<cmath> : pow, sqrt
    pow : Raise to power
    sqrt : Return the square root of x
  • Example
    cout<<"The square root of the radius is: "<<sqrt(radius)<<endl;
    cout<<"The area of the circle is: "<<3.1416 pow(radius, 2)<<endl;
  • Function: a group of code statements which are given a name
  • BODY The body may consists of: 1. Reserved word 2. Variable declaration 3. Input/Output console 4. C++ statement 5. Return statement