Monday, February 28, 2011

Exercise

1. Write correct C++ syntax & for each statement below:

a) Initializing variable Pi with the value 3.14 (constant)
answer :
float pi =3.142;

b) Declare a variable named Perimeter with double data type (declare variable)
answer :

double perimeter

c) Give instruction that allowed user to input data (input)
answer :
int data;
//input
cout<<"enter your data";
cin>>data;

d) Input number of computer using variable (input assign to variable value)
answer :
int number;
cin>>number;

2. Solve the question below. Show the working.

a) 5 * 2 % 3 + 25 / 5
answer :
= [10%3]+25/5
= 1+[25/5]
= 1+5
= 6

b) a = 5, b = 6
!((a < 3) && (a == 3) || (b > 9))
answer :
= !((5<3)&&(5 == 3) || (6>9))
= !((0)    &&(0)          || (0)
=           !((0)             (0)
=                   !(0)
=                      1

3. Identify syntax errors in the following program. (5errors)

include<iostream.h>
main()
{
float allowance = 300.00, salary;

cout<<"Input Salary = ";
cin>>salary;

TSalary = salary + Allowance;

cout<<"Salary is= "<< salary;
}

answer :
#include<iostream.h>
main()
{
float allowance = 300.00, salary;

cout<<"Input Salary = ";
cin>>salary;

TSalary = salary + Allowance;

cout<<"Total Salary is= "<< Tsalary;

return 0;}
4. Write a program that will calculate the monthly salary for an employee that where Saturday and Sunday are considered as non-working days.
answer :



5. Write a program that calculates the average of 5 numbers that can be input by user.

answer :



6. Write a program that will calculate the area of rectangular, triangle and circle.

answer :









Sunday, February 27, 2011

homework2

Question :
 
OUTPUT:

Subject 1 (0.00) :
Subject 2 (0.00) :
Subject 3 (0.00) :
Subject 4 (0.00) :
Subject 5 (0.00) :

CPA:

FORMULA:
CPA = ((Subject1*3) + (Subject2*3) + (Subject3*2) + (Subject4*2) + (Subject5*4)) / 5
 
 
Answer :
 


homework1

Questions :

OUTPUT:

Assignment 1 (10%):
Assignment 2 (10%):
Assignment 3 (10%):
Assignment 4 (10%):
Assignment 5 (10%):
MidTerm (10%):
Final (40%):

TOTAL (100%):

FORMULA:
TOTAL = Assignment1+Assignment2+Assignment3+Assignment4+Assignment5+MidTerm+Final
 
 
Answer :
 
 

Thursday, February 24, 2011

Weekly Reflection3 : 8 feb 2011

-install turbo C++..
-tutorials blogspot
-buat exercise 2.
-miss bg homework 1 and homework 2

Tuesday, February 22, 2011

Weekly Reflection 2 : Chapter 2 : C++ Basics

C++ Language

consists of 2 basic elements :
  • semantics : a vocabulary of commands that humans can understand and that can be converted into machine language.
  • syntax : a language structure (or grammar) that allows humans to combine these C++ commands into a program that actually does something.
C++ Program

- is a text file containing a sequence of C++ commands put together according to the laws of C++ grammar.

__________ . CPP

# include <iostream.h>  = header
- - - - - - - - - - - - - - - - - - - - - - - - (start)
main (  ) = start
{ // open curly braket
                                        = body
} // close curly braket
- - - - - - - - - - - - - - - - - - - - - - - -(end)

In body

1. Variable
      to declare variable
      data_type  variable _name

Data_type
int          :  integar = real 0-9 only
float       :  float    = decimal
double   :  double = decimal
const      : constant = formula akan jd statik
char       : character = one alphabet only a-z
string     : string = one/more word

2. Input
cout<<"please enter your radius";
cin>>radius;

3. Output
cout<<"area = " << area ;

example :





Questions that will be ask on 1 Feb 2011

Questions :

List the differences of structured programming, procedural programming and object oriented programming.

Answer :

Procedural programming
-Approach specifying the steps the program must take to reach the desired state.
-Using programming languange to create computer memor y locations.
-Also know as routine , subroutines, methods, or functions.
-Defines the variable memory location
-Invokes a eries of procedure to input , manipulate, and output the values stored in those locations.

Structured programming
-Composed of simple , hierarchical program flow structure.
-Three flow structure : sequential , selection, and repitition.
-Sequential refers to a sequence of statements executed in order.
-Selection is executed depending on the state of the program.
-Repitition is execute until the program reaches a certain tate of applied to every element of a collection.
-Associated with a “top-down design” approach.

Object oriented programming
-Is an extension of procedural programming.
-Made up of states and methods (functions).
-State of an object are known as attributes.
-Method(functions)to accomplish tasks.
-The attributes and methods are encapsulated into objects that are then used much like real world objects.
-Programmer are allowed to access to data or procedures only via a specified interface.

 

Exercise 2

Questions :

Calculate 3 numbers with using the formula below:

calculate=(num1*num2)-num3+(num2/num1)

Do a complete C++ Coding.


Answer :





#include<iostream.h>
main()
{
//declare variable
float num1,num2,num3,calculate;
//input1
cout<<"Enter Num1";
cin>>num1;
//input2
cout<<"Enter Num2";
cin>>num2;
//input3
cout<<"Enter Num3";
cin>>num3;
//formula
calculate=(num1*num2)-num3+(num2/num1);
//output
cout<<"Answer is="<<calculate;
return 0;
}



Monday, February 14, 2011

exercise 1

Sum and Minus Two Integers




answer :
#include<iostream.h>
main( )
{
//declare variable
float sum,minus,num1,num2;
//input1
cout<<''num1='';
cin>>num1;
//input2
cout<<''num2='';
cin>>num2;
//formula
sum=num1+num2;
minus=num2-num1;
//output
cout<<''sum=''<<sum;
cout<<''minus=''<<minus;
return 0;
}


Multiply Two Integers



answer : 

#include<iostream.h>
main()
{

//Declare variable
int multiply,num1,num2;

//Input num1
cout<<"Enter num1 =";
cin>>num1;

//Input num2
cout<<"Enter Num 2 =";
cin>>num2;

//Formula
multiply=num1*num2;

//Output
cout<<"mutiply= "<<mutiply;
return 0;
}


Fahrenheit Convert to Celcius

                                                                                       

answer:
#include<iostream.h>
main( )
{

float celcius;
float farenheit;

cout<<"Enter farenheit=";
cin>>farenheit;

celcius=5/9*(farenheit -32);

cout<<"farenheit= "<<farenheit;
cout<<"celcius= "<<celcius;

return 0;
}


Celcius Convert to Fahrenheit

                                                                                       

answer :
#include<iostream.h>
main()
{
float celcius,farenheit;
cout<< "Enter celcius=";
cin>>celcius;
farenheit=9/5*(celcius+32);
cout<<"Celcius="<<celcius;
cout<<"Farenheit="<<farenheit;
return 0;
}


Divide and Modulus Two Integers

                                                                             

answer:
#include<iostream.h>
main( )

{
//declare variable
float divide, modulus, Num1, Num2;
//Input 1
cout<<"Num1= ";
cin>>Num1;
//Input 2
cout<<"Num2= ";
cin>>Num2 ;
//formula
Divide=Num2/Num1;
Modulus=Num1%Num2;
//Output
cout<<"divide="<<divide;
cout<<"modulus="<<modulus;
return 0;
}

Friday, February 4, 2011

Weekly Reflection1 : Chapter1 : programming and problem solving

Algorithm

-a sequence of instrutions to solve a problem.
-it can be written in human language n programming language

example :
area of a rectangle



1. get the width of the rectangle
2. get the heigth of the rectangle
3. calculate using the formula area= width *heigth
4. display the answer


Pseudocode
-is an outline of a program,written in a from taht can easily be converted into real programming statements.

example:
  • read the width
  • read the height
  • set the area to the width multiplied by height
  • print the area
Flowchart
-is a graphic representation of the logic or steps in a program.

example:



Program Design
-divided in to two phase : problem solving phase, implementation phase



The Software Life Cycle
  1. analysis and specification of the task (problem definition)
  2. design of the software (algorithm design)
  3. implementation (coding)
  4. testing
  5. maintenance and evolution of the system
  6. obsolescence


Procedural programming
Approach specifying the steps the program must take to reach the desired state.
Using programming languange to create computer memor y locations.
Also know as routine , subroutines, methods, or functions.
Defines the variable memory location
Invokes a eries of procedure to input , manipulate, and output the values  stored in those locations.
Structured programming
Composed of simple , hierarchical program flow structure.
Three flow structure : sequential , selection, and repitition.
Sequential  refers to a sequence of statements executed in order.
Selection is executed depending on the state of the program.
Repitition is execute until the program reaches a certain tate of applied to every element of a collection.
Associated with a “top-down design” approach.


Object oriented programming
Is an extension of procedural programming.
Made up of states and methods (functions).
State of an  object are known as attributes.
Method(functions)to accomplish tasks.
The attributes and methods are encapsulated  into objects that are then used  much like real world objects.
Programmer are allowed to access to data or procedures only via a specified interface.

Wednesday, February 2, 2011

ema nufrah


ni la si kecik yg bernama nurul fatimah..boley di panggil c kecik atau ema nufrah..nape adanye nme nufrah..?nme nufrah tu adalah gbungan antara nur dan fah tetapi r dan f ditukarkn spaye menjadi nufrah..huhu...ema seorg yg pemalu,pendiam ada msenye dan berckap pun ade mse2nye..kkdg susa di fahami ttpi memahi org lain..ema berminat dgn dunia mathematic tetapi tak minat pd akaun..skrg ema blaja di cosmopoint jb..dgn mngambil dip e-business..skrg nih ema kena amik sbjek fundamental of programming..so,lecturer pun minta student wat blog..memula tu ema tak pandai nk wat blog nihh..so explore la sendiri..so inila hasil yg ema wat..hope blog ni dpt membntu ema dlm ape jua situasi..