Computer programming Engr. Otitigbe Obadiah Oghoerore Alegbe Profesor de Sistemas Universidad Nacional de Lanus Buenos Aires – Argentina.

Slides:



Advertisements
Similar presentations
Fundamentals of Computer and programming in C Programming Languages, Programs and Programming Rohit Khokher.
Advertisements

What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Dale/Weems/Headington
1 9/10/07CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Data types and variables
Chapter 2 Data Types, Declarations, and Displays
Basic Elements of C++ Chapter 2.
By: Mr. Baha Hanene Chapter 4. LEARNING OUTCOMES This chapter will cover learning outcome no. 2 i.e. Use basic data-types and input / output in C programs.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
11 Chapter 3 DECISION STRUCTURES CONT’D. 22 FORMATTING FLOATING-POINT VALUES WITH THE DecimalFormat CLASS We can use the DecimalFormat class to control.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
Input & Output: Console
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 2 Introduction to C++
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
1 C++ Syntax and Semantics, and the Program Development Process.
Week 1 Algorithmization and Programming Languages.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Fundamental Programming: Fundamental Programming Introduction to C++
Introduction to Programming
CHAPTER # 2 Part 2 PROGRAMS AND DATA 1 st semster King Saud University College of Applied studies and Community Service CSC1101 By: Asma Alosaimi.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
DATA TYPE AND DISPLAY Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
CSE 232: C++ memory management Overview of Arrays Arrays are the simplest kind of data structure –One item right after another in memory (“contiguous range”
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
CSI 3125, Preliminaries, page 1 Data Type, Variables.
1 What is a Named Constant? A named constant is a location in memory that we can refer to by an identifier, and in which a data value that cannot be changed.
COMPUTER PROGRAMMING. Array C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An.
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
Arrays. Topics to be Covered... Arrays ◦ Declaration ◦ Assigning values ◦ Array manipulation using loops Multi-dimensional arrays ◦ 2D arrays ◦ Declaration.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 A more complex example Write a program that sums a sequence of integers and displays the result. Assume that the first integer read specifies the number.
A Sample Program #include using namespace std; int main(void) { cout
Pointers A variable that holds an address value is called a pointer variable, or simply a pointer.  What is the data type of pointer variables? It’s not.
Integer VariablestMyn1 Integer Variables It must be possible to store data items in a program, and this facility is provided by variables. A variable is.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Copyright © Texas Education Agency, Computer Programming Variables and Data Types.
Chapter # 2 Part 2 Programs And data
LESSON 06.
Chapter Topics The Basics of a C++ Program Data Types
Programming Fundamentals
Documentation Need to have documentation in all programs
Computing Fundamentals
ITEC113 Algorithms and Programming Techniques
Basic Elements of C++.
Command Line Arguments
Revision Lecture
Basic notes on pointers in C
Variables ,Data Types and Constants
DATA HANDLING.
Basic Elements of C++ Chapter 2.
IDENTIFIERS CSC 111.
2.1 Parts of a C++ Program.
C++ Data Types Data Type
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Chapter # 2 Part 2 Programs And data
C++ Programming Lecture 3 C++ Basics – Part I
CSCE 206 Lab Structured Programming in C
Variables and Constants
Data in a C++ Program Numeric data and character data
Getting Started With Coding
Presentation transcript:

Computer programming Engr. Otitigbe Obadiah Oghoerore Alegbe Profesor de Sistemas Universidad Nacional de Lanus Buenos Aires – Argentina

we can define a variable as a portion of memory to store a determined value. Each variable needs an identifier that distinguishes it from the others. For example, in the previous code the variable identifiers were a, b and result, but we could have called the variables any names we wanted to invent, as long as they were valid identifiers. Fundamental data types When programming, we store the variables in our computer's memory, but the computer has to know what kind of data we want to store in them, since it is not going to occupy the same amount of memory to store a simple number than to store a single letter or a large number, and they are not going to be interpreted the same way. The memory in our computers is organized in bytes. A byte is the minimum amount of memory that we can manage in C++. A byte can store a relatively small amount of data: one single character or a small integer (generally an integer between 0 and 255). In addition, the computer can manipulate more complex data types that come from grouping several bytes, such as long numbers or non-integer numbers. Next you have a summary of the basic fundamental data types in C++, as well as the range of values that can be represented with each one:

Below are just estimate values, In some Operating system or IDE, there may be different

Declaration of variables In order to use a variable in C++, we must first declare it specifying which data type we want it to be. The syntax to declare a new variable is to write the specifier of the desired data type (like int, bool, float...) followed by a valid variable identifier. For example: 1 2 int a; float mynumber; These are two valid declarations of variables. The first one declares a variable of type int with the identifier a. The second one declares a variable of type float with the identifier mynumber. Once declared, the variables a and mynumber can be used within the rest of their scope in the program. If you are going to declare more than one variable of the same type, you can declare all of them in a single statement by separating their identifiers with commas. For example: int a, b, c; This declares three variables (a, b and c), all of them of type int, and has exactly the same meaning as: int a; int b; int c; We are going to write a program that will print the value of a data on the computer screen. To do that, we must first declare a variable to hold the data, then we give value to it or initialize the data after which we shall print the data on the computer screen. For us to put the data on the screen we need a function form the library called printf. Printf has a convention and we format it dependint on the variable. When we want to put and integer value on the screen we arrange the inromation within printf for printf to interprete it. Supossing we want to print the number of student in a class, by logic the number bust be less that 250, thus we shal use short int. So we must declare a variable of short int or int and initialize it with the number of student. Int numStudents; numStudents = 50; Note we initialize the value. With printf we ´put the value on the screen. Printf(“%d”,numStudents); Let us see how it is done inside DevC++. Let us create a new project and then write the code. We shall have the following:

Declare a variable to hold number of students, initialize it and print it on the screen #include using namespace std; int main(int argc, char *argv[]) { int numStudents; numStudents = 50; printf("%d",numStudents); system("PAUSE"); return EXIT_SUCCESS; }

Suposing we want to print a salary which has decimal number, in this case we use float. We declare a variable of float type and initialize it. Float f_Salary; F_Salary = ; Printf(“%f”,f_Salary) #include using namespace std; int main(int argc, char *argv[]) { float f_Salary;; f_Salary = printf("%f",f_Salary); system("PAUSE"); return EXIT_SUCCESS; }