Week 02 ProgrammingBasics 09022025 101952pm 2
Week 02 ProgrammingBasics 09022025 101952pm 2
COMPUTER
PROGRAMMING
Programming Basics
What will be discussed
2
Can’t you
see? Neo is
here.
Computer Programmin g(CSC-113) - Fall 2019
Hierarchy of Programming
6
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=euc-kr">
<title>▒경희대학교 전자정보대학▒</title>
</head>
<frameset rows="1*" cols="100%" border="0">
<frame name="electronic" scrolling="auto"
marginwidth="0" marginheight="0"
src="electronic/main.php">
<noframes>
<body bgcolor="#FFFFFF" text="#000000"
link="#0000FF" vlink="#800080" alink="#FF0000">
<p> </p>
</body>
</noframes>
</frameset>
</html>
Examples of ProgrammingLanguage
- COBOL (COmmon Business-Oriented Language)
$ SET SOURCEFORMAT"FREE"
IDENTIFICATION DIVISION.
PROGRAM-ID. Multiplier.
AUTHOR. Michael Coughlan.
* Example program using ACCEPT, DISPLAY and MULTIPLY to
* get two single digit numbers from the user and multiply them together
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Num1 PIC 9 VALUE ZEROS.
01 Num2 PIC 9 VALUE ZEROS.
01 Result PIC 99 VALUE ZEROS.
PROCEDURE DIVISION.
DISPLAY "Enter first number (1 digit) : " WITH NO ADVANCING.
ACCEPT Num1.
DISPLAY "Enter second number (1 digit) : " WITH NO ADVANCING.
ACCEPT Num2.
MULTIPLY Num1 BY Num2 GIVING Result.
DISPLAY "Result is = ", Result.
STOP RUN.
Brief History of C++
11
Structure of a C++ Program
11
Pre-compiler directive
Opening brace
Closing brace
Opening brace
Closing brace
Hello World!
#include <iostream>
“I want to use a predefined library called iostream”
Always start with a ‘#’
iostream: a library for inputs (from e.g., a user) and outputs
(to e.g., the monitor)
“using” Directives
14
using namespace s t d ;
“I want to use objects in a name group
‘std’ ”
Tells the compiler where to look for names
in the library
Can deal with the situation where two or
i n t main()
The main body of the program.
Start of comment
End of comment
Start of comment
End of comment
Nested BlockCommentsareInvalid
17
Variables
18
Memory
Address of memory:
Hard to remember
Identifier: name of
address
Variables and Identifiers
20
Memory
Identifiers
studentID
studentGrade1
studentGrade2
Variables and Identifiers
Memory
studentID
studentGrade
studentName
In program
2 Bytes 4 Bytes
2 or 4 Bytes 8 Bytes
4 Bytes 10 Bytes
26
Value Type
Type Sign Byte Minimum value Maximum value
signed -32,768 32,767
short int/short 2
unsigned 0 65,535
signed -32,768 32,767
int (PC) 2
unsigned 0 65,535
signed -2,147,483,648 2,147,483,647
int (Mainframe) 4
unsigned 0 4,294,967,295
signed -2,147,483,648 2,147,483,647
long int/long 4
unsigned 0 4,294,967,295
27
Variables Declaration
28
Variable Initialization
29
Assignment Operators
Arithmetic operators
+ (Addition)
- (Subtraction
* (Multiplication)
/ (Division)
% (modulo)
34
C++ ExpressionFormat
Operators
Operators
36
Sizeof operator
Example
A=sizeof(b);
Compound Assignment
37
Examples
Standard streams
38
i n t x = 42;
cou t. w idth (5 ) ;
cout << x << ‘ \ n ’ ; // Outputs 42
cout << x << ‘ \ n ’ ; // Outputs 42
More about cout
44
i n t x = 42;
cout.width(5);
cou t. f i l l ( ‘ * ’ ) ;
cou t << x << ‘ \ n’ ; / / Ou tput s * * * 42
More about cout
47
#include <iomanip.h>
i n t x = 42;
cout << o c t << x << e n d l ; / / Outputs 52\n
cout << hex << x << e n d l ; / / Outputs 2a\n
cout << dec << x << e n d l ; / / Outputs 42\n
Example codesreading (Program 2-2)
#include <iostream>
using namespace s t d ;
Welcome. This program adds
int main (void)
three numbers. Enter three numbers
{
in the form: nnn nnn nnn <return>
11 22 33
int a;
int b; The total is: 66
int c;
int sum; Thank you. Have a good day.
cout << "Welcome. This program adds\n";
cout << " t h r e e numbers. Enter three numbers\n";
cout << " i n the form: nnn nnn nnn < r e t u r n > \ n " ;
In this lecture …
What is structure of C++?
What is variable and Identifier?
What Is Standard Data Types?
What are operators in the language?
What are strems?
ANY QUERY?
53 Sample examples
See examples provided in chapter 4 on introduction to
programming in C++ BY Dian Zak