Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 1 / Variables.cpp
diff options
context:
space:
mode:
Commit52039652b293ff72ba571055aaf06f00d9be6d3a (patch)
Author
 Angel Dimitriev <achi_d@abv.bg>
2020-10-09 14:11:42 +0300
Committer
 GitHub <noreply@github.com>
2020-10-09 14:11:42 +0300
Files35760fbcbbcdc48c3d70aaecd2ac1ebd593d58dc /Sem. 1/Variables.cpp
Introduction_to_programming_FMI-52039652b293ff72ba571055aaf06f00d9be6d3a.tar
Introduction_to_programming_FMI-52039652b293ff72ba571055aaf06f00d9be6d3a.tar.gz
Introduction_to_programming_FMI-52039652b293ff72ba571055aaf06f00d9be6d3a.zip
Parent09ef07083d7e63bb6013c12270575c105057a8a7 (diff)
Create Variables.cpp
1 files changed, 112 insertions, 0 deletions
-rw-r--r--Sem. 1/Variables.cpp112
diff --git a/Sem. 1/Variables.cpp b/Sem. 1/Variables.cpp
new file mode 100644
index 0000000..222b9e2
--- /dev/null
+++ b/Sem. 1/Variables.cpp
@@ -0,0 +1,112 @@
+#include<iostream>
+using namespace std;
+
+
+int main()
+{
+ //The reason why operator = returns a value!
+ int a, b, c, d, e, f;
+ a = b = c = d = e = f = 5;
+
+
+ //Operators
+
+
+ //Arithmetic operators
+ int num1 = 5;
+ int num2 = 2;
+
+ int result = a + b; //7
+ result = a - b; //3
+ result = a*b; //10
+ result = a / b; // 2 (not 2.5) (both are ints)
+ result = a%b; //1 5:2 = 2 (rem :1)
+
+ double num2Copy = 2;
+ double resultCopy = num1 / num2Copy; //2.5 (one of the variables is a double)
+
+ int A = 5;
+ int B = 2;
+
+ cout << (A++ - B) << endl;// 3 (but A becomes 6)
+ A = 5;//let's make it 5 again
+ cout << (++A - B) << endl;//4 (A becomes 6)
+
+ // Comparison operators
+
+ int N1 = 5;
+ int N2 = 6;
+
+ cout << (N1 > N2)<<endl; // 0(false);
+ //or we can do this:
+ bool cond = N1 > N2;
+ cout << cond;
+
+
+ //Other comparison operators : ==, !=, >, <, >=,<=
+
+
+
+ //Logical operators
+
+ bool var1 = false;
+ bool var2 = true;
+
+ bool t1 = var1 && var2; //false;
+ bool t2 = var1 || var2; //true
+ bool t3 = var1 ^ var2; //true
+
+
+ //Type casting
+
+ int a1 = 97;
+ double b1 = a1;
+ char c1 = a1;
+ bool d1 = a1;
+
+ cout << a1 << endl; //97
+ cout << b1 << endl; //97.0
+ cout << c1 << endl; //a
+ cout << d1 << endl; //1
+
+
+ double b2 = 65.5;
+ int a2 = b2;
+ char c2 = b2;
+ bool d2 = b2;
+
+ cout << b2 << endl; //65.5
+ cout << a2 << endl; //65
+ cout << c2 << endl; //A
+ cout << d2 << endl; //1
+
+
+ char c3 = 'a';
+ double b3 = c3;
+ int a3 = c3;
+ bool d3 = c3;
+
+ cout << c3 << endl; //a
+ cout << b3 << endl; //97
+ cout << a3 << endl; //97
+ cout << d3 << endl; //1
+
+ bool d4 = true;
+ int a4 = d4;
+ double b4 = d4;
+ char c4 = d4;
+
+ cout << c4 << endl; // ??
+ cout << b4 << endl; // 1
+ cout << a4 << endl; // 1
+ cout << d4 << endl; // 1
+
+ int grade = 5;
+
+ bool isValid = grade >= 2 && grade <= 6;
+ bool isValid2 = grade == 2 || grade == 3 || grade == 4 || grade == 5||grade == 6;
+
+ bool isNotValid = !isValid;
+ bool isNotValid2 = grade < 2 || grade>6;
+
+}