You are on page 1of 9

BCS 1214

PROGRAMMING TECHNIQUE

ASSIGNMENT 1

NAME : MATRIC NO. : COURSE : LECTURER :

MOHD SHAH SHAFIE BIN IDRIS 10B07016 BACHELOR OF COMPUTER SCIENCE ( COMPUTER NETWORK & SECURITY) EN. MOHD NAZRI B. IBRAHIM

PART 1 i) Pseudocode ii)Flowchart

iii) C++ program

1. Develop a program to input height and length of a right triangle and calculate, print the area of a right triangle. Area of right triangle = (height x length) /2

1.1 Pseudocode - Prompt user to insert height and length - Read height and length - Calculate (height x length) /2 - Display payment. 1.2 Flowchart
START

INPUT: Height, Length

Area = (Height x Length) / 2

OUTPUT : Area

END

1.3 C++ Program #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { double height, length, area; cout<<"please enter height = "; cin>>height; cout<<"please enter length ="; cin>>length; area = (height*length)/2; cout<<"Area of triangle = "; cout<<area<<endl; system("PAUSE"); return EXIT_SUCCESS; }

2. Write a program that prompt and read your age in years and output yaour ages in days. You may assume that there ar 365 days in a year.

2.1 Pseudocode - Prompt age value - Read age - Calculate age x 365 - Display ages in days

2.2 Flowchart
START

INPUT : Age

Age in days = Age x 365

OUTPUT : Age in days

END

2.3 C++ Program

#include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int age,days; cout<<"Your age = "; cin>>age; days = age*365; cout<<"Your age in days = "<<days<<endl; system("PAUSE"); return EXIT_SUCCESS; }

3.0 Write C++ program to input your name, age, height in cm and weight in kg and display the following results :

Name : Abu Bakar Bin Rahman Age : 19 Height : 179 cm Weight : 60 kg

3.1 Pseudocode Prompt user to enter name Read name Prompt user to input age Read age Prompt user to enter height Read height Prompt user to enter weight Read weight Display name, age, height and weight.

3.2 Flowchart

3.3 C++ program #include <cstdlib> #include <iostream>

using namespace std; int main(int argc, char *argv[]) { char Name[20]; int Age, Height, Weight;

cout<<"Please enter name, age, height and weight\n"; cin.getline(Name,20); cin>>Age>>Height>>Weight; cout<<"\nName :"<<Name; cout<<"\nAge :"<<Age; cout<<"\nHeight :"<<Height<<" cm"; cout<<"\nWeight :"<<Weight<<" kg"<<endl;

system("PAUSE"); return EXIT_SUCCESS;

PART 2 : i) Pseudocode

ii) Flowchart

4.0 Write a program that input a grade. If the grade is less than 0 or greater than 100, your program Should print the appropriate message informing the user that an invalid grade has entered.

4.1 Pseudocode Prompt user to insert grade Read grade Determine grade is less than 0 or greater than 100 (0>grade>100) Display invalid grade has entered

4.2 Flowchart

5.0 Write a program that read an integer from the user and determines and print whether it is odd or even (Hint : use modulus operator) 5.1 Pseudocode - Prompt input number from user - Read number - Calculate num%2==0 - Decision if num %2=0 - Prompt even number. - Decision if num %2 !=0 - Prompt odd number.

5.2 Flowchart

6.0 Write a program that input ten (10) integers. Print out the sum of those integers.

6.1 Pseudocode Read num Read num 1 to 10 integer number Calculate sum of num. Prompt sum.

6.2 Flowchart

You might also like