Lecture 1 CSC 202
Lecture 1 CSC 202
CSC 202
Computer Programming-II
Course Introduction
The goal of this course is to equip students with the necessary skills for
programming using the ANSI (American National Standards Institute)
standards. It aims to provide a solid understanding of the C++
Programming Language and cover special topics in Advanced
Programming.
Course Outline information
down programming.
10 Method: in deep look
11 Constructors/Destructors
12 Function Overloading &Overriding
13 Memory Management and OOP Concept
14 Free Lecture/Revision week
15 Final Examination week
Lecture
1
Introduction to C++
What is C++ Programming?
#include<iostream> in C++
#include<stdio.h> in C language
int main()
{
cout << "C++ is power
programming."; printf(“ C is power
Programming”); return 0;
}
• C++ provides built-in data types that correspond to
integers, characters, floating-point values, and
Boolean values.
x = 4 + 2;
Example
int main () {
int x;
x = 4 + 2;
cout << x /
3 << " " <<
x * 2;
return 0;
Example: User Inputting from
keyboard
# include <iostream >
using namespace std ;
int main () {
int x;
cin >> x;
cout << x / 3 << ’ ’ << x *
2<<endl;
return 0;
}
Keyword/
Reserve
words in C+
+
At the core of the C++ type
system are the seven basic data
types shown here:
Double vs Float
The main difference between `float` and `double` data types lies in their precision. `double` has double the
precision of `float` (64 bits vs. 32 bits), making it capable of representing larger and more precise floating-
point values. However, `double` consumes more memory than `float`. Use `double` when higher precision
is required, and `float` when memory efficiency is a priority.
Lecture
2
Control Structures in C++
Control structures are portions of program code
that contain statements within them and,
Control depending on the circumstances, execute these
Structur statements in a certain way. There are typically
es two kinds:
conditionals and loops.
Condition In order for a program to change its behavior
als
depending on the input, there must a way to test
that input. Conditionals allow the program to
check the values of variables and to execute (or
not execute) certain statements.
int main(){
int number = 6;
return 0;
}
if(condition)
{
statementA1
statementA2
…
The if- }
else else
{
form statementB1
statementB2
…
}
Example
#include <iostream>
s…
using namespace std;
int main(){
int number = -3;
if(condition)
statementA1
else
statement
B1
The else if is used to decide between two or more
blocks based on multiple conditions:
if(condition1)
{
statementA1
The …
statementA2
else if }
else if(condition2)
conditio {
statementB1
n statementB2
…
}
Example if(number > 0){
cout << "This means that it is a positive integer" << endl;
s…
#include <iostream>
}
while and {
statement1
do- while statement2
…
}
While As long as condition holds, the block of
e.. }
return 0;
}
do
{
statement1
statement2
…
}
while(condit
ion);
Exampl
e…
using namespace std;
int main()
{
int x = 0;
do
{
x++;
cout<<x<<"\n";
return 0;
} while(x <= 10);
}
Remar
k…
The block of statements is executed and then, if the condition holds, the
program returns to the top of the block. Curly braces are always
required. Also note the semicolon after the while condition.
The For loop
The for loop works like the while loop but with some change in
syntax: for(initialization; condition; incrementation)
{
statement1
statement2
…
}
Remar
k…
The for loop is designed to allow a counter variable that is initialized at
the beginning of the loop and incremented (or decremented) on each
iteration of the loop. Curly braces may be omitted if there is only one
statement.
Here is an example:
Example…
for(i=0;i<=10;i++)
cout<<i<<endl;
return 0;
}
Nested Control Structures
It is possible to place ifs inside of ifs and loops inside of loops by simply
placing these structures inside the statement blocks. This allows for
more complicated program behavior. Here is an example using nesting if
conditionals
Exampl
e…
Question
s?