Monday, February 28, 2011

Fundamental of Programming - 4th Week

CHAPTER 4

OPERATORS & EXPRESSIONS


1. Arithmetic operators
a) UNARY
* plus ++
* minus --

b) BINARY
: addition +
: subtraction -
: multiplication *
: division /
: modulus (remainder)

c) INCREMENT & DECREMENT
: pre-increment --> ++m [ 1+m]
: post-increment --> m++ [ m+1]
: pre-decrement --> --m [1-m]
: post-decrement --> m-- [m-1]

2. Relational Operators

a) NOT EQUIVALENT GROUP
symbols operators
> greater than
>= greater than or equals to
< less than
<= less than or equals to

b)EQUIVALENT GROUP
symbols operators
== equal to
!= not equal to

3. Logical Operators
symbols operators
&& AND
|| OR
! NOT

OPERATOR COMPOUND
()
! ++ --
* / %
+ -
< <= > >=
== !=
&&
||
=

( HIGHEST PRIORITY: TOP to BELOW !!!!!! )



4. Assignment Operators
Expressions Meaning
a+b=b a=a+b
a*=5 a=a*5
a-+2 a=a-2
a%=3 a=a%3


EX 1:
a=2 b=3
m=2 n=3
p=2 q=3
x-2 y=3

++a + --b * 4 > ++m * --n + 4
1+2 + 3-1 * 4 > 2+1 * 3-1 + 4
3 + 2 * 4 > 3 * 2 + 4 [settle *]
3 + 8 > 6 + 4
11 > 10
= TRUE/ 1

EX 2:
++a + --b * 4 > ++m * --n + 4 && p++ + q-- * 4 < x++ * y-- + 4;
(1+2) + (3-1) * 4 > (1+2) * (3-1) + 4 && 2 + 3 * 4 < 2 * 3 + 4
3 + 2 * 4 > 3 * 2 + 4 && 2 + 12 < 5 + 4
3 + 8 > 6 + 4 && 14 < 9
11 > 10 && 14 < 9
1 && 0
= FALSE/0

PRE! n=5
n --> 5
++n --> 1+5=6
n=6

POST!
n --> 5
n++ -->> 5
n --> 6


EXAMPLE 1:
#include
main()
{
int n;
n=5;
//pre-increment
cout<cout<<++n;
cout<//post-increment
cout<cout<cout<return 0;
}

OUTPUT
5
6
6

5
5
6


EXAMPLE 2:
#include
main()
{
int m;
m=7;
//pre-decrement
cout<cout<<--m;
cout<//post-decrement
cout<cout<cout<return 0;
}

OUTPUT
7
6
6

7
7
6


EXAMPLE 3:

#include
main()
{
int result, a,b,m,n,p,q,x,y;
result=0;
a=6;
b=7;
m=8;
n=9;
p=3;
q=2;
x=4;
y=5;
result=++a + --b * 4 < ++m * --n + 4 || p++ + q-- * 4 > x++ y-- + 4;
cout<<"InResult="<return 0;
}

What is the output of result?
Result=True/1

Thursday, February 17, 2011

Fundamental Of Programming (FOP) - 3rd week

First day of using TURBO C++ software.


Ms. Ayuni asked us to answer a question each for every group present. My group consists of Yani, Mohamad, Azuwan, Badrul, and Amalina. It was a temporary group since a lot of students were not in class yet.



EXERCISE
Multiply and divide 2 FLOAT numbers, num1 and num2.
multiply=num1*num2
divide=num2/num1


FLOWCHART




















# include // header

main () // start body

{ //open curly bracket

// declare variable

float num1;

float num2;

float multiply;

float divide;

// input 1

cout<<"enter num1:";

cin>>num1;

// input 2

cout<<"enter num2:";

cin>>num2;

// formula

multiply=num1*num2;

// output

cout <<"multiply=" <>

// formula

divide=num2/num1;

// output

cout << "divide=" <>

return 0;

} // close curly bracket

// end body



Then Ms. Ayuni asked us to follow instructions as stated below, to open TURBO C++ on the PC;


1. ON your computer --> click "START" -->doubled-click "Computer"














2. Doubled-click " WIN7 C:















3. Choose folder, doubled-click " TC " ,













4. Then choose folder, doubled-click " BIN " ,












5. Then doubled-click " TC " ,













6. Click " Ignore " to go to TURBO C++ ;













7. Click " File ", choose " New " , and may start write your coding using TURBO C++.















We continued with another exercise in our group.


EXERCISE ( TARRAGON )
















#include // header

main() //start body

{//open curly bracket

//declare variable

float bm;

float bi;

float math;

float sains;

float total;

float average;

//input 1

cout<<"bahasa melayu=";

cin>>bm;

//input 2

cout<<"bahasa inggeris=";

cin>>bi;

//input 3

cout<<"matematik=";

cin>>math;

//input 4

cout<<"sains=";

cin>>sains;

///formula

total=bm+bi+math+sains;

//output

cout<<"total=" <>

//formula

average=total/4;

//output

cout<<"average=" <>

return 0;

}//close curly bracket

//end body




NOTES !!!!
  • for INPUT, follow exactly as stated in question. EX: bahasa melayu= .
  • to declare variable, MUST look up in formula given. EX: bm, bi, math, sains.


[[ Weekly reflection & Exercises = group]]
[[ Blog tutorial= individual ]]


Chapter 3 & 4 will be continued on the following week.

-- ALL SMILES -- (",)

Saturday, February 5, 2011

Fundamental Of Programming (FOP) - Chapter 1 & 2.

Class started with a first task - where Ms. Ayuni had asked us to register on a forum as stated below: ( as she wrote on the whiteboard )

-http://lect-ayuni.forumms.net
-Register, click " JOIN " the n check e-mail, followed by clicking on the link given, test your username and password by login the forum.


Step by step to register forum:

1. type URL as given:




2. Click JOIN;



3, Click " I Agree " ;



4. Fill in the blanks with info needed as circled;









5. Next, to confirm password;







6. Next, Account Activation;








7. Login at gmail.com ;












8. Click on the link given for activation;












9. Login with the username&password;









10. Choose " FOP PART TIME " ;








11. " Users granted special access " means ADMIN/creator has not approved user as an official member;









12.Click " REPLY " to add the answer;






13. An example of an answer;














14. Finally, click " LOGOUT " ;










After we done with the registration of the forum, Ms. Ayuni started to explain briefly on the Chapter 1 & 2.
















CHAPTER 1
- Programming & Problem Solving

Example of a simple question:



















NOTES: !!!!!!!!















EXAMPLE:
1. Find the area of a rectangle.
area=width*height










ALGORITHM

1. Get the width of the rectangle.
2. Get the height of the rectangle.

3. Calculate the area using the formula, area equals to width multiplied by height.

4. Display the area of the rectangle.


PSEUDOCODE
1. Read the width.
2. Read the height.
3. Set the area to the width multiplied by height.
4. Print the area.


FLOWCHART



















NOTES !!!!!




























EXERCISE 1:

1. Find the area of a circle
area=3.14*radius*radius












ALGORITHM

1. Get the radius of the circle.
2. Calculate the area equals to 3.14 multiplied by radius by radius.

3. Display the area.


PSEUDOCODE
1. Get radius.
2. Set area=3.14*radius*radius
3. Print output.

FLOWCHART





















EXERCISE 2:
Find celcius
celcius=(5/9)*(fahrenheit-32)

ALGORITHM
1. Get the fahrenheit of celcius.
2. Calculate celcius equals to five divided by nine, multiplied by fharenheit minus thirty two.
3. Display celcius.

PSEUDOCODE
1. Read fahrenheit.
2. Set celcius=
(5/9)*(fahrenheit-32).
3. Print celcius.

FLOWCHART





















EXERCISE 3
Find fahrenheit.
fahrenheit=(9/5)*(celcius+32).

ALGORITHM
1. Read the celcius of the fahrenheit.
2. Calculate fahreheit equals to nine divided by five, multiplied by celcius added thirty two.
3. Display fahrenheit.

PSEUDOCODE
1. Get celcius.
2. Set fahrenheit=(9/5)*(celcius+32).
3. Print fahrenheit.

FLOWCHART






















THE SOFTWARE LIFE CYCLE
1. Problem definiton.
2. Algorithm design.
3. Coding.
4. Testing.
5. Maintenance & evolution of the system.
6. Obsolescence.

PROGRAMMING APPROACHES
1. Procedural programming
  • structured programming;
  • steps taken by program to reach the desired state;

2. STRUCTURED PROGRAMMING
  • composed of simple, hierarchical program flow sructures;
  • 3 flow structures - sequential, selection, repetition;
3. OBJECT ORIENTED PROGRAMMING
  • an extension of precedural programming;
  • have variables/attributes and prececdures/methods;


CHAPTER TWO - C++ BASICS






























NOTES !!!!!!!!

// comment (hidden)
// or /**/ -----> // 1 coding line

-----> /**/ more than 1 coding lin
e
!!semicolon ; = existst in the BODY structure of coding and MUST use it accordingly without FAIL!














RULES 1: Check on the FORMULA given;
RULES 2: FIND how many VARIABLES name;
RULES 3: Declare variables;

INPUT
cout<<" sentences"; cin>>variable_name_that_had_been_declared;

OUTPUT
cout<<"sentences"<< variable_name_that_had_been_declared

** BE CAREFUL with the SPELLING, capital/lower case letters !!!!!!!!!!!! **



" This week Ms. Ayuni taught us theoretically !! Next week we shall start use TURBO C++, to complete our scope in learning programming language or coding in shortword. "


ALL SMILES (",) --