Department of Electronic and Information Engineering
EIE2111 Lab 3: Control Statements (Part 1)
Introduction
This laboratory exercise is designed to give you hand-on experience in Control Statements (Part 1).
Questions
1. One large chemical company pays its salespeople on a commission basis. The salespeople each receives $200 per week plus 9 percent of their gross sales for that week. For example, a salesperson who sells $5000 worth of chemicals in a week receives $200 plus 9 percent of $5000, or a total of $650. Develop a C++ program that uses a while statement to input each salesperson’s gross sales for last week and calculates and displays that salesperson’s earnings. You should process one salesperson’s figure at a time. If the input is -1, the program should exit.
2. Write a program that reads the side of a square and then prints a hollow square of that size out of asterisks and blanks. Your program should work for squares of all sides between 1 and 20.
3. A company wants to transmit data over the telephone, but is concerned that its phones could be tapped. All of the data are transmitted as four-digit integers. The company has asked you to write a program that encrypts the data so that it can be transmitted more securely. Your program should read a four-digit integer and encrypt it as follows: Replace each digit by (the sum of that digit plus 7) modulus 10. Then, swap the first digit with the third, swap the second digit with the fourth and print the encrypted integer. Write a separate program that inputs an encrypted four-digit integer and decrypts it to form. the original number.
4. The factorial of anon-negative integer n is written n! and is defined as follows:
a) Write a program that reads anon-negative integer, and computes and prints its factorial.
b) Write a program that estimates the value of the Mathematical constant e by using the formula
Prompt the user for the desired accuracy (i.e., the number of terms in the summation).
c) Write a program that computes the value of ex by using the formula
Prompt the user for the desired accuracy (i.e., the number of terms in the summation).
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.