Programming Fundamental. Instructor Name: Lecture-2

Similar documents
Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Chapter One Introduction to Programming

C++ Language Tutorial

Introduction to Python

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Moving from CS 61A Scheme to CS 61B Java

Chapter 2: Elements of Java

Computer Programming C++ Classes and Objects 15 th Lecture

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 3: Input/Output

Introduction to Visual C++.NET Programming. Using.NET Environment

Pemrograman Dasar. Basic Elements Of Java

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Basics of I/O Streams and File I/O

The C Programming Language course syllabus associate level

Variables, Constants, and Data Types

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

Sequential Program Execution

Comp151. Definitions & Declarations

- Hour 1 - Introducing Visual C++ 5

Informatica e Sistemi in Tempo Reale

Example of a Java program

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

C++ INTERVIEW QUESTIONS

Decision Logic: if, if else, switch, Boolean conditions and variables

Introduction to Java

Sources: On the Web: Slides will be available on:

PIC 10A. Lecture 7: Graphics II and intro to the if statement

Introduction to Java. CS 3: Computer Programming in Java

Appendix K Introduction to Microsoft Visual C++ 6.0

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

C++ Input/Output: Streams

An Incomplete C++ Primer. University of Wyoming MA 5310

Moving from C++ to VBA

Outline Basic concepts of Python language

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

Lecture 5: Java Fundamentals III

Install Java Development Kit (JDK) 1.8

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

csce4313 Programming Languages Scanner (pass/fail)

Lecture 2 Notes: Flow of Control

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Computer Programming Tutorial

VB.NET Programming Fundamentals

Introduction to Python

Programming Languages CIS 443

Chapter 3. Input and output. 3.1 The System class

Ubuntu. Ubuntu. C++ Overview. Ubuntu. History of C++ Major Features of C++

How to translate VisualPlace

COSC282 BIG DATA ANALYTICS FALL 2015 LECTURE 2 - SEP 9

Welcome to Introduction to programming in Python

Learning Objective. Purpose The purpose of this activity is to give you the opportunity to learn how to set up a database and upload data.

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

JavaScript: Control Statements I

CS106A, Stanford Handout #38. Strings and Chars

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

Chapter 13 - The Preprocessor

Lecture 1 Introduction to Java

Data Storage: Each time you create a variable in memory, a certain amount of memory is allocated for that variable based on its data type (or class).

Member Functions of the istream Class

CS 106 Introduction to Computer Science I

CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing

VHDL Test Bench Tutorial

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

sqlite driver manual

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++)

Programming and Data Structures with Java and JUnit. Rick Mercer

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

Recognizing PL/SQL Lexical Units. Copyright 2007, Oracle. All rights reserved.

Object-Oriented Programming in Java

Number Representation

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

PL / SQL Basics. Chapter 3

The programming language C. sws1 1

A Brief Introduction to MySQL

Passing 1D arrays to functions.

Hands-on Exercise 1: VBA Coding Basics

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

6.170 Tutorial 3 - Ruby Basics

Oracle Database: SQL and PL/SQL Fundamentals

Repetition Using the End of File Condition

UEE1302 (1102) F10 Introduction to Computers and Programming

Time Clock Import Setup & Use

Fundamentals of Programming

Java Basics: Data Types, Variables, and Loops

Transcription:

Programming Fundamental Instructor Name: Lecture-2

Today s Lecture What is Programming? First C++ Program Programming Errors Variables in C++ Primitive Data Types in C++ Operators in C++ Operators Precedence 2

What is Programming? Computer programming (often shortened to programming) is a process that leads from an original formulation of a computing problem to executable computer programs. Programming involves activities: Analysis Develop understanding Generating algorithms Verification of requirements of algorithms including their correctness and resources consumption, and Implementation of algorithms in a target programming language (C++ in our case) 3

First Program in C++ using namespace std; #include <conio.h> #include <iostream> main() { } cout<<" Welcome to GC University"; getch(); # is HASH and also called SHARP #include: This is a pre-processor directive. It is not part of our program; it is an instruction to the compiler. It tells the C compiler to include the contents of a file i.e. iostream. The compiler knows that it is a system file, and therefore looks for it in a special place. 4

First Program in C++ Namespace in C++ Different libraries may have functions or variables with same name A namespace is designed to overcome this difficulty by using additional information to differentiate similar functions, classes, variables etc. with the same name available in different libraries. Using namespace, you can define the context in which names are defined. In essence, a namespace defines a scope. A namespace definition begins with the keyword namespace followed by the namespace name as follows: namespace namespace_name; 5

First Program in C++ The Using Directive To call the namespace-enabled version of either function or variable, prepend the namespace name as follows: name_space::code; You can also avoid prepending of namespaces with the using namespace directive which tells the compiler that the subsequent code is making use of names in the specified namespace The using directive can also be used to refer to a particular item within a namespace. For example, using std::cout; 6

First Program in C++ #include directive Both user and system header files are included using the preprocessing directive #include. It has two variants: #include <file> - used for system header files. It searches for a file named file in a standard list of system directories. #include "file - used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the quote directories and then the same directories used for <file>. 7

First Program in C++ main() Function All C++ Must have main() function When the operating system runs a program in C, it passes control of the computer over to that program. The main() function uses its parentheses() to contain any information typed after the program name at the command prompt. This is useful for more advanced programming. The curly braces {} are used for organization. They contain programming instructions that belong to the function. Those programming instructions are how the function carries out its task or does its thing. Without main() function a C++ program will not execute. 8

First Program in C++ cout in C++ The predefined object cout is an instance of ostream class. The cout object is said to be "connected to" the standard output device, which usually is the display screen. The cout is used in conjunction with the stream insertion operator, which is written as << which are two less than signs indicates the direction of data cout<<" Welcome to GC University"; Thing between the double quotes ( ) is known as character string, will display it on the screen. 9

First Program in C++ Semicolon ; in C++ The semicolon is part of the syntax of C++. It tells the compiler that you're at the end of a command. The semicolon (;) will be used at the end of the every statement other wise compiler will report an error. The error reported as result of missing semicolon(;) is referred as syntax error 10

Programming Errors Three Types of Errors 1) Syntax Error Detected By the Compiler 2) Logical Error Produce incorrect result due to wrong logic 3) Runtime Error Causes the program to abort 11

Variables in C++ What is Variable? A variable is used to store a piece of data for processing. It is called variable because you can change the stored value with new value during program execution A variable is a named storage location, that stores a value of a particular data type 12

Variables in C++ Variable 13

Variables in C++ Dissecting a Variable In a Program a variable Consists of: Name: Used as identifier for the variable. e.g. radius, area, age Type: Represents the type of data a variable will hold. e.g. Integer, Float Size: Represents memory size a variable require to store a value. It depends on the type of variable and compiler that compiles the code. Value: Actual value that is stored in variable 14

Variables in C++ Variable Declaration Rule A variable must start with: Character Underscore _ (Not recommended) A variable must [recommended] Consists of sequence of Upper/lower case Characters, numbers (0-9), _ up to certain length have a name that is self-descriptive and closely reflects the meaning of the variable e.g. age, user_name, email, address,ph_no not be of single character and meaning less unless they are common names like x,and z for coordinators 15

Variables in C++ Variable Declaration Rule It is perfectly okay to use long names of says 30 characters to make sure that the name accurately reflects its meaning! Use singular and plural nouns prudently to differentiate between singular and plural variables. For example, you may use the variable row to refer to a single row number and the variable rows to refer to many rows. 16

Variables in C++ Variable Declaration Rule Prohibition: White space (blank, tab, new-line) and other special characters (such as +, -, *, /, @, &, commas, etc.) are not allowed. It cannot begin with a digit. An identifier cannot be a reserved keyword or a reserved literal (e.g. int, double, if, else, for, main,while,break). Identifiers are case-sensitive. E.g. A rose is NOT a Rose, and is NOT a ROSE. 17

Variable Data Types Data Types While doing programming in any programming language, you need to use various variables to store various information. Variables are nothing but reserved memory locations to store values, this means variable reserve some space in memory. Information store in variables may be of various data types like character, wide character, integer, floating point, double floating point, boolean etc. Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory. A data type is set of values and operations performed on those value 18

Variable Data Types Primitive Data Types Integers: used to store numerical values(signed or unsigned). Characters: used to store Characters A to z. Every alphanumeric digit and or symbol encoded in single quotes in considered a character. Floating-point: used store the decimal point numbers. Boolean: A special type called bool, which takes a value of either true or false. 19

20