Department of Electronic and Information Engineering
EIE2111 Lab 4: Control Statements (Part 2)
Introduction
This laboratory exercise is designed to give you hand-on experience in Control Statements (Part 2).
Questions
1. Write a program that uses a for statement to calculate and print the average of several integers. Assume the last value read is a sentinel value of-100.
2. Write a program that uses a for statement to find the smallest integer among several integers. Assume that the first value read specifies the number of integers remaining. Note that the first number is not one of the integers to compare.
3. Write a program that uses for statements to print the following patterns. Note that all asterisks (*) should be printed by a single statement of the form cout << ‘*’.
[Hint:
a. You should print each pattern separately at the beginning and then combine them together after that.
b. The last two patterns require that each line begin with an appropriate number of blanks.]
4. Calculate the value of π from the infinite series below:
Print a table that shows the approximate value of π in the first 1,000 terms of this series. The approximation should be printed after each 100 terms (i.e., 100th term, 200th term, and so on until 1000th term.)
5. Combine the above four programs into one. The following is the sample output:
Instructions
a. You are required to submit your C++ programs (the whole projects created in Microsoft Visual Studio 2019) in Question 5 to Blackboard. Zip all of them into a single file.
b. The deadline of the submission: Check the course information.
c. It is not required to create any classes or header files for the above exercises. It is fine if all program codes are in the main program.
Reviews
There are no reviews yet.