You are on page 1of 3

UNIVERSITI KUALA LUMPUR

MALAYSIAN INSTITUTE OF INDUSTRIAL TECHNOLOGY

LAB 2
VARIABLE DECLARATION

CLO 3: Integrate various type of computer programming software in order to solve the
control engineering problems. (P4)
CLO4: Combine the computer programming skills competencies to integrate the design,
coding and debugging the computer programs. (P4)

SEMESTER : JANUARY 2018

SUBJECT CODE : JCB 12204

SUBJECT TITLE : COMPUTER PROGRAMMING

SUBMISSION DATE :

NAME :

STUDENT ID :

LECTURER’S NAME :

SUBMISSION DATE :
JCB20204 COMPUTER PROGRAMMING LAB 2

Introduction:

C++ was developed by Bjarne Stroustrup of AT&T Bell Laboratories in the early 1980's, and
is based on the C language. The "++" is a syntactic construct used in C (to increment a
variable), and C++ is intended as an incremental improvement of C. Most of C is a subset of
C++, so that most C programs can be compiled (i.e. converted into a series of low-level
instructions that the computer can execute directly) using a C++ compiler.
C is in many ways hard to categorise. Compared to assembly language it is high-level, but it
nevertheless includes many low-level facilities to directly manipulate the computer's memory.
It is therefore an excellent language for writing efficient "systems" programs. But for other
types of programs, C code can be hard to understand, and C programs can therefore be
particularly prone to certain types of error.

Objectives:
After doing this laboratory exercise, student be able to:
1. Write C++ programs that perform simple computations
2. Read input from the keyboard
3. Use identifiers to name elements such as variables and functions

Getting Started:

1. Explain the C++ keywords. List some C++ keywords you learned in this chapter.
2. Is C++ case sensitive? What is the case for C++ keywords?
3. What is the C++ source file name extension, and what is the C++ executable file name
extension on Windows?
4. What is a comment? What is the syntax for a comment in C++? Is the comment ignored
by the compiler?
5. What is the statement to display a string on the console?
6. What does the namespace std stand for?
7. The C++ compiler command performs three tasks in sequence: preprocessing, compiling,
and linking. Explain the term of pre-processor, compiler and linker.

1|Page
JCB20204 COMPUTER PROGRAMMING LAB 2

Lab Questions:

1. Write a statement (or comment) to accomplish each of the following (assume that using
directives have been used for cin, cout and endl):
a) State that a program calculates the product of three integers.
b) Declare the variables x, y, z and result to be of type int (in separate
statements).
c) Prompt the user to enter three integers.
d) Read three integers from the keyboard and store them in the variables x, y and z.
e) Compute the product of the three integers contained in variables x, y and z,
and assign the result to the variable result.
f) Print "The product is " followed by the value of the variable result. Return a value
from main indicating that the program terminated successfully.

2. Write a program that reads in the radius of a circle as an integer and prints the circle’s
diameter, circumference and area. Use the constant value 3.14159 for π. Do all
calculations in output statements.

3. Write a program that inputs three integers from the keyboard and prints the sum, average,
and product of these numbers. The screen dialog should appear as follows:

4. Write an assignment statement to calculate the elapsed time, in minutes, it takes to make
a trip. The formula for computing elapsed time is elapsed time = total distance / average
speed. Assume the distance is in miles and the average speed is in miles per hour (mph).

5. Determine and correct the errors in the following programs.

2|Page

You might also like