• No results found

CSC 113 Lecture1

N/A
N/A
Protected

Academic year: 2020

Share "CSC 113 Lecture1"

Copied!
40
0
0

Loading.... (view fulltext now)

Full text

(1)

CSC-113

Computer Programming

(2)

MOBILE ALERT

Kindly

Switch Off

your Mobile/Cell Phone

OR

Switch it to Silent Mode Please

(3)

COURSE ASSESSMENT

Home/Assignment --- 20%

Quizzes --- 10%

Mid Term --- 20%

Lab --- 50%

(4)

GOOGLE

SITE ADDRESS

FOR LECTURE NOTES AND STUDY MATERIAL DOWNLOAD, PLEASE VISIT :

https://sites.google.com/site/sumeerahashmics

(5)

Text Book

Computer Science

A Structured Approach : Using C++

(6)

Lecture Outline

Structure of C++ Program C++

Variables

Escape Sequences

I/O Statements

Operators

Precedence of Operators

(7)

Writing, Editing,

Compiling and Linking

1. Editor to create a program. (source program)

2. Compiler translates in to machine language.

(8)

Writing, Editing,

(9)

Structure of a C++

Program

Pre-compiler directive

Pre-compiler directive

Opening brace

(10)

Hello World Program

Without namespace Without namespace

Namespace std contains all the classes, objects and

functions of the standard C++ library.

Namespace std contains all the classes, objects and

functions of the standard C++ library.

#include <iostream> int main () {

std::cout << "Hello world!\n"; return 0;

(11)

Preprocessor Directives

#include <iostream>

“I want to use a predefined library

called iostream”

Always start with a ‘#’

(12)

Directives

using namespace std;

“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

(13)

Main Function

int main()

The main body of the program.

Compiler first tries to locate

“main()” to find where to begin the program

(14)

Comments

Start of comment

End of comment Start of comment

End of comment

Internal program document

(15)

Variables in C++

Named memory locations that have a type

Named: identifier

Type: needs declaration

What you can do with variables

(16)

Variables and

Identifiers

Memory

Address of memory:

Hard to remember

(17)

Variables and Identifiers

Memory

studentID

studentGrade1

studentGrade2

(18)

Variables and Identifiers

Memory

studentID

studentGrade

studentName

(19)

Naming

Identifiers

Allowed characters: A-Z, a-z, 0-9, _ (underscore)

Not allowed to start with a digit. E.g., 3class (x),

class3(o)

The identifier cannot duplicate a reserved word.

e.g., if, case, while…

Good names  descriptive but short

(20)
(21)

Integer and Floating Point

Types

2 or 4 Bytes

4 Bytes 2 Bytes

8 Bytes

(22)

Maximum/Minimum of

Integer Value Type

Type Sign Byte Minimum value Maximum value

short int/short signed 2 -32,768 32,767

unsigned 0 65,535

int (PC) signed 2 -32,768 32,767

unsigned 0 65,535

int (Mainframe) signed 4 -2,147,483,648 2,147,483,647

unsigned 0 4,294,967,295

long int/long signed 4 -2,147,483,648 2,147,483,647

(23)
(24)
(25)

Variable Initialization

Variable declaration ≠ variable initialization

Should be initialized by a programmer before it is

used e.g.,

int count;

(26)

Constants

Data values that cannot be changed during program

execution

E.g.,

3.141592‘d’

(27)
(28)

Escape Sequence

Escape sequences are used to represent certain special characters

within string literals and character literals.

Escape

sequence Description

\' single quote

\" double quote

\? question mark

\\ backslash

\a audible bell

\b backspace

\f form feed - new page

\n line feed - new line

\r carriage return

\t horizontal tab

(29)
(30)

Standard streams

(31)

More about

cout

• width(int) function sets the width for printing a value

Only works until the next insertion command comes

int x = 42;

cout.width(5);

(32)
(33)

More about

cout

• fill(char) function sets the fill character.

The character remains as the fill character until set

again.

int x = 42;

cout.width(5); cout.fill(‘*’);

(34)
(35)

More about

cout

precision (int) sets the number of significant digits

of float type numbers

float y = 23.1415; cout.precision(1);

cout << y << '\n'; // Outputs 2e+01 cout.precision(2);

(36)

More about

cout

• Output Manipulators (not a function)

endl - outputs a new line character, flushes output

dec - sets int output to decimal

hex - sets int output to hexadecimal

oct - sets int output to octal

#include <iomanip.h>

int x = 42;

(37)
(38)
(39)
(40)

References

Related documents

Going forward, regardless of whether a corporate case begins as a civil or criminal inquiry, the DOJ attorneys initially handling the matter will be responsible for notifying the

Basic Occupational Safety and Health (BOSH) Training Administrative and engineering control measures should be implemented to prevent the adverse health effects caused by

When the standard deviation of investment tax shocks is set so that this model reproduces the observed volatility in hours, as Table 2 shows, technology shocks account for 36% of

In particular, the ODL training stimulated physics teachers to: (1) explore, collect and organize new open educational resources on physics remote and.. The relationship between

Another point in which projection resembles repression is that it is not associated with any particular anxiety situation but may be motivated equally by objective anxiety,

[r]

The study population was constituted by 100 consecutive euthyroid obese patients (BMI &gt;30 kg/m 2 ), classified as severely obese (50 females/50 males; mean age, 40.4±12.7 yr;

There are some other techniques more sophisticated that can be used to identify a network traffic that is related to botnets activities, such as Machine Learning [8], however,