Sunday, February 27, 2011

Assignment 1

1.       Write correct C++ syntax & for each statement below:
a)    Initializing variable Pi with the value 3.14 (constant)

//variable Pi
Float Pi = 3.14

b)      Declare a variable named Parameter with double data type (declare variable)

//variable Parameter
Double Parameter = 9.212156867

c)       Give instruction that allowed user to input data (input)

Cout<<”Please Input Your Data Here”;
Cin >>data;

d)      Input number of computer using variable (input assign to variable value)

//variable noc=number of computer
Int noc;

2.    Solve the question below. Show the working.
a)    5 * 2 % 3 + 25 / 5

(5*2 % 3) + (25 /5)
1 + 5 = 6

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

3.    Identify syntax errors in the following program.

include<iostream.h>
main()
{
float allowance = 300.00, salary
, TSalary;
cout<<"Input Salary = ";
cin>>salary;
TSalary = salary + Allowance;
cout<<"Salary is= "<< T
Salary;
}




4.    Write a program that will calculate the monthly salary for an employee that where Saturday and Sunday are considered as non-working days.
#include <iostream.h>
main()
{
      //declare
      float basic, payment, total ;
      //intput
      cout<<"Enter basic=";
      cin>>basic;
      cout<<"Enter payment=";
      cin>>payment;
      //process
      total= (payment*22)+basic;
      //output
      cout<<"Your salary="<< total;
      return 0;
 }

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

#include <iostream.h>
main()
{
//declare
int num1, num2, num3, num4, num5, average;
//input
cout<<"Enter 5 numbers=";
cin>>num1;
cin>>num2;
cin>>num3;
cin>>num4;
cin>>num5;
//process
average= (num1+num2+num3+num4+num5)/5;
//output
cout<<"Total average="<<average;
return 0;
}


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

Rectangular

#include <iostream.h>
Main()
{
//declare
Float h, w, area;
//input
Cout<<”Enter your height=”;
Cin>>h;
Cout<<”Enter your width=”;
Cin>>w;
//process
Area= h*w;
//output
Cout<<”Total of area=”;
Return 0;
}

Triangle

#include <iostream.h>
main()
{
      //declare
      float b,h, area;
      //input
      cout<<"Enter base=";
      cin>>b;
      cout<<"Enter height=";
      cin>>h;
      //process
      area= b*h*0.5;
      //output
      cout<<"Total area="<< area;
      return 0;
      }

Circle

#include <iostream.h>
main()
{
      //declare
      float r,pi=3.14, area;
      //input
      cout<<"Enter radius=";
      cin>> r;
      //process
      area= r*r*pi ;
      //output
      cout<<"Total area="<< area;
      return 0;
      }







No comments:

Post a Comment