Cosc1415/cosc1436 | Computer Science homework help

  

COSC1415/COSC1436

Lab – Chapter 5A

Objective: To learn how to use looping structures, especially while loops, in a program

At the end of this lab you should know how to:

1. incorporate while loops in a program.

2. use selection, repetition, files and value-returning functions in a program.

Remember to put a line in each program that identifies you as the programmer.

Lab 5A1:  Write a program that reads the radius of a circle from a file (circles.txt). The program should use value-returning functions to calculate the area and circumference. Declare  π (pi) as a constant that equals 3.1416. The program should use a priming read and a while loop that terminates when there is no more data in the file. The output should be sent to a file and include a title and be displayed (with one decimal place) similar to what you see below. Don’t forget to put the <your name> statement in your program.

Radius Area Circumference

5.6  98.5  35.2

123.5  47877.7   775.7

Save a copy of the program and the output file.

Lab 5A2:  Write a program that reads test scores (four scores for each student) from a file (tests.txt). The program should use value-returning functions to determine the test average. (The test average is the average of the three highest test scores.). The program should use priming read and a while loop that terminates when there is no more data in the file. The program should output the four test scores rounded to one decimal place and the average rounded to two decimal places to a file. The labeled output should look similar to what you see below: Don’t forget to put the <your name> statement in your program.

Test 1 Test 2 Test 3 Test 4 Average

 75.0  85.0   95.0  65.0   85.00

 87.5  91.5  66.5  78.5  85.83

Save a copy of the program and the output file.

When you have completed the entire lab, you should e-mail the assignment to me. The subject line should be – C++ CHAP5A LAB

The following five files should be attached to the e-mail

This assignment with your name

Program for Lab5A1 and its output file

Program for Lab5A2 and its output file