Activity #1 - Your First Program "Hello World!": Lab 2 Week 3
Activity #1 - Your First Program "Hello World!": 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 (Visual 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.
i. cout << "Hello" << "World" << endl; ii. cout << "Hello" << endl << "World" << endl;
What does this program print?
C. D.
Write three versions of the hello.cpp program that have different syntax errors. Explain each error. Write a version of your program that has a logic error.
May 2012
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 Berhad (NEB) is a domestic company that supplies electricity to various types of consumers such as residential, industrial, commercial and transportation. NEB 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 customers usage is 200 units or less, a rate of 21.8 cent per unit is applied; if the customers usage is more than 200 units, then a rate of 25.8 cent per unit is applied for the first 800 units and 27.8 cent 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 customers 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.
May 2012