Slide (1) Introduction
Slide (1) Introduction
Introduction
Second term
2021
2 Points to be covered:
Why This Course?
Why C++?
What is development tools?
Starting to write simple C++ program.
Review of basics taken before:
Variables
Reading and writing to user
Operators
Conditional Execution
Iteration (loops)
Outline of course content
3 Why This Course?
To help students improve or acquire the programming
skills they need for research in earth sciences or
engineering.
Learning how to develop a software is needed in all
fields.
A computer program is an example of computer
Software. Software makes a computer a truly universal
machine transforming it into the proper tool for the task
at hand.
Computing professionals known as software engineers
develop software to drive particular systems .
The software is written using programming languages
like : java , C++, python, C#, and others.
In this course we will learn C++.
4 Why C++?
C++ is a MUST for students and working professionals to
become a great Software Engineer. I will list down some
of the key advantages of learning C++:
C++ is very close to hardware, so you get a chance to work
at a low level which gives you lot of control in terms of
memory management and better performance.
C++ programming gives you a clear understanding about
Object Oriented Programming.
C++ is from the most widely used programming languages
in application and system programming. So you can
choose your area of interest of software development.
C++ really teaches you the difference between compiler,
linker and loader, different data types, classes, variable
types their scopes etc.
5 What is development tools?
Software can be represented by printed words and
symbols that are easier for humans to manage than
binary sequences (Machine language).
The development tools exists that automatically convert a
higher-level description of what is to be done into the
required lower-level code.
The higher-level language code is called Source code.
The compiled machine language code is called the
Target code. The Compiler translates the source code into
the target machine language.
A debugger allows a programmer to more easily trace a
program’s execution in order to locate and correct errors
in the program’s implementation.
Examples of known C++ tools:
Dev C++, Borland, Visual studio, Code blocks, and etc.
6
Starting to write a simple C++
program.
Properly written C++ programs have a particular structure.
The syntax must be correct, or the compiler will generate
error messages known as (syntax error) and not produce
executable machine language.
Types of errors in programming:
Syntax error.
Logic error: writing the logic of code wrong.
Compilation error: results after compiling program like dividing
by zero.
7
Starting to write a simple C++
program.
Let us look at a simple code that would print the words Hello
World.
#include <iostream>
using namespace std;
Variables
Reading and writing to user
Expressions and Arithmetic
Conditional Execution
Iteration
10
Review on basics (variable)
While writing program in any language, you need to use
various variables to store various information. Variables are
nothing but reserved memory locations to store values.
Following table lists down seven basic C++ data types:
11 Review on basics (variable)
#include <iostream>
using namespace std;
int main() {
cout << "Size of char : " <<sizeof(char) << endl;
cout << "Size of int : " << sizeof(int) << endl;
cout << "Size of short int : "<<sizeof(short
int)<< endl;
cout << "Size of long int :"<< sizeof(long int) <<
endl;
cout << "Size of float : " << sizeof(float) <<
endl;
cout << "Size of double : " << sizeof(double) <<
endl;
return 0;
}
12
Review on basics (reading and writing)
To read a value from user we use cin>>.
Example
int x; cin>>x;
int main () {
// local variable declaration:
int a = 100;
return 0;
}
#include <iostream>
using namespace std;
20
int main () {
// local variable declaration:
char grade = 'D';
Switch
switch(grade) {
case 'A' :
cout << "Excellent!" << endl;
break;
case 'B' :
case 'C' :
cout << "Well done" << endl;
break;
case 'D' :
cout << "You passed" << endl;
break;
case 'F' :
cout << "Better try again" << endl;
break;
default :
cout << "Invalid grade" << endl;
}
cout << "Your grade is " << grade << endl;
return 0;
}
Review on basics
21
(Iterative)
A loop statement allows us to execute a statement or group of
statements multiple times and following is the general from of a
loop statement in most of the programming languages:
Review on basics
22
(Iterative)
C++ programming language provides following types of
Iterative statements.
Review on basics
23 (Iterative)
While
#include <iostream>
using namespace std;
int main () {
// Local variable declaration:
int a = 10;
return 0;
}
Review on basics
24
(Iterative)
For
#include <iostream>
using namespace std;
int main () {
// for loop execution
for( int a = 10; a < 20; a = a + 1 ) {
cout << "value of a: " << a << endl;
}
return 0;
}
Review on basics
25
(Iterative)
Do-while
#include <iostream>
using namespace std;
int main () {
// Local variable declaration:
int a = 10;
// do loop execution
do {
cout << "value of a: " << a << endl;
a = a + 1;
} while( a < 20 );
return 0;
26
Outline of course
New contents going to be covered during course:
Functions
Arrays
Pointers
Structure
Strings
Files and exception handling
Object oriented programming.
Namespace and Generic