Vous êtes sur la page 1sur 2

Fundamental Programming

LAB 2 Week 3

LAB 2 WEEK 3

Objective
1. To become familiar with compiler
2. To compile and run your first C++ program.
3. To recognize syntax and logic errors.
4. To design algorithms using flowchart and pseudocode.

Deliverables:
Simple C++ programs.
Flowchart and pseudocode.

Activity #1 – Your First Program “Hello World!”

A. Open your C++ development environment (Turbo C++ or DevC++) on your


own computer. Enter the program statements into a text editor.

Save the file to disk as hello.cpp. Compile and run the program.

NOTE: If you have the problem with the MSDOS display, Add
system("pause"); before return(0); to pause the output display.

B. Modify your code, compile and run the program.

i. cout << "Hello" << "World" << endl;


ii. cout << "Hello" << endl << "World" << endl;

What does this program print?

C. Write three versions of the hello.cpp program that have different syntax
errors. Explain each error.

D. Write a version of your program that has a logic error.

1 Sep 2012
Fundamental Programming
LAB 2 Week 3

Activity #2

A program is required to read from screen the length and width of a rectangular
house block and the length and width of the rectangular house that has been built on
the block. The program should then compute and display the mowing time required
to cut the grass around the house at the rate of two square meters per minute.

1. Determine the input(s) and output(s) of the program.


2. Write the pseudocode for the program.
3. Desk check with one set of test data.

Activity #3

National Energy Company (PLN) is a domestic company that supplies electricity to


various types of consumers such as residential, industrial, commercial and
transportation. PLN records its customers electricity usage figures on a customer
usage file. Each record on the file contains the customer id, name/owner, address
and their electricity usage expressed in unit for each kilowatts/hour used.
For the residential type of customer, the company bills its customer according to the
following rate: if the customer’s usage is 200 units or less, a rate of Rp 700 per unit
is applied; if the customer’s usage is more than 200 units, then a rate of Rp 850 per
unit is applied for the first 800 units and Rp 1000 per unit for the remaining usage.

Design a program for this company that will read the customer usage file, calculate
the amount owing for electricity usage for each customer and print a report listing
each customer’s id, name/owner, address, their electricity usage and the amount
owing. At the end of the report, print the total number of customers and the total
amount owing to the company. Use flowchart to design your proposed algorithm.

References:
Labsheet materials of Structured Programming & Database lab. class,
Computer & Information Sciences Department., University Technology Petronas.

2 Sep 2012

Vous aimerez peut-être aussi