Showing posts with label Expression. Show all posts
Showing posts with label Expression. Show all posts

Sunday, March 12, 2017

C++ Part 18

A SINGLE STATEMENT FOR EACH ALTERNATIVE


if (Boolean_Expression)
Yes_Statement
else
No_Statement
If the Boolean_Expression evaluates to true, then the Yes_Statement is executed.
If the Boolean_Expression evaluates to false, then the No_Statement is executed.
Multi if-else Statement

if (Boolean_Expression_1)
Statement_1
else if (Boolean_Expression_2)
Statement_2
. . .
else if (Boolean_Expression_n)
Statement_n
else
Statement_For_All_Other_Possibilities

// EXAMPLE

if ((temperature < -10) && (day == SUNDAY))
cout << "Stay home.";
else if (temperature < -10) // and day != SUNDAY
cout << "Stay home, but call work.";
else if (temperature <= 0) // and temperature >= -10
cout << "Dress warm.";
else // temperature > 0
cout << "Work hard and play hard.";  

Intro to C++ Part 12

  • How Do I Start a Program? 


  1.  Identify inputs and outputs.
  2. Understand what you asked for ( Ask Questions ).
  3. Break the program down. // Functions
  4. into steps, writing each step in pseudocode English.
  5.  Replace each pseudocode step with C++ codes.

Intro to C++ Part 10

Expression 

The following table is showing some example and the equivalent meaning ones:

EXAMPLE
EQUIVALENT TO
count += 2;
count = count + 2;
total -= discount;
total = total - discount;
bonus *= 2;
bonus = bonus * 2;
change %= 100;
change = change % 100;
amount *= cnt1 + cnt2;
amount = amount * (cnt1 + cnt2);  

Intro to C++ Part 9

A statement

is an instruction that is executed and typically
updates some variable (called a side effect).
An expression is something that is evaluated and does not update
a variable (typically)
int x,y;
y=5;
x = (y = y+2);

What is x going to be?

Evaluate 5+2 and store 7 in y
2 Above also resulted in evaluating the y=y+2 expression, to 7.
→ store 7 in x.
It is very bad Idia to do so
Assignment Statements
In an assignment statement, first the expression on the right-hand side of the equal sign is
evaluated and then the variable on the left-hand side of the equal sign is set equal to this value.
SYNTAX
Variable = Expression;
EXAMPLES
distance = rate * time;
count = count + 2;

Digital Design Part 3

4th→ assembler translates it to the machine language. 1.6 [20] <§1.6> Consider two different implementations of the same instru...