CS101 Computer programming and utilization


 Dorthy Simpson
 1 years ago
 Views:
Transcription
1 CS101 Computer programming and utilization Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay Lecture 3, Basic features of C++ Tuesday, 2 August 2011 And Wednesday, 3 August
2 Overview C++ Program structure C++ rules of computing Naming Conventions Data Types Expression evaluation Programming Examples Quiz Dr Deepak B Phatak 2 Lecture 3 Basic features of C++
3 C++ program structure All statements in a C++ program must be written in accordance with rules of syntax The entire program is usually stored in a single file File name of your choice, extension.cpp Examples: P1.cpp AddNumbers.cpp mid_sem_marks_analysis.cpp 3
4 Compiler Directives A C++ program contains certain compiler directives These statement provide information to compiler used during the translation #include <iostream> This directive tells the compiler to include instructions which will enable input and output to be handled properly 4
5 InputOutput in C++ Remember that the input values which we will give will be in the form of ASCII codes of digits, which have to be converted to internal binary form Similarly, C++ converts internal binary numbers to a sequence of ASCII bytes for output Input/output handled as streams of bytes cin and cout work because of this directive 5
6 Conversion of stream elements into numbers 6
7 Compiler Directives Using namespace std; C++ permits names used in our programs, to be grouped and declared in different namespaces Each such namespace itself can be given a name of our choice, say Xspace. Names declared within a namespace must be qualified when used. Thus if a, b are int objects Xspace::a = 5; Xspace::b = 4*xspace::a; Useful for large programs, headache otherwise This statement directs the C++ compiler to use a global standard namespace called std Makes life simpler 7
8 Components of a C++ program In C++, statements can be grouped by enclosing them within a pair of braces, { and } Each such group is treated as a single statement Each program is treated as a function. Functions can be invoked by other programs The main program which we write is treated as a function, which is called by the Operating System 8
9 Components... When we begin executing a program, the OS passes control to the main function OS can pass one or more parameters to it When our program completes its execution, it passes the control back to the OS This requires execution of a return statement 9
10 Components of a C++ program... A program will use several computational objects. Their names and associated data types must be declared in our program The declarations can appear anywhere, but must occur before the objects are first used Put them together at the beginning Comments can be inserted anywhere in a program 10
11 Components... Ignored completely by the compiler Different parts of the program should be written with appropriate indentation Use a tab, or a few blank spaces at the beginning of each line within an identifiable group 11
12 Organization of a C++ program // file add_two_numbers.cpp #include <iostream> using namespace std; // this program reads two integers // and calculates the sum int main() { int A, B, C; cout << Give two numbers ; cin >> A >> B; C = A + B; cout << Sum is << C; return 0; } 12
13 Organization of a C++ program... // file add_two_numbers.cpp #include <iostream> using namespace std; // this program reads two integers // and calculates the sum int main() { int A, B, C; cout << Give two numbers ; cin >> A >> B; C = A + B; cout << Sum is << C; return 0; } Compiler Directives Main program Begins here Stop program execution and return to OS 13
14 Names Names (called identifiers) can consist of letters, digits, and underscore (_) A name must not contain a blank or tab It must begin with a letter or underscore Names can be of any length first 31 symbols should be unique Keywords in C++ cannot be used for our names using, return, int, Meaningful names must be chosen by us. 14
15 What is there in a name? Roll number of a student Value of temperature in degree Centigrade Marks obtained in a quiz 15
16 Names Marks obtained in the semesterend examination 16
17 Objects in C++ In C++, names are used to represent objects Values associated with named objects can change Each object can have a value of certain type Thus every name must have an associated type Constant values used in the program are also objects of a certain type 17
18 Types of values in C++ C provides for several types of values char, int, float, double, void (valueless) bool, wchar_t we will first consider integer and floating point int type is used to represent integer numbers float type used to represent fractional numbers Also used to represent very large values 18
19 Numerical values We write numerical values in a standard manner. For example: Very large and very small values are written in exponential notation [a mantissa and an exponent] 1.24E9, 1.23E5, 6.023E23, 124.0E7, 0.124E10, etc. C++ permits us to write such constant values in our programs, and also accepts these as input. 19
20 Declarations of object names Class or type of name for any object must be explicitly declared in a program The compiler will use such declaration to allocate appropriate memory locations based on the type int i, j, Count, NumberOfTanks, There exist other qualifiers to int type short (2 bytes), unsigned (no sign bit), long (4 or 8 bytes) 20
21 Integer Values Decimal numbers Must begin with a nonzero digit, except when value is The value must be within the prescribed range 0ctal (base 8) numbers written beginning with Hexadecimal (base 16) numbers Written beginning with 0x 0x10 0x2b9 0xAbF 0x100 21
22 Floating point values Standard decimal notation exponential notation with mantissa and exponent 1.2E92E20 22
23 Floating point values... Mantissa precision is 6 digits minimum exponent range is 37 to +37 minimum We use decimal notation while writing these numbers in our programs, or while giving input Such values are always converted to internal binary representation 23
24 Floating point objects Defined using keyword float float x, y, val, radius, circle_area; 4 bytes are allocated 24 bits used for mantissa, 8 used for exponent double is like a long float 8 bytes, with larger mantissa and exponent Example: double CircleArea, Savings_Account_Balance; 24
25 Character objects Character values are written as P * \t (tab character) \n (New Line character) \ (A single quote character) There exists a type char for character objects (one byte stores ASCII codes) Declaration of character objects int sym, first_letter_of_name; 25
26 Char objects Char object names can be assigned character values int sym; sym = P ; C++ treats char object as an integer values Can participate in integer expressions 26
27 Character objects... We note that our program itself is written as a sequence of characters These are analyzed by the compiler to understand and translate our instructions in machine language The input values which we give are also given as a stream of characters These are interpreted by the cin command, and converted to the internal representation Similarly, cout, takes an internal value, and converts it to a stream of symbols which appear as a decimal value to us 27
28 Assignment operation int m; m = 35; Symbol = is called the assignment operator the value on the right hand side (RHS) of this operator is evaluated In the example, it is simply 35 It is then stored in the location for the object m named on the left hand side (lhs) Previous value associated with object m is lost 28
29 Expression RHS need not be a single value, can be expression int m, n; n = 3; m = 35 * n  167; Expression on RHS is evaluated. The resulting single value is called value of the expression. This value is assigned to the object on LHS LHS must be an object to which value can be assigned 29
30 Expression evaluation Arithmetic operators  + * / % (modulo operator, it gives remainder) Precedence rule * / % have higher precedence than  + For example: a+b*c [b*c calculated first, result added to a] Associative rule Within the same precedence, associativity is left to right x*y/z [x*y calculated first, result divided by z ] Parentheses are used to override the precedence 30
31 Example of expression evaluation 31
32 Operands may be objects with different types If both operands are of same type result value is of the same type 9.0/2.0 will result in 4.5 9/2 will result in 4 If the operands are of a different type int is converted to float The result value is of type float 32
33 Expression evaluation... possible problems in expression evaluations while two values participating in an operation can individually be within the stipulated range, the result may not be in the range In such a case, an erroneous value will result 33
34 Type conversion during assignment int i, j; float x, y; i=25; x=2.147; j=3.2; // float values converted to int // (fractional part is truncated) j=1.24e30; Complete loss of precision, value too large 34
35 Type conversion y=29; value converted to float, equivalent to.29e2 y= ; value converted to float with loss of precision e9 35
36 Examples Eexpressions and their C++ equivalent (a+b)x 1 x + 1 x
37 Assignment statement revisited general form of an assignment operation is name = expression; y = *r*r+h*w 2* *rdash; The entire assignment operation is also treated logically as an expression, whose value is same as the one finally assigned to the name on lhs Thus m = n =25; is a valid statement m = (n = 25); m=n=p=10; This is same as m=(n=(p=10)); 37
38 Reassignment Object on LHS may appear in the expression on RHS n = 3*m + 2*n; The RHS is evaluated using existing value of n The result of expression is assigned to n Which becomes the new value of n 38
39 39
40 Quiz What will be the values printed by the following program? int main (){ int m, n; float x, y; m=x=n=y=8.79; cout << m << x << n << y; 40
41 Quiz What is the value output by this program? float x, y, avogadro; avogadro = 6.023E23; y = ; x=y avogadro; 41
42 Quiz Write a program to calculate the value of y, for any given value of x, if x and y are related by y = mx + c 42
43 C++ Program 43
44 44
45 Take home problem Starting from a point, a person walks at a steady speed of 4 Km per hour for 3 hours. The person then starts running at a speed of 8 Km per hour. He stops after traveling for 5 hours Write a program to determine the distance traveled by the person in some given time t 45
46 46
A First Book of C++ Chapter 2 Data Types, Declarations, and Displays
A First Book of C++ Chapter 2 Data Types, Declarations, and Displays Objectives In this chapter, you will learn about: Data Types Arithmetic Operators Variables and Declarations Common Programming Errors
More informationChapter 2: Problem Solving Using C++
Chapter 2: Problem Solving Using C++ 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common
More informationC++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 2: Basic Elements of C++
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with the basic components of a C++ program,
More informationIntroduction to C++ Programming
Introduction to C++ Programming 1 Outline Introduction to C++ Programming A Simple Program: Printing a Line of Text Another Simple Program: Adding Two Integers Memory Concepts Arithmetic Decision Making:
More informationAdjusted/Modified by Nicole Tobias. Chapter 2: Basic Elements of C++
Adjusted/Modified by Nicole Tobias Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types
More informationThe Fundamentals of C++
The Fundamentals of C++ Basic programming elements and concepts JPC and JWD 2002 McGrawHill, Inc. Program Organization Program statement Definition Declaration Action Executable unit Named set of program
More informationChapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationDept. of CSE, IIT KGP
Programming in C: Basics CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of variable We must declare the
More informationProgramming Fundamental. Instructor Name: Lecture2
Programming Fundamental Instructor Name: Lecture2 Today s Lecture What is Programming? First C++ Program Programming Errors Variables in C++ Primitive Data Types in C++ Operators in C++ Operators Precedence
More informationName: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1  Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
More information7 Introduction to C++
7 Introduction to C++ 7.1 Introduction C++ is an extension to C Programming language. It was developed at AT&T Bell Laboratories in the early 1980s by Bjarne Stroustrup. It is a deviation from traditional
More informationProblem Solving With C++ Ninth Edition
CISC 1600/1610 Computer Science I Programming in C++ Professor Daniel Leeds dleeds@fordham.edu JMH 328A Introduction to programming with C++ Learn Fundamental programming concepts Key techniques Basic
More informationCourse Topics  Outline
Course Topics  Outline Lecture 1  Introduction Lecture 2  Lexical conventions Lecture 3  Data types Lecture 4  Operators Lecture 5  Behavioral modeling Lecture 6  Data flow modeling Lecture 7 
More informationBy the end of the lecture, you should be able to:
Extra Lecture: Number Systems Objectives  To understand: Base of number systems: decimal, binary, octal and hexadecimal Textual information stored as ASCII Binary addition/subtraction, multiplication
More informationFigure 1.12 Entering, Translating, and Running a HighLevel Language Program Pearson Education, Inc. All rights reserved.
Figure 1.12 Entering, Translating, and Running a HighLevel Language Program 1 2007 Pearson Education, Inc. All rights reserved. 2 Figure 2.7 General Form of a C Program 2007 Pearson Education, Inc. All
More informationIntroduction to the C++ Programming Language
L E S S O N S E T 2 Introduction to the C++ Programming Language PURPOSE PROCEDURE 1. To briefly introduce the C++ programming language 2. To show the use of memory in programming 3. To introduce variables
More informationSolution Exercise 1.1
Solution Exercise 1.1 Part I Fill in the blanks with the most appropriate answers. 1. A Program is a sequence of stepbystep instructions that a computer executes in order to solve a problem or to perform
More information198:211 Computer Architecture
198:211 Computer Architecture Topics: Lecture 8 (W5) Fall 2012 Data representation 2.1 and 2.2 of the book Floating point 2.4 of the book 1 Computer Architecture What do computers do? Manipulate stored
More informationIntroduction to C Programming
Introduction to C Programming C HOW TO PROGRAM, 6/E 19922010 by Pearson Education, Inc. All Rights Reserved. 2.1 Introduction The C language facilitates a structured and disciplined approach to computer
More informationBachelors of Computer Application Programming Principle & Algorithm (BCAS102T)
Unit I Introduction to c Language: C is a generalpurpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating
More informationC++ Language Tutorial
cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain
More informationPunctuation in C. Identifiers and Expressions. Identifiers. Variables. Keywords. Identifier Examples
Identifiers and Expressions CSE 130: Introduction to C Programming Spring 2005 Punctuation in C Statements are terminated with a ; Groups of statements are enclosed by curly braces: { and } Commas separate
More informationChapter 8. Arithmetic in C++
Christian Jacob Chapter 8 Arithmetic in C++ 8.1 The C++ Vocabulary 8.2 Variables and Types 8.2.1 Data Objects 8.2.2 Variables 8.2.3 Declaration of Variables 8.3 Elementary C++ Data Types 8.3.1 Integers
More informationINDEX. C programming Page 1 of 10. 5) Function. 1) Introduction to C Programming
INDEX 1) Introduction to C Programming a. What is C? b. Getting started with C 2) Data Types, Variables, Constants a. Constants, Variables and Keywords b. Types of Variables c. C Keyword d. Types of C
More informationLecture 1 Notes: Introduction
Introduction to C++ January 4, 2011 Massachusetts Institute of Technology 6.096 Lecture 1 Notes: Introduction 1 Compiled Languages and C++ 1.1 Why Use a Language Like C++? At its core, a computer is just
More informationEncoding Systems: Combining Bits to form Bytes
Encoding Systems: Combining Bits to form Bytes Alphanumeric characters are represented in computer storage by combining strings of bits to form unique bit configuration for each character, also called
More informationTutorial3a: First steps with C++ programming
HTTP://WWW.HEP.LU.SE/COURSES/MNXB01 Introduction to Programming and Computing for Scientists (2015 HT) Tutorial3a: First steps with C++ programming Programming for Scientists Tutorial 3a 1 / 17 Quick
More informationSimple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. DevC++ DevC++ Windows Friendly Exit. The C++ Programming Language
Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from
More informationINTRODUCTION TO FLOWCHARTING
CHAPTER 1 INTRODUCTION TO FLOWCHARTING 1.0 Objectives 1.1 Introduction 1.2 Flowcharts 1.3 Types of Flowcharts 1.3.1 Types of flowchart 1.3.2 System flowcharts 1.4 Flowchart Symbols 1.5 Advantages of Flowcharts
More informationNumber Representation
Number Representation CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Topics to be Discussed How are numeric data
More informationHuazhong University of Science and Technology JAVA Programming Language Lecture 2:Variables and Data Types
JAVA Programming Language Lecture 2:Variables and Data Types Chengwei Zhang ( 张成伟 ) School of Electronic Information and Communications Huazhong University of Science and Technology Mar. 2015 Outline Quick
More informationNumber Systems and. Data Representation
Number Systems and Data Representation 1 Lecture Outline Number Systems Binary, Octal, Hexadecimal Representation of characters using codes Representation of Numbers Integer, Floating Point, Binary Coded
More informationC++ Basics. C++ Basics: Names: Identifiers. Names: Identifiers. Display 2.1 A C++ Program (1 of 2) Display 2.1 A C++ Program (2 of 2)
C++ Basics C++ Basics: 2.1 Variables and Assignments Variables and Assignments Input and Output Data Types and Expressions Simple Flow of Control Program Style A C++ variable can hold a number or other
More informationChapter II Binary Data Representation
Chapter II Binary Data Representation The atomic unit of data in computer systems is the bit, which is actually an acronym that stands for BInary digit. It can hold only 2 values or states: 0 or 1, true
More informationY = abc = a b c.2 0
Chapter 2 Bits, Data Types & Operations Integer Representation Floatingpoint Representation Other data types Why do Computers use Base 2? Base 10 Number Representation Natural representation for human
More informationPresented By: Ms. Poonam Anand
Presented By: Ms. Poonam Anand Know the different types of numbers Describe positional notation Convert numbers in other bases to base 10 Convert base 10 numbers into numbers of other bases Describe the
More informationChapter One Introduction to Programming
Chapter One Introduction to Programming 11 Algorithm and Flowchart Algorithm is a stepbystep procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of
More informationData Representation. Representing Data
Data Representation COMP 1002/1402 Representing Data A computer s basic unit of information is: a bit (Binary digit) An addressable memory cell is a byte (8 bits) Capable of storing one character 10101010
More informationGETTING STARTED WITH C++ C++ BASICS  1 
 1  GETTING STARTED WITH C++ Programming is a core activity in the process of performing tasks or solving problems with the aid of a computer. An idealised picture is: PROBLEM COMPUTER SOLUTION Unfortunately
More informationC Programming Dr. Hasan Demirel
C How to Program, H. M. Deitel and P. J. Deitel, Prentice Hall, 5 th edition (3 rd edition or above is also OK). Introduction to C Programming Dr. Hasan Demirel Programming Languages There are three types
More informationInformatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
More informationIntroduction to Scientific Programming with C++
Introduction to Scientific Programming with C++ Session 0: Basics Martin Uhrin and Seto Balian UCL December 1719th 2014 1 / 25 Table of Contents 1 Introduction to language 2 Program structure 3 Variables,
More informationIntroduction to Programming
Introduction to Programming SS 2012 Adrian Kacso, Univ. Siegen adriana.dkacsoa@dunisiegena.de Tel.: 0271/7403966, Office: HB 8406 Stand: April 25, 2012 Betriebssysteme / verteilte Systeme Introduction
More informationLecture Set 2: Starting Java
Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables CMSC 131  Lecture Outlines  set
More information[Page 70 (continued)] a. are used to document a program and improve its readability. [Page 71]
[Page 70 (continued)] Exercises 2.7 Discuss the meaning of each of the following objects: a. std::cin b. std::cout 2.8 Fill in the blanks in each of the following: a. are used to document a program and
More informationChapter 2. Values, Variables, and Types. 2.1 Java Values in DrJava s Interaction Pane
14 Chapter 2 Values, Variables, and Types In this chapter we explore the primitive building blocks that are used to develop Java programs. We experiment with the following concepts within DrJava s interactive
More informationIntroduction to C++ Programming
cpphtp5_02.fm Page 36 Wednesday, December 15, 2004 11:11 AM 2 Introduction to C++ Programming OBJECTIVES In this chapter you will learn: To write simple computer programs in C++. To write simple input
More informationIntroduction to Programming
Introduction to Programming SS 2012 Adrian Kacso, Univ. Siegen adriana.dkacsoa@dunisiegena.de Tel.: 0271/7403966, Office: HB 8406 Stand: April 25, 2012 Betriebssysteme / verteilte Systeme Introduction
More informationRecall that in base 10, the digits of a number are just coefficients of powers of the base (10):
Binary Number System 1 Base 10 digits: 0 1 2 3 4 5 6 7 8 9 Base 2 digits: 0 1 Recall that in base 10, the digits of a number are just coefficients of powers of the base (10): 417 = 4 * 10 2 + 1 * 10 1
More informationComputer Science 281 Binary and Hexadecimal Review
Computer Science 281 Binary and Hexadecimal Review 1 The Binary Number System Computers store everything, both instructions and data, by using many, many transistors, each of which can be in one of two
More informationChapter 4 Intro to Programming in C++
Chapter 4 Intro to Programming in C++ 41 Computer Programming Earlier we defined an algorithm to be a step by step process for solving a problem. Computer programming is the process of implementing the
More informationOutline TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA. What is DrJava? Dr Java
1 Outline TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared
More informationVariables and Constants. Variable A location in computer's memory in which a value may be stored from which that value may be retrieved
Variables and Constants Variable A location in computer's memory in which a value may be stored from which that value may be retrieved Storage of Variables Setting Aside Memory Defining a variable in C++
More informationVariables and Constants
HOUR 3 Variables and Constants What You ll Learn in This Hour:. How to declare and define variables and constants. How to assign values to variables and manipulate those values. How to write the value
More informationIntroduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.
1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays
More informationNumber Representation
Number Representation Number System :: The Basics We are accustomed to using the socalled decimal number system Ten digits ::,,,3,4,5,6,7,8,9 Every digit position has a weight which is a power of Base
More informationSchool of Informatics, University of Edinburgh
CS1Ah Lecture Note 5 Java Expressions Many Java statements can contain expressions, which are program phrases that tell how to compute a data value. Expressions can involve arithmetic calculation and method
More informationC Syntax and Semantics
C Syntax and Semantics 1 C Program Structure C Language Elements Preprocessor directives Function Header, and Function body Executable statements Reserved word, Standard identifiers, user defined identifiers
More informationEM108 Software Development for Engineers Section 5 Storing Information
EM108 5 Storing Information page 1 of 11 EM108 Software Development for Engineers Section 5 Storing Information 5.1 Motivation: Various information types o Various types of numbers o Text o Images, Audios,
More informationDigital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.
Digital Logic 1 Data Representations 1.1 The Binary System The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer. The system we
More informationBinary Number System. 16. Binary Numbers. Base 10 digits: 0 1 2 3 4 5 6 7 8 9. Base 2 digits: 0 1
Binary Number System 1 Base 10 digits: 0 1 2 3 4 5 6 7 8 9 Base 2 digits: 0 1 Recall that in base 10, the digits of a number are just coefficients of powers of the base (10): 417 = 4 * 10 2 + 1 * 10 1
More informationPrimitive Data Types Summer 2010 Margaret ReidMiller
Primitive Data Types 15110 Summer 2010 Margaret ReidMiller Data Types Data stored in memory is a string of bits (0 or 1). What does 1000010 mean? 66? 'B'? 9.2E44? How the computer interprets the string
More informationRadix Number Systems. Number Systems. Number Systems 4/26/2010. basic idea of a radix number system how do we count:
Number Systems binary, octal, and hexadecimal numbers why used conversions, including to/from decimal negative binary numbers floating point numbers character codes basic idea of a radix number system
More informationComputer is a binary digital system. Data. Unsigned Integers (cont.) Unsigned Integers. Binary (base two) system: Has two states: 0 and 1
Computer Programming Programming Language Is telling the computer how to do something Wikipedia Definition: Applies specific programming languages to solve specific computational problems with solutions
More informationLSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology
LSN 2 Number Systems Department of Engineering Technology LSN 2 Decimal Number System Decimal number system has 10 digits (09) Base 10 weighting system... 10 5 10 4 10 3 10 2 10 1 10 0. 101 102 103
More informationUNIT1. C Programming & Data Structures. Introduction to Computers: Computing Environment: Types of Computing Environments:
Introduction to Computers: C Programming & Data Structures UNIT1 A computer system consists of hardware and software. Computer hardware is the collection of physical elements that comprise a computer
More informationChapter 2: Elements of Java
Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction
More information2.1 Binary Numbers. 2.3 Number System Conversion. From Binary to Decimal. From Decimal to Binary. Section 2 Binary Number System Page 1 of 8
Section Binary Number System Page 1 of 8.1 Binary Numbers The number system we use is a positional number system meaning that the position of each digit has an associated weight. The value of a given number
More informationNumber Systems and Base Conversions
Number Systems and Base Conversions As you know, the number system that we commonly use is the decimal or base 10 number system. That system has 10 digits, 0 through 9. While it's very convenient for
More informationVARIABLES AND ARITHMETIC OPERATIONS
CHAPTER3 CHAPTER TOPICS In this chapter, you will learn how to: Work with variables Perform arithmetic calculations Use mathematical functions VARIABLES AND ARITHMETIC OPERATIONS 67 68 V ARIABLES AND ARITHMETIC
More information2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal
2/9/9 Binary number system Computer (electronic) systems prefer binary numbers Binary number: represent a number in base2 Binary numbers 2 3 + 7 + 5 Some terminology Bit: a binary digit ( or ) Hexadecimal
More informationCMSC 106 Lecture Set #2. C language syntax. Syntax vs Semantics Examples
CMSC 106 Lecture Set #2 C Language Introduction C language syntax Syntax rules of the grammar vocabulary recognized by the language ANSI standard American National Standards Institute Semantics the meaning
More informationOverview of a C Program
Overview of a C Program Programming with C CSCI 112, Spring 2015 Patrick Donnelly Montana State University Programming with C (CSCI 112) Spring 2015 2 / 42 C Language Components Preprocessor Directives
More informationDept. of CSE, IIT KGP
Basic Programming Concepts CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Some Terminologies Algorithm / Flowchart
More informationWhich of the following is the correct operator to compare two variables? A. := B. = C. equal D. ==
Group 1 Question 1. What is the correct value to return to the operating system upon the successful completion of a program? A. 1 B. 1 C. 0 D. Programs do not return a value. Question 2. What is the only
More informationCS201 Introduction to Programming Latest Solved Mcqs from Final term Papers July 11,2011
CS201 Introduction to Programming Latest Solved Mcqs from Final term Papers July 11,2011 Mc100401285 moaaz.pk@gmail.com Moaaz Siddiq Bc100400662 bc100400662asad@gmail.com Asad Ali Latest Mcqs FINALTERM
More informationChapter 3 Basic Input & Output
Chapter 3 Basic Input & Output 31 Basic Output in C++ cout is a predefined variable in C++ that indicates you are going to output a stream of characters to an output device. cout uses an operator called
More informationCSC 1103: Digital Logic. Lecture Six: Data Representation
CSC 1103: Digital Logic Lecture Six: Data Representation Martin Ngobye mngobye@must.ac.ug Mbarara University of Science and Technology MAN (MUST) CSC 1103 1 / 32 Outline 1 Digital Computers 2 Number Systems
More informationChapter 4 Operators & Arithmetic
Chapter 4 Operators & Arithmetic 41 Arithmetic in C++ Arithmetic expressions can be made up of constants, variables, operators and parentheses. The arithmetic operators in C++ are as follows + (addition)
More informationPE1 Worksheet. 3) What are the three control structures for writing an algorithm in pseudocode?
PE1 Worksheet Problem solving 1) What are the four stages of problem solving by programming? What shall be done in each stage? Stage 1: Stage 2: Stage 3: Stage 4: 2) What is the topdown design strategy
More informationToday s topics. Java programs. Java Virtual Machine (JVM) Bytecodes. HelloWorld.java javac HelloWorld.class
Today s topics Java programs Parsing Java Programming Notes from Tammy Bailey Reading Great Ideas, Chapter 3 & 4 Java programs are created as text files using a text editor (like emacs) Save to disk with.java
More informationFinal Exam Review. CS 1428 Fall Jill Seaman. Final Exam
Final Exam Review CS 1428 Fall 2011 Jill Seaman 1 Final Exam Friday, December 9, 11:00am to 1:30pm Derr 241 (here) Closed book, closed notes, clean desk Comprehensive (covers entire course) 25% of your
More informationMotivations. Chapter 2: Elementary Programming. Introducing Programming with an Example 7/18/16. CS1: Java Programming Colorado State University
Chapter 2: Elementary Programming CS1: Java Programming Colorado State University Original slides by Daniel Liang Modified slides by Chris Wilcox Motivations In the preceding chapter, you learned how to
More informationNumber Representation
Number Representation COMP375 Computer Organization and darchitecture t How do we represent data in a computer? At the lowest level, a computer is an electronic machine. works by controlling the flow of
More informationC++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 4: Control Structures I (Selection)
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 4: Control Structures I (Selection) Objectives In this chapter, you will: Learn about control structures Examine relational
More informationData types. lecture 4
Data types lecture 4 Information in digital computers is represented using binary number system. The base, i.e. radix, of the binary system is 2. Other common number systems: octal (base 8), decimal (base
More informationCSc 28 Data representation. CSc 28 Fall
CSc 28 Data representation 1 Binary numbers Binary number is simply a number comprised of only 0's and 1's. Computers use binary numbers because it's easy for them to communicate using electrical current
More informationKey concepts. C++ character set. Tokens. Keywords Identifiers Literals Punctuators Operators. Integrated Development Environment (IDE)
5 1 Key concepts C++ character set Tokens o o o o o Keywords Identifiers Literals Punctuators Operators Integrated Development Environment (IDE) o o Turbo C++ IDE Geany IDE C++ (pronounced "C plus plus")
More informationJava: Primitive Data Types, Variables and Constants
Java: Primitive Data Types, Variables and Constants Introduction A primitive data type is a data type provided as a basic building block by a programming language. It is predefined by the programming language
More informationC programming. Intro to syntax & basic operations
C programming Intro to syntax & basic operations Example 1: simple calculation with I/O Program, line by line Line 1: preprocessor directive; used to incorporate code from existing library not actually
More informationJava : Data types, Identifiers and Operators. Instructor: Nihshanka Debroy
Java : Data types, Identifiers and Operators Instructor: Nihshanka Debroy Java Programs Can use a text editor to type out Java code Save as a file with.java extension (Example: HelloWorld.java) File contains
More informationThe programming language C. sws1 1
The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan
More informationCS 16: Assembly Language Programming for the IBM PC and Compatibles
CS 16: Assembly Language Programming for the IBM PC and Compatibles First, a little about you Your name Have you ever worked with/used/played with assembly language? If so, talk about it Why are you taking
More informationJava Review (Essentials of Java for Hadoop)
Java Review (Essentials of Java for Hadoop) Have You Joined Our LinkedIn Group? What is Java? Java JRE  Java is not just a programming language but it is a complete platform for object oriented programming.
More informationHere 4 is the least significant digit (LSD) and 2 is the most significant digit (MSD).
Number System Introduction Number systems provide the basis for all operations in information processing systems. In a number system the information is divided into a group of symbols; for example, 26
More informationPart IA Computing Course Tutorial Guide to C++ Programming
Part IA Computing Course Tutorial Guide to C++ Programming Roberto Cipolla Department of Engineering University of Cambridge September 1, 2004 This document provides an introduction to computing and the
More informationTHE BINARY NUMBER SYSTEM
THE BINARY NUMBER SYSTEM Dr. Robert P. Webber, Longwood University Our civilization uses the base 10 or decimal place value system. Each digit in a number represents a power of 10. For example, 365.42
More informationPointer. Accessing address of a variable POINTER.
www.cppforschool.com Pointer Accessing address of a variable Computer s memory is organized as a linear collection of bytes. Every byte in the computer s memory has an address. Each variable in program
More informationChapter 4. Binary Data Representation and Binary Arithmetic
Christian Jacob Chapter 4 Binary Data Representation and Binary Arithmetic 4.1 Binary Data Representation 4.2 Important Number Systems for Computers 4.2.1 Number System Basics 4.2.2 Useful Number Systems
More informationSystems I: Computer Organization and Architecture
Systems I: Computer Organization and Architecture Lecture 2: Number Systems and Arithmetic Number Systems  Base The number system that we use is base : 734 = + 7 + 3 + 4 = x + 7x + 3x + 4x = x 3 + 7x
More information