Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.

Similar presentations


Presentation on theme: "Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation."— Presentation transcript:

1 Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation

2 Integer Data Type : positive or negative whole number Data TypeMinimum Range of ValuesMinimum Number of Bytes Occupied char-128 to 1271 unsigned char0 to 2551 short-32,768 to 32,7672 unsigned short0 to 65,5352 int-2,147,483,648 to 2,147,483,6474 unsigned int0 to 4,294,967,2954 long-2,147,483,648 to 2,147,483,6474 unsigned long0 to 4,294,967,2954

3 Floating-Point Data Type : number with decimal point Data TypeApproximate Range of Values Digits of Precision Number of Bytes Occupied float3.4 x 10 -38 to 3.4 X10 38 74 double1.7 x 10 -308 to 1.7 X10 308 158 long double3.4 x 10 -4932 to 3.4 X10 4932 1910

4 The bool Data Type Boolean variables are set to either true or false Internally, true is represented as the number 1 and false is represented by the number 0.

5 Variables and Constants Variable holds data that can change while the program is running Constant is used to store data that remains the same throughout the program’s execution. You must declare variables and constant before you can reference (use) them. The name for your variable and constant called identifier –Case sensitive –Begin with underscore_, alphabet (upper or lower case), follow by underscore_, alphabet (a..z or A..Z) and digit (0-9) –Meaningful to your program and application

6 String and Character Literal character constant surrounded by single quote ‘A’ ‘ ‘ ‘$’ ‘5’ ‘\n’ Strings are consecutive sequences of characters and can occupy several bytes of memory. Literal string constant surrounded by double quote “Hello!” “This is a programming class”

7 Declaration int number; char Code; double average; string Name; bool Found ; Declaration and Initialization int number = 4; char Code = ‘A’; double average = 0.0; string Name = “John Doe”; bool Found = false;

8 Standard Input and Output The cout object is referred to the standard output device (screen) cout << “My name is ” << Name; The cin object is referred to the standard input device (keyboard) cin >> number; cin >> code >> average;

9 New lines cout does not produce a newline at the end of a statement To produce a newline, use either the stream manipulator endl or the escape sequence \n cout << “Good Day.” << endl; cout << “Good Day.\n”;

10 American Standard Code for Information Interchange (ASCII) Letters and digit and symbol, called character, are assigned a number that the computer uses to represent them. Most computers assign numbers to characters according to the ASCII (Appendix A) The basic ASCII code is based on 7 bits, which gives 128 character.

11 Escape Sequence is a special character (1 byte) begin with \ and something.

12

13 Arithmetic Operators There are many operators for manipulating numeric values and performing arithmetic operations.

14 Rule of Precedence

15 Problem: Calculate the Circumference of a circle with the given radius Structure Chart Main Module Input radius Process data circumference = 2 Muiltiply PI Mulitply radius Output circumference

16 Pseudo Code 1.Declare PI as a constant double with 3.14159 2.Declare radius as double 3.Declare circumference as double 4.Prompt user to input the value of radius 5.Input radius 6.Set circumference = 2 Muiltiply PI Mulitply radius 7.Output “The circle’s circumference is “ 8.Output the content circumference and then carriage return

17 Start End Input radius circumference = 2 * PI * radius Output circumference Flow Chart

18 // circle.cpp // Example of using a constant #include using namespace std; int main() { const double PI = 3.14159; double circumference, radius; // Ask user for the raduis of a circle cout << “What is the radius of the circle? “; cin >> radius; circumference = 2 * PI * radius; // calculate cirdumference // Output the circle’s circumference cout << “The circle’s circumference is “; cout << circumference << endl; return 0; }


Download ppt "Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation."

Similar presentations


Ads by Google