Operating Systems make it easier to communicate with hardware devices
Operating Systems runs applications and to make this happen they create process
Each Process gets some cpu and to preserve any data it uses disks
Generally application are stored on a disk, when we want to execute the application, OS creates a process
Datatypes
Purpose of datatypes is to specify the size of data to be allocated in memory and also make it easy for developers
Two types of Data
Fixed Length
Variable Length
To make it easier for developers there will be basic datatypes around the type of data
numeric
integer
decimal numbers
boolean
text
character
string
custom datatypes
structures
int a = 10;
float b = 10.56;
Programming languages are further categorized into two types based on how the approach datatypes
static typed languages: We need to specify to type of data (C,C++, Java, C#, typescript)
we need to store balance amount in memory float balance = 1000.59
dynamic typed languages: During the code execution, language will allocate the type depeneding on the values passed (Javascript, python, bash/shell)
we need to store balance amount in memory balance = 1000.59
Problem solving with Flora
Selfie
Flora expects a sequence of instructions and it executes them line by line
Flora remembers anything with an alias
Remember 10 as number
or
number = 10
Flora knows basic arthimetic
+
-
*
/ 10/3 = 3
% remainder 10%3 == 1
Flora knows comparisions
<
<=
==
>
>=
While writing instructions lets have line numbers added
Area of Rectangle
Instructions
1. Hello Flora
2. Remember 10 as length
3. Remeber 40 as breadth
4. calculate length * breadth and remember as result
5. display result
Perimeter of Rectangle
Instructions
1. Hello Flora
2. Remember 10 as length
3. Remeber 40 as breadth
4. calculate length + breadth and store in result (result = length + breadth)
5. calculate result * 2 and store in result (result = result * 2)
6. display result
Area of circle
Instructions
1. Hello flora
2. Remember 3.14 as pi
3. Remember 10 as radius
4. result = pi * radius * radius
5. display result
Find if the number is even or odd
Instructions
1. Hello flora
2. Remember 10 as number
3. remainder = number % 2
4. if remainder == 0 say even
5. if remainder == 1 say odd
Conditional statements (tip)
if
if else
if else if
switch/case
Find the students grade
Flora learnt how to combine statements using and or
Problem
Lets give flora the average or percentage and make her say the grade
Instructions
1. Hello flora
2. Remember 10 as average
3. if average >= 90 and average <= 100
3.1. say Excellent
4. if avergage >= 80 and average < 90
4.1 say Good
5. if avergage >= 65 and average < 80
5.1 say Fair
6. if avergage >= 55 and average < 65
6.1 say Poor
7 if average < 55
7.1 say Very Poor
Lets print line number execute according to different values of average
The instructions above will make flora work even after finding the grades
Instructions
1. Hello flora
2. Remember 10 as average
3. if average >= 90 and average <= 100
3.1. say Excellent
3.2 go to line 8
4. if avergage >= 80 and average < 90
4.1 say Good
4.2 go to line 8
5. if avergage >= 65 and average < 80
5.1 say Fair
5.2 go to line 8
6. if avergage >= 55 and average < 65
6.1 say Poor
6.2 go to line 8
7 if average < 55
7.1 say Very Poor
8. Bye
Lets print line number execute according to different values of average
100: 1 -> 2 -> 3 -> 3.1 -> 3.2 -> 8 Excellent
65: 1 -> 2 -> 3 -> 4 -> 5 -> 5.1 -> 5.2 -> 8 Fair
Consider boundary conditions i.e. allow only valid set of values
1. Hello flora
2. Remember 10 as average
3. if average > 100 or average < 0
3.1 Say give me right averages
...
...
1. Hello Flora
2. Remember 82 as number
3. Remember 0 as result
4. digit = number % 10
5. number = number / 10
6. result = digit + result
7. if number > 0
7.1 go to 4
8. if result > 9
8.1 number = result
8.2 result = 0
8.3 go to 4
9. say result
Tip: Looping constructs help in executing block (sequence of lines) multiple times according to conditions, generally in most languages we have
while
for
Find if the number is pallendrome or not
A number is conisdered pallendrome if the reverse is equal to original number
121 => 121 (Pallendrome)
123 => 321 ( not a pallendrome)
Write instructions
1. Hello Flora
2. Remember 353 as number
3. Remember 0 as reverse
4. original = number
5. digit = number % 10
6. number = number / 10
7. reverse = reverse * 10 + digit
8. if number > 0
8.1 go to line number 5
9. if original == reverse
9.1 say pallendrom
10. if original != reverse
10.1 say not a pallendrome