EECE 230 Homework, Fall 2010

American University of Beirut · Introduction to Programming · 2 pages · Prof. Hassan Artail

All EECE 230 files
EECE 230 Homework, Fall 2010, page 1

Stuck on a question? A tutor can walk you through it.

EECE 230 Homework, Fall 2010, page 2

More EECE 230 files

Show the text of this homework
EECE 230 Computers and Programming Lab Assignment # 2 Objectives: To practice if, switch, rand, and while statements. 1. Write a C++ program to allow the user to enter two numbers and one of the operations: +, -, *, /. Your program will print the result of the expression. Notice that division by zero is not allowed and the result of integer division can be with decimals. Use nested ifs. 2. Write a C++ program to allow the random number generator to guess a number between 750 and 1000 inclusive. Then ask the user to guess that number. The program will check the answer and give the user one of three following messages: a- Guess higher, b- Guess lower, c- Correct, number of guesses is X. Example: if the random generator chooses 830 and the user guessed 900. The program will answer Guess lower. Then the user guessed 800 and the program answer Guess higher…. Finally the program will print the number of guesses it took the user to guess the right number. 3. Write a C++ program that uses a while loop and a switch statement to enter a given number of grades then print how many grades there are in the range 90- 100 and in the range 80-89 and so on. Example run would be: Enter number of grades: 5 Enter grade 1: 83 Enter grade 2: 91 Enter grade 3: 86 Enter grade 4: 65 Enter grade 5: 82 The output will be: Range 90-100: 1 Range 80-89: 3 Range 60-69: 1 EECE 230 Computers and Programming Lab Assignment # 1 Objectives: To learn about C++ environment, iostream, cmath, expressions and static_cast. 1. Write a C++ program that will accept the radius of the circle and the program will print the circumference and the area of the circle. 2. Write a C++ program to enter a four digit integer and print the sum of the digits. Example, if the number entered is 3256 then the output will be 16. 3. Write a C++ program to enter 3 grades of type integer, and then find their average. Notice that you have to use static_cast. 4. Write a C++ program named SellStocks that calculates the value of a stock sale. The user will be prompted to enter the stock price, the number of shares to be sold, and the commission rate. The program will calculate the value of shares by multiplying the stock price by the number of shares. It will also calculate the commission (the value of shares multiplied by the commission rate) and the net proceeds (the value of the shares minus the commission). The following example shows what the user will see on the screen: This program calculates the net proceeds from a sale of stock. Enter stock price: 10.125 Enter number of shares: 11 Value of shares: $111.38 Enter commission rate (as a percentage): 1.5 Commission: $1.67 Neat proceeds for XYZ is: $109.71