0% found this document useful (0 votes)
42 views5 pages

(C ++) Programming: Data Type Data

1) The document discusses various data types in C++ programming including int, long, float, double, char, and strings. 2) It covers variable declaration and naming conventions, noting variables must start with a letter, be less than 31 characters, and not use reserved words or special characters other than underscores. 3) Arithmetic expressions and operators are explained, including addition, subtraction, multiplication, division, modulo, increment, and decrement. Priority of operators is also covered. 4) Mathematical functions in C++ like absolute value, sine, cosine, logarithms, exponents, and square root are shown along with their syntax. Integer arithmetic rules and the modulo operator are also summarized.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views5 pages

(C ++) Programming: Data Type Data

1) The document discusses various data types in C++ programming including int, long, float, double, char, and strings. 2) It covers variable declaration and naming conventions, noting variables must start with a letter, be less than 31 characters, and not use reserved words or special characters other than underscores. 3) Arithmetic expressions and operators are explained, including addition, subtraction, multiplication, division, modulo, increment, and decrement. Priority of operators is also covered. 4) Mathematical functions in C++ like absolute value, sine, cosine, logarithms, exponents, and square root are shown along with their syntax. Integer arithmetic rules and the modulo operator are also summarized.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lecture 5 programming

(C ++) programming
Data type Data
int 5, -5 , 20 , -12 (may be positive or negative)
long 5, -5 , 20 , -12 (may be positive or negative)
unsigned int
Positive only
unsigned long
float
0.___
double
char 'A' , 'B' , 'C'
string "Hello" → array of characters

Variable declaration:
int x; int x,y; int main
int y; (void)

float a,b,c; int x,y;


double x1,x2,x3;
float z;

char c;
Rules of naming variables:
1) Length is less than 31 characters
2) Not from the reserved words
3) Should start with alphabet
4) Any following character can be alphanumeric
5) Should not contains any space or special character (symbols)
6) The only allowed special character is under score (_)
7) Variable are case sensitivity (UPPER CASE \ lower case)

Examples:
 Int →  (the reserved is "int" and not "Int")
 Flaot →  (check spelling , it's not "float")
 MAX value →  (there is a space)
o MAX_value →  (correction)

|Page1
Lecture 5 programming

 Money$ →  (special character)


 MoNeY → 
 1st_value →  (doesn't start with alphabet)
o _1st_value →  (correction)
 X12A_B → 

Variable assignment:
int x;

x=5;

x=10;

Arithmetic expression:

expression Name
+ Addition

- Subtraction

* Multiplication

/ Division

% Modulo

++ Increment

-- Decrement

Example
Y=2+5*4/2

Priority of operators:

a) ( brackets )
b) [ * , / , %] (from left to right)
c) [+ , -] (from left to right)

|Page2
Lecture 5 programming

Ex: what is the value of y?


( ( 6 + 4 ) / 2 * 4 ) / ( 4 + ( 3 * 2 ) / ( 2 – 1 ) )

= ( 10 / 2 * 4 ) / ( 4 + ( 3 * 2 ) / ( 2 – 1 ) )

= ( 10 / 2 * 4 ) / ( 4 + 6 / ( 2 – 1 ) )

= ( 10 / 2 * 4 ) / ( 4 + 6 / 1 )

= ( 5 * 4 ) / ( 4 + 6 / 1 )

= 20 / ( 4 + 6 / 1 )

= 20 / ( 4 +6)

= 20 / 10

=2

Operation in C++

math Programming
𝐚
Y= Y = a/b
𝐛
𝐚+𝐛
Y= Y = (a+b)/(c+d)
𝐜+𝐝
𝐚
Y =3 Y = 3*(a/b)
𝐛
𝐱
Y = 1+ Y = 1+ x/(y+z)
𝐲+𝐳

Integer arithmetic:
5/2 = 2 → (integer division)

5./2 = 2.5

int ∆ int = int

|Page3
Lecture 5 programming

int ∆ long = long

int ∆ float = float

float ∆ double = double

Modulo operator (%):


integer only

Integer is contains long


int x; and characters int x;
int y; float y;
Error : type mismatch
x=y%5;
x=y%5;

Y=x%n; Is a periodic function with period (n) and values from zero to (n-1)

Mathematical functions
#include <math.h>

math C++
Y = |x| Y=abs(x);
Y = 𝐬𝐢𝐧 𝐱 Y=sin(x);
Y = 𝐜𝐨𝐬 𝐱 Y=cos(x);
Y = 𝐭𝐚𝐧 𝐱 Y=tan(x);
Y = 𝐬𝐢𝐧−𝟏 𝐱 Y=asin(x);
Y = 𝐜𝐨𝐬 −𝟏 𝐱 Y=acos(x);
Y = 𝐭𝐚𝐧−𝟏 𝐱 Y=atan(x);
Y = 𝐞𝐱 Y=exp(x);
Y = 𝐥𝐨𝐠 𝐱 Y=log10(x);
Y = 𝐥𝐧 𝐱 Y=log(x);

|Page4
Lecture 5 programming

Y = 𝐱𝐚 Y=pow(x,a);
Y = √𝐱 Y=sqrt(x);
Y = ⌊ 𝐱⌋ Y = floor(x);
Y = ⌈ 𝐱⌉ Y = ceil(x);

X10 = pow(x,10) ≠ pow(10,x) ≠ x^10

−𝒃 ± √𝒃𝟐 − 𝟒𝒂𝒄
𝟐𝒂

= (-b+sqrt(pow(b,2)-4*a*c)/2*a)

|Page5

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy