## CS110 Lab #4 In-lab Exercise:

### Objectives

• Arithmetic Expressions
• Formatting the Output
• Input Stream
• File Input and Output

Lab material

### Exercise #1

• Get a copy of the readdata.cpp file by:
• Entering the cp command:
• or, using your mouse to copy and paste the program into Pico, or
• using the Hercules command-line ftp program to copy this file from the CS Department's anonymous ftp site.
```
The path:	pub/class/110/ftp/cpp/io

```

The purpose of the program is to demonstrate how to INPUT data from the standard input device (the keyboard)
and how to OUTPUT data to the standard output device (screen) in certain format.

• Add code to the program to complete it.
• Compile and run this C++ program.
• Perform a screen capture of the program run and show your readdata.log file to your lab instructor.

### Exercise #2

Write a program to find the area of a triangle given the length of its base and height.
```  Algorithm:

1. Read the values of the base and height of the triangle.
2. Determine the area of the triangle using the formula,
A = (1/2)*base* height.
3. Output the area of the triangle.
```
• Create a file called area.cpp
• Compile and run this C++ program.
• Compile and run this C++ program with different input values.
• Show your lab instructor the scripted output file area.log