Double Revolving field theory-how the rotor develops torque
2019 session 6 develop programs to solve a variety of problems in math , physics , and games
1. http://www.stemassiut.info prepared By Mr. Osama
Ghandour
1
1.Read and prepare The C.S. PPT well before
session .
2.During session Engage your team work ,
present , personalize and speak ,Use body
language , move and lead your colleges
The result is a clever , good personality and
communication skills .
2. Agenda of Develop programs to solve a
variety of problems in math, and games .
- Warming UP : quiz 15 min .
- PPT Revision 10 min
- PPT presentation 15 min.
- code blocks video 5 min .
- Using code blocks :- writing different programs
for math 10 min
- ways to learn programming fast video 5 min
- PPT presentation 15 min.
- Exit ticket 5 minhttp://www.stemassiut.info prepared By Mr. Osama Ghandour
2
3. Learning Outcome: Describe different basic
programming codes and languages.
Key Concepts: -
• Understand random number generation function.
• Understand some mathematics function like Square
root .
• If statement
• Combine conditions using logical operators (&&, ||,
and !).
• Skills: Design, thinking, analyzing and problem-solving.
• Essential Questions: How can we benefit from programming
language in solving problems in our daily life?
http://www.stemassiut.info prepared By Mr. Osama Ghandour
3
5. 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
6. Rules for writing variable name in C
•Variable name can be composed of letters (both
uppercase and lowercase letters), digits and
underscore '_' and Digits ( 0 – 9 ) only
•Blanks & Commas are not allowed
•No Special Symbols other than underscore(_) are
allowed
•First Character should be alphabet or Underscore
•Variable name Should not be Reserved Wordhttp://www.stemassiut.info prepared By ENG.
Osama Ghandour
6
7. • Constants
Constants are the terms that
can't be changed during the
execution of a program.
Its preprocessor Syntax as :
#define Pi 3.14
or as :
const float Pi=3.14 ;
• Variables
• A variable is just a named
area of storage , it is a
memory location in
computer's memory to store
data that can hold a single
value
its Syntax as :
int j=10;http://www.stemassiut.info prepared By ENG. Osama Ghandour7
Constant vs Variable
8. http://www.stemassiut.info prepared By ENG. Osama Ghandour
printf("%f", Y );
Previous
session
Input : In any programming language input means to feed some data
into program. This can be given in the form of file or from command
line. C programming language provides a set of built-in functions to
read given input and feed it to the program as per requirement.
scanf("%f",& X);
Y=F(x)
Output : In any programming language output means to display
some data on screen, printer or in any file. C programming
language provides a set of built-in functions to output required
data.
11. # 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",& voltage);
current = voltage / resistant;
printf("%f", ” current = ”, current );
return 0;
}
http://www.stemassiut.info prepared By ENG. Osama Ghandour
16. In math in MA.L.O. 1.07 W 1 : 4
you learned about : • Analyze the functions
• quadratic equations , Parabola .
• complex numbers
• Trigonometric functions
http://www.stemassiut.info prepared By Mr. Osama
Ghandour
16
In capstone you are required to
design a prototype for saving
wasted energy
o How can things be real and imaginary?
20. Pr. 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
21. Essential questions
-Why is modeling an
indispensable tool?
-Why do we need
laws/rules? To be used in
programming?http://www.stemassiut.info prepared By Mr. Osama
Ghandour
21
22. In math in MA.L.O. 1.08 Week 5 : 7
you will learn about :
In C programming you learned about
http://www.stemassiut.info prepared By Mr. Osama
Ghandour
22
exponential and logarithmic functions
pow(num,power)
23. http://www.stemassiut.info prepared By Mr. Osama Ghandour
23
#include<stdio.h>
#include<math.h>
int main()
{
int num,power,result;
printf("nEnter the numaber and its Power : ");
scanf("%d%d",&num,&power);
result = pow(num,power);
printf("nResult : %d",result);
return(0);}
//Are we ready to code?
24. In math in MA.L.O. 1.09 Week 8 : 11
you will learn about :
In C programming you learned about
http://www.stemassiut.info prepared By Mr. Osama
Ghandour
24
-Trigonometric functions
-sine, cosine and tangent
functions
cos (degree)
26. Essential questions
•How do humans make informed
decisions, given multiple options?
•What factors affect our decisions
and how do these factors relate
to programmimg models?
http://www.stemassiut.info prepared By Mr. Osama
Ghandour
26
27. In math in MA.L.O. 1.10 Week 8 : 11
you will learn about :
In C programming you learned about
http://www.stemassiut.info prepared By Mr. Osama
Ghandour
27
Pythagorean Identities
sqrt (num);
28. sqrt example
#include <stdio.h>
#include <math.h>
int main () /* sqrt example */
{
double param, result;
param = 1024.0;
result = sqrt (param);
printf (“%f%fn", param , result);
return 0;
}
http://www.stemassiut.info prepared By Mr. Osama Ghandour28
//Are we ready to code?
29. See also
•log Compute natural logarithm
(function).
•exp compute exponent of
number (function
http://www.stemassiut.info
prepared By Mr. Osama Ghandour
29
30. Are we ready to code it?
Video about using code
blocks
30 http://www.stemassiut.info prepared By Mr. Osama Ghandour
Press here
for on line
Press here
for off line
OR
31. Essential questions
•Why use shortcuts?
•Why is it essential to have
different ways of
reaching solutions?
http://www.stemassiut.info prepared By Mr. Osama
Ghandour
31
32. In math in MA.L.O. 1.12 Week 12 :
14
you will learn about :
In C programming write a program to
find the values of n unknowns when
you given a set of n equations of thesehttp://www.stemassiut.info prepared By Mr. Osama
Ghandour
32
1-Matrices 2- System
3- System of equations
33. In mechanics you learned
ME.L.O. 1.06 W 3:5
Lami's rule write a C program to find
unknown when given required values
ME. L.O. 1.07 W 6:8
Newton's 2nd law write a C program to find
unknown when given required values
http://www.stemassiut.info prepared By Mr. Osama
Ghandour
33
34. In Physics you are learning in
PH. L.O. 1.08 W 1:3
1. Fluids , 2. Pressure , 3. Archimedes Principle
PH. L.O. 1.09 W 4:6
1. Continuity equation , 2. Work-Energy Theorem , 3.
Bernoulli Equation
PH. L.O. 1.11 W 10:12
1-1st Law of Thermodynamics
http://www.stemassiut.info prepared By Mr. Osama
Ghandour
34
Write C programs to find automated
solutions for each of the above
equations and or laws
35.
36. Home work 1 Write a cprogram for
application which uses the continuity
equation a1*v1 = a2*v2 where a and v
are area and velocity respectively .
36 http://www.stemassiut.info prepared By Mr. Osama Ghandour
37.
38. Design a c program for calculating the EMF
(Electromotive force )using faraday's law of
induction equation
http://www.stemassiut.info preparedBy Mr. Osama Ghandour38
What is and where wastedenergy here ?
39. Are we ready to code it?
6 ways to learn
programming fast
39 http://www.stemassiut.info prepared By Mr. Osama Ghandour
Press here
for on line
Press here
for off line
OR
41. • The conditions in if statements are built out of
relational and logical operators.
The six relational operators that C provides
for comparing numbers:
== != > < >= <=
• But suppose you need to know if the value of
the variable x is both greater than zero and
less than one? None of these relational
operators by itself can answer that question.
What you need is to combine two conditions:
• (x > 0.0) and (y < 1.0)
41
http://www.stemassiut.info prepared By Mr. Osama Ghandour
42. •This is what logical operators can do for you. A
logical operator combines one or two
conditions into a single new condition. C
provides three logical operators:
•``&&'' (two ampersands) means and.
•``||'' (two vertical bars) means or.
•``!'' (an exclamation point) means not.
•Let's look at an example. If you need to know if
the value of the variable x is between zero and
one, inclusive, you would write this:
• if ((x >= 0.0) && (x <= 1.0))http://www.stemassiut.info prepared By Mr. Osama Ghandour42
43. •Now you try. Translate the
following English questions into C
conditions.
•Is the temperature temp greater
than 32.0 and less than 212.0?
•Is the height not equal to zero?
•Is the absolute value of pos greater
than 5.0?43
http://www.stemassiut.info prepared By Mr. Osama Ghandour
44. ExampleDescriptionOperator
(A && B) is false.
Called Logical AND operator. If both the
operands are non-zero, then the condition
becomes true.
&&
(A || B) is true.
Called Logical OR Operator. If any of the
two operands is non-zero, then the
condition becomes true.
||
!(A && B) is true.
Called Logical NOT Operator. It is used to
reverse the logical state of its operand. If a
condition is true, then Logical NOT
operator will make it false.
! http://www.stemassiut.info prepared By Mr. Osama Ghandour44
45. Example Try the following example to understand all
the logical operators available in C −
#include <stdio.h>
main()
{
int a = 5 , b = 20 , c ;
if ( a && b ) { printf("Line 1 - Condition is truen" ); }
if ( a || b ) { printf("Line 2 - Condition is truen" ); }
/* lets change the value of a and b a = 0 b = 10 */
45 http://www.stemassiut.info prepared By Mr. Osama Ghandour
46. if ( a && b ){printf("Line3-Condition is truen"); }
else {
printf("Line 3 - Condition is not truen" );
}
if ( !(a && b) ) {
printf("Line 4 - Condition is truen" );
}
}
46 http://www.stemassiut.info prepared By Mr. Osama Ghandour
47. •When you compile and execute the above
program, it produces the following result −
•Line 1 - Condition is true
•Line 2 - Condition is true
•Line 3 - Condition is not true
•Line 4 - Condition is true
47 http://www.stemassiut.info prepared By Mr. Osama Ghandour
49. Home work 2 what are the foolowin functions
and how you can use its in C programming ?
srand((unsigned) time(&t));
rand()
http://www.stemassiut.info prepared By Mr. Osama
Ghandour
49
50. 5 min Reflection
• Mention 2 skills and 2 pits of
knowledge of C programming
you learned today?
Osama Ghandour Geris
Assiut STEM School
50