Agenda of Describe different basic programming codes and languages.
- Worming Up quiz about Types of Errors 10 min
- Ppt presentation 20 min
- Write a c program about trigonometric functions 20 min
- Write a c program about Equations of Voltage , Current and
resistance in electricity 10 min .
- Write a c program about calculating a system efficiency 10
min.
- Write a c program about calculating the power factor of a
machine 10 min .
http://www.stemassiut.info prepared By ENG. Osama Ghandour
Learning Outcome: Describe different basic
programming codes and languages.
Key Concepts:
• Understanding computer basics, programs, and operating systems
• Understanding difference between high level language and low level
language.
• Understanding the terms of programming toolkit.
• Skills: Thinking, communicate
Essential Questions: How can we write a program code?
Evidence of Learning: Write a program code in a correct way.
http://www.stemassiut.info prepared By ENG. Osama Ghandour
From Decimal to Binary
Assiut STEM School Mr. Osama Ghandour Computer Science
52
1248163264128
001011000
1248163264128
32+16+4
𝟏𝟏𝟎𝟏𝟎𝟎 𝟐
Previous
Quiz
From Binary to Decimal
Assiut STEM School Mr. Osama Ghandour Computer Science
01234567
110101
01234567
43
𝟏 ∗ 𝟐 𝟓
+ 𝟎 ∗ 𝟐 𝟒
+𝟏 ∗ 𝟐 𝟑
+0∗ 𝟐 𝟐
+ 𝟏 ∗ 𝟐 𝟏
+1*𝟐 𝟎
32+0+8+0+2+1=
𝟏𝟎𝟏𝟎𝟏𝟏 𝟐
Previous
Quiz
Using calculator
http://www.stemassiut.info
Previous
home
works
http://www.stemassiut.info
Previous
home
works
http://www.stemassiut.info
prepared By ENG. Osama Ghandour
Data types in C
•Only really four basic types:
• char
• int (short, long, )
• float
• double
•Size of these types on CLEAR
machines:
•Sizes of these types vary
from one machine to another!
Type Size
(bytes)
Precision
char 1
int 2 to 4
short 2
long 4
float 4 6 decimal places
double 8 15 decimal places
Long double 10 19 decimal places
Previous
session
Press here
for on line
Press here
for off line
OR
http://www.stemassiut.info
prepared By ENG. Osama Ghandour
Characters are just numbers
•What does this function do?
Char
fun(char c)
{
char new_c;
if ((c >= ’A’) && (c <= ’Z’))
new_c = c - ’A’ + ’a’;
else
new_c = c;
return (new_c);
}
return type
procedure
name
argument type
and name
local variable
type and name
Math on
characters!
comparisons
with characters!
Previous
session
Press here
for on line
Press here
for off line
OR
Types of Errors
• There are three types of errors that may occur while developing or writing
C program. There errors are:
•Syntax Errors
•Logical Errors
•Runtime Errors
http://www.stemassiut.info prepared By ENG.
Osama Ghandour
Previous
session
http://www.stemassiut.info prepared By ENG. Osama Ghandour
A Simple C Program
• Create example file: try.c
• Compile using gcc:
gcc –o try try.c
• The standard C library libc is
included automatically
• Execute program
./try
• Note, I always specify an
absolute path
/* include stdio.h and stdlib.h */
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
printf(“Hello Worldn”);
return 0;
}
Previous
session
Home work2 write a program in C
Language to calculate the measure of
each interior angle of a regular
polygon of n-sides avoid any error
using Code Blocks . Note the sum of
measures of the interior angles of a
polygon of n-sides=(n-2)*180
Home work3 write a program in C
Language to draw a regular polygon of
n-sides http://www.stemassiut.info prepared By ENG. Osama Ghandour
Previous
home
works
Quiz
•Quiz about Types of Errors 10 min
http://www.stemassiut.info prepared By ENG. Osama Ghandour
Essential Questions: How can we write a program code?
Essential Questions:
•How can we write a program code?
For
Calculating voltage , current or
resistance or For Calculating electric
power ,efficiency , power factor or
For using Arduino circuits in capstone
projects. http://www.stemassiut.info prepared By ENG. Osama Ghandour
http://www.stemassiut.info prepared By ENG. Osama Ghandour
http://www.stemassiut.info prepared By ENG. Osama Ghandour
Press here
for on line
Press here
for off line
OR
Press here
for on line
Press here
for off line
OR
The terms of programming toolkit.
• Online help information for the Toolkit and other online help for
source code , examples functions and its formatting .
• C keywords , Data types , functions , arrays , pointers
• C header files.
• C import libraries.
• ActiveX automation type libraries.
http://www.stemassiut.info prepared By ENG. Osama Ghandour
Special Characters in C language
, < > . _ ( ) ; $ : % [ ] # ?
' & { } " ^ ! * / | -  ~ +
http://www.stemassiut.info prepared By ENG. Osama
Ghandour
Keywords in C Language
auto double int struct
break else long switch
case enum register typedef
char extern return union
continue for signed void
do if static while
default goto sizeof volatile
const float short unsigned
http://www.stemassiut.info prepared By ENG.
Osama Ghandour
toolkit
• Printf and Scanf formatting .
• https://wpollock.com/CPlus/PrintfRef.htm#printfPrec
http://www.stemassiut.info prepared By ENG. Osama Ghandour
scanf("%f",& voltage);
printf("%f", ”voltage = ”, voltage );
http://www.stemassiut.info prepared By ENG. Osama Ghandour
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
/*find the trigonometric sin ratio of the given angle */
int main()
{
float degree;
scanf("%f",&degree);
printf("%f", tan (degree));
return 0;
}
http://www.stemassiut.info prepared By ENG. Osama Ghandour
http://www.stemassiut.info prepared By Eng. Osama Ghandour
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
/*find the Voltage Value when given the current and resistant values*/
int main()
{
float current , resistant , voltage ;
scanf("%f",&resistant);
scanf("%f",&current);
Voltage = current * resistant
printf("%f", ”voltage = ”, voltage );
return 0;
}
http://www.stemassiut.info prepared By ENG. Osama Ghandour
http://www.stemassiut.info prepared By ENG. Osama Ghandour
Real (Active )
Power
Power factor
A program for calculating power
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
/*find the power Value when given the current and voltage values*/
int main()
float current , power , voltage ;
scanf("%f",&);
scanf("%f",&);
Power = current * voltage;
printf("%f", ” power = ” , power );
return 0;
}
http://www.stemassiut.info prepared By ENG. Osama Ghandour
Real (Active ) Power
A program for calculating power factor
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
/*find the power factor PF when given its angle value*/
int main()
float degree , PF , ;
scanf("%f",degree);
printf("%f", ”PF = ” , cos(degree) );
return 0;
http://www.stemassiut.info prepared By ENG. Osama Ghandour
Power factor
A program for calculating efficiency
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
/*find the efficiency Value when given the input power and output power values*/
int main()
float input , efficiency , output ;
scanf("%f",&input);
scanf("%f",&output);
efficiency = output / input;
printf("%f", ” efficiency = ” , efficiency );
return 0;
http://www.stemassiut.info prepared By ENG. Osama Ghandour
References
•https://www.ibm.com/support/knowledgecenter/ssw_i5_54/rzaik/rz
aikcaexpresstoolkit.htm
•https://wpollock.com/CPlus/PrintfRef.htm#printfPrec
•https://www.google.com.eg/url?sa=i&rct=j&q=&esrc=s&source=imag
es&cd=&cad=rja&uact=8&ved=&url=http%3A%2F%2Fwww.bbc.co.uk
%2Feducation%2Fguides%2Fzgmpr82%2Frevision&psig=AFQjCNHjP2
QJSGFDBUa_FZALmAs7FgQfvA&ust=1458549460497918
•http://www.fearnleyeducation.com/files/PageImages/FlowDiagram2.
png
http://www.stemassiut.info prepared By ENG. Osama Ghandour
References
• https://www.google.com.eg/search?q=power+in+kw&safe=active&bi
w=1120&bih=706&source=lnms&tbm=isch&sa=X&ved=0ahUKEwinh8
LC-
c7LAhUFmBoKHWg5Aq4Q_AUIBigB#safe=active&tbm=isch&q=efficie
ncy+definition&imgrc=LaNTli9TFZhF_M%3A
• https://www.google.com.eg/url?sa=i&rct=j&q=&esrc=s&source=imag
es&cd=&cad=rja&uact=8&ved=0ahUKEwiehNXm_M7LAhUFCBoKHYKl
BoIQjRwIBw&url=http%3A%2F%2Fwww.apexpakistan.net%2Fservices
%2F&bvm=bv.117218890,d.d2s&psig=AFQjCNE0kXffcphykSACGXLhoC
XFbk6nQw&ust=1458552678591236
http://www.stemassiut.info prepared By ENG. Osama Ghandour
A default simple code
you will find then write
your code and develop
your program from your
flowchart and defined
issue , build and run
program at first time
from build menu or F9
next time run it by
“CTRL+ F10” , save your
program /project Press here
for on line
Press here
for off line
ORhttp://www.stemassiut.info prepared By ENG.
Osama Ghandour
Open
Arduino
software
Arduino
connecting
Power factor
http://www.stemassiut.info prepared By ENG.
Osama Ghandour
saving wasted energy
http://www.stemassiut.info prepared By ENG.
Osama Ghandour
Power factor
http://www.stemassiut.info
prepared By ENG. Osama Ghandour
Power factor
Home work you studied in physics about
electric power and in your capstone about saving
wasted energy so design a flowchart for Arduino
control circuit to save the consumed energy in
electric power circuit . Note : an ideal electric
system has power factor PF=0.999 and very low
reactive power.
http://www.stemassiut.info prepared By ENG. Osama Ghandour
5 min Reflection
• Mention 2 skills and 2 pits of
knowledge of C programming
you learned today?
Osama Ghandour Geris
Assiut STEM School
41
Thank you
Mr. Osama Ghandour

2019 session 5 describe different basic programming codes and languages