You are on page 1of 2

Assignment 3 Part 2

Question 1:
Write a C++ functions-based program that takes 3 inputs from user: ’Start’ that denotes the start of the series, ‘End’ that
denotes the end of the series, and ‘Jump’ that denotes the difference between 2 numbers in the series in function
printSeries. Sample input output cases are provided below:
Input case 1: Input case 2:
Start ==> 10 Start ==> 12
End ==> 37 End ==> 61
Jump ==> 5 Jump ==> 10
Output case 1: Output case 2:
10, 15, 20, 25, 30, 35 12, 22, 32, 42, 52
Question 2:
Write a C++ program that takes an integer from user, and checks if it is divisible by 10. If it is divisible, it outputs that the
number is indeed divisible by 10. Otherwise it tells how many numbers you need to add to the number to make it
divisible by 10.
Input case 1: Input case 2:
num = 50 num = 1562
Output case 1: Output case 2:
50 is divisible by 10. 1562 is not divisible by 10. You must add 8 to it to
make it divisible by 10.
Question 3:
Write a C++ functions based program that outputs the first 10 numbers of the Fibonacci series.
Fibonacci series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,

Hint: First 2 numbers of Fibonacci series are 0 and 1 respectively. Each new value is generated by adding previous 2
values. (Can you tell when the series till end?)
Question 4:
Write a C++ program with function that takes ‘num1’ and ‘num2’ from user and swap the contents of num1 and num2
and print the values of num1 and num2 after swapping.
Swapping of two variables refers to mutually exchanging the values of the variables. For example
Original values after swapping:
num1 = 10 num1 = 20
num2 = 20 num2 = 10
Hint: Use a temporary variable to swap values of two variables.
Question 5:
Write a C++ program with function that takes as argument ‘num1’ and ‘num2’ and checks if num1 is larger than num2. If
yes, then output that num1 is already larger than num2. If not, then you must swap the contents of num1 and num2 and
then output that after swapping num1 is larger than num2. Be sure to print the values of the variables on screen as well
in parenthesis.
Input case 1: Input case 2:
Num1 = 50 Num1 = 44
Num2 = 6 Num2 = 100
Output case 1: Output case 2:
First num1(50) is larger than num2 (6)! After swapping num1(100) is larger than num2 (44)!
Question 6:
Ask user to enter numbers. Keep taking numbers until user enter 5 positive even numbers. In the end, display how many
numbers are entered by user (including positive and negative numbers).

Question 7:
Ask user to enter numbers. Keep taking numbers until user enter 5 positive numbers. Simultaneously calculate the sum
of given positive even numbers. In the end, display how many numbers (positive + negative) are entered by user and the
calculated sum.

Question 8:
Write a program using iteration statement for number guessing game. Here is the sample output of this program if user
guesses number correctly in 6 attempts: (Note: Maximum tries should not be exceeded 10).

I am thinking of a number...What is your guess? 15


Your guess was too low
Try again...What is your guess? 45
Your guess was too high
Try again...What is your guess? 20
Your guess was too low
Try again...What is your guess? 25
Your guess was too low
Try again...What is your guess? 40
Your guess was too high
Try again...What is your guess? 30

**** Congratulations! You got it right!


It took you only 6 tries to guess.
Question 9:
Write a C++ program with function ‘easySin()’ that takes a number ‘x’ as input and calculates its simplified sine
expansion series. The series expansion is given below, and you must calculate first 10 values of the series using loop.

Sine Series:
Sin(x) = x – x/3 + x/5 – x/7 + x/9 – x/11 + x/13 – x/15 + x/17 – x/19
Input:
x=5
Output:
Sin(5) = 3.8023
Bonus:
Print the whole series as well the result on screen as shown below.
Sin(5) = +5–5/3+5/5–5/7+5/9–5/11+5/13–5/15+5/17–5/19 = 3.8023

You might also like