0% found this document useful (0 votes)
10 views7 pages

Lab 02 Arithmetics

CS100 LAB 2

Uploaded by

mibrahim13as
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views7 pages

Lab 02 Arithmetics

CS100 LAB 2

Uploaded by

mibrahim13as
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Department of Computing

Arithmetic Operations

CS-110: Fundamentals of Computer


Programming

Mr. Jaudat Mamoon

CS-110 Fundamentals of Computer Programming


Learning Objectives
After completing this section you will be able to:
CLO 1 Understand the syntax and semantics of different (following) programming constructs

1. Do variable declarations and initializations.


2. Perform arithmetic in C++
3. Read numbers from the user using cin command

CS-110 Fundamentals of Computer Programming Page 2


Binary Arithmetic Operator

Cin in C++

[Type text] Page 3


Lab Tasks

[Type text] Page 4


1. Write a program that inputs three different integers from the keyboard, and then prints the
sum, the average, the product. The screen dialogue should appear as follows:

2. Write a program that inputs one five-digit number. Separates the number into its
individual digits and prints the digits separated from one another by three spaces each.
For example, if the user types in 42139, the program should print

3. Write a program that reads in the radius of a circle and prints the circle’s diameter,
circumference and area. Use the constant value 3.14159 for π. Perform each of these
calculations inside the cout statement(s).

4. Using only the techniques you learned in this chapter, write a program that calculates the
squares and cubes of the numbers from 0 to 10 and uses tabs to print the following table
of values:

[Type text] Page 5


5. (Body Mass Index Calculator) To determine whether a person is overweight or obese,
one can use a measure called the body mass index (BMI). The formulas for calculating
BMI are

Create a BMI calculator application that reads the user’s weight in pounds and height in
inches (or, if you prefer, the user’s weight in kilograms and height in meters), then
calculates and displays the user’s body mass index. Also, the application should display
the following information from the Department of Health and Human Services/National
Institutes of Health so the user can evaluate his/her BMI:

6. A company wants to transmit data over the telephone, but they are
concerned that their phones may be tapped. All of their data is
transmitted as four-digit integers. They have asked you to write a
program that will encrypt their data so that it may be transmitted
more securely. Your program should read a four-digit integer and
encrypt it as follows: Replace each digit by the remainder after (the
sum of that digit plus 7) is divided by 10. Then, swap the first digit
with the third, and swap the second digit with the fourth. Then print
the encrypted integer. Write a separate program that inputs an
encrypted four-digit integer and decrypts it to form the original
number.

Enter a four-digit number to be encrypted: 5678


Encrypted number is 4523

Enter the four-digit number to be decrypted: 4523

[Type text] Page 6


Decrypted number is 5678

7. (Financial application: compound value) Suppose you save $100


each month into a savings account with the annual interest rate 5%.
Thus, the monthly interest rate is:

0.05/12 = 0.00417

After the first month, the value in the account becomes:

100 * (1 + 0.00417) = 100.417

After the second month, the value in the account becomes:

(100 + 100.417) * (1 + 0.00417) = 201.252

After the third month, the value in the account becomes:


(100 + 201.252) * (1 + 0.00417) = 302.507
and so on. Write a program that prompts the user to enter a monthly
saving amount and displays the account value after the sixth month.

[Type text] Page 7

You might also like