0% found this document useful (0 votes)
21 views

ENG3202 Lab Report 2 - User Input

ENG3202 Lab Report 2 - User Input This is example of Lab report that I sent to my Lecturer, Hopes it Helps.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

ENG3202 Lab Report 2 - User Input

ENG3202 Lab Report 2 - User Input This is example of Lab report that I sent to my Lecturer, Hopes it Helps.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Lab-Report 2

ENG3202
Name: Fakhrul Hakim bin Anwar
No. Matrik: 228724

OCTOBER 30

COMPUTER PROGRAMMING

1
ENG3202 Computer Programming 2024-2025 LAB 2: USER INPUT

Question 1
Write a program that will prompt the user to input the height, length and width of
a box in centimeters. From the user input the program must calculate and display
box’s volume.

Pseudocode:
1. Start the program
2. Declare your variable Height, length , width and Volume in float value
3. Put the Height Value
4. Put the length Value
5. Put the width Value
6. State the Volume formula ‘ Volume = Height x length x width ‘
7. Display the value of the Volume in float value
8. End Program.

Flow Chart

2
ERROR

Debug

Output
3
4
Question 2
Write a program that simulates an odometer. The user inputs the speed (in kmph)
and time the vehicle has traveled (in seconds!!). From the user input, the program
must calculate and display the distance traveled. The program must also display
the speed and time entered by the user.

Pseudocode:
1. Start the Program
2. Declare your Variable Speed, Time and Distance as Float Value
3. Put the value of Speed in kmph
4. Put the value of Time in seconds
5. Calculate the Distance by using the formula ‘ Distance = Speed x time/3600

6. Display the value of the Distance
7. End of program

5
Flow Chart

6
Error

At this error I got the output 0.000 where I shouldn’t have gotten that result. I
notice that I use %f for Distance where it has been stated that its integer.

7
Debug

Output

8
Question 3
Given by a user are the x- and y- coordinates of two points in a plain: (x1, y1) and
(x2,y2). Write a C program that will compute and print the distance between
these two points using given below.
𝑫𝒊𝒔𝒕𝒂𝒏𝒄𝒆 = √(𝒙𝟏 − 𝒙𝟐 )𝟐 + (𝒚𝟏 − 𝒚𝟐 )𝟐

Pseudocode:
1. Start the program.
2. Declare your Variable X1 , Y1, X2, Y2, and Distance, as Float Value.
3. Print ‘This program will calculate the distance between two points (x1,y1)
and (x2,y2) ‘
4. Put the value of X1
5. Put the value of Y1
6. Put the value of X2
7. Put the value of Y2
8. Calculate the value of distance using the equation
𝑫𝒊𝒔𝒕𝒂𝒏𝒄𝒆 = √(𝒙𝟏 − 𝒙𝟐 )𝟐 + (𝒚𝟏 − 𝒚𝟐 )𝟐
9. Print the Value of Distance.
10.End of Program

9
Flow Chart

10
Error

Debug

11
Output

12
Discussion and Analysis

1) For question 1 , The Program was conducted to find the Volume of a Box .
By putting scanf, User can put any Value of height length and width of any
variation of Boxes to find the Volume of it. Volume was found by using
the formula Volume = height x length x width . From my Output picture
given the volume is 8 when height = 2 , length=2 and width=2 meaning
the program works as it intended to. The program was successful after 3
times compiling it . I got some error like Forgot to put ‘;’ at the end of
each command and some spelling error

2) For Question 2, The program was conducted to find the distanced


traveled when Speed in Kmph and time in seconds are given. By putting
scanf, User can put any Value of their speed and seconds but with the
units kmph and Seconds only. The distance traveled is determine by using
the formula Distance = Speed x Time/3600 . From my Output picture
Given the Distance traveled is 45 Km when the speed= 90Kmph Time=
1800seconds . The program was successful after 4 times compiling it . It
got some simple error like Missing ‘;’ , Some spelling error , the output got
some mistake where the Distance are %f while It stated that distance is
integer.

3) For Question 3, The program was conducted to find the distanced


between two points of coordinates. By putting scanf , User can use any
points to find the distance between 2 points of coordinates choosen. The
distance between two points are calculated by using the formula
𝑫𝒊𝒔𝒕𝒂𝒏𝒄𝒆 = √(𝒙𝟏 − 𝒙𝟐 )𝟐 + (𝒚𝟏 − 𝒚𝟐 )𝟐 . From my Output picture Given
the distance is 12.086 when the two coordinates is (1,0) and (9,10) .
The program was successful after 3 times compiling it . The error I
ecountered is only a common one where forgot to put epsilon and some
spelling error.

13

You might also like