assignment
part 1:
1. Write a program that reads a number in feet, converts it to meters, and displays
the result. One foot is 0.305 meter.
2. (section). Write a program that reads the subtotal and the gratuity rate, then
computes the gratuity and total. For example, if the user enters 10 for subtotal
and 15% for the gratuity rate, the program displays $1.5 as the gratuity and $11.5
as the total. Here is a sample run:
Enter the subtotal: 10
Enter the gratuity rate: 15
The gratuity is $1.5 and total is $11.5
3. Write a program that converts pounds into kilograms. The program prompts the
user to enter a number in pounds, converts it to kilograms, and displays the result.
One pound is 0.454 kilograms. Here is a sample run:
Enter a number in pounds: 55.5
55.5 pounds is 25.197 kilograms
4. (section). Write a program that prompts the user to enter the days and displays
the number of years, months, and days for the days. For simplicity, assume a year
has 365 days and a month has 30 days.
5. Average acceleration is defined as the change of velocity divided by the time taken
to make the change, as shown in the following formula: a = (v1 - v0)/t
Write a program that prompts the user to enter the starting velocity v0 in meters/
second, the ending velocity v1 in meters/second, and the time span t in seconds,
and displays the average acceleration. Here is a sample run:
Enter v0: 5.5
Enter v1: 50.9
Enter t: 4.5
The average acceleration is 10.0889
part 2:
Q1: Write a program to find the maximum value of two variables(then try it using the
comparison operator).
Q2: Write a program to check whether a number is positive or negative.
Q3- Write a program to print the absolute value of a number entered by the user.
Q4: Write a program that takes values of the length and width of a rectangle from
the user and checks if it is square or not.
Q5: Write a program in C++ to find the power of any number using for loop. Sample
Output: Input the base: 2 Input the exponent: 5 2 ^ 5 = 32
part 2:
Q1: Write a program in C++ to find power of any number using for loop.
Sample Output:
Input the base: 2
Input the exponent: 5
2 ^ 5 = 32
Q2: Write a program in C++ to display n terms of natural number and their sum.
Sample Output:
Input a number of terms: 7
The natural numbers up to 7th terms are:
1234567
The sum of the natural numbers is: 28
Q3: Write a program in C++ to display the odd natural and their sum, these numbers are less
than or equal to the number entered by the user.
Sample Output:
Input the upper pound: 7
The odd numbers are: 1 3 5 7
The Sum of odd Natural Numbers upto 7 is 16
Q4:Write a program in C++ to find the Greatest Common Divisor (GCD) of two numbers.
Sample Output:
Input the first number: 25
Input the second number: 15
The Greatest Common Divisor is: 5
Q5: Write a program in C++ to find the factorial of a number.
Sample output:
Input a number to calculate the factorial: 5
The factorial is: 120
Q6: Write a program in C++ to find the power of any number using for loop. Sample
Output: Input the base: 2 Input the exponent: 5 2 ^ 5 = 32