Assignment
Assignment
Q1: Write a program to print the following text on the console screen.
Welcome to C++
Welcome
to
C++
Q3: Write a program that takes two integer numbers from the user and print their sum on console screen.
Q4: What are Arithmetic operators? Write the rule of precedence for the Arithmetic operators.
Q6: Write a program that take two numbers and operation to perform on those numbers as input from the
user and print the result of operation on console screen.
(Hint: Use if-statements to identify the required operation)
Q7: Write a program that asks user to enter two integers, obtains the numbers from the user, and then
prints the larger number followed by the words “is larger.” If the numbers are equal, print the
message “These numbers are equal.”
Q8: Write a program that inputs three integers from the keyboard and prints the sum, average, product,
smallest and largest of these numbers. The screen dialog should appear as follows:
Q9: Write a program that reads an integer and determines and prints whether its odd or even.
Q10: Write a program that inputs a five digit integer, separates the integer into its digit and prints them
separated by three spaces each. For example, if the user types in 42339, the program should print:
4 2 3 3 9
Q11: Develop a C++ program that uses a while statement to determine the gross pay for each of several
employees. The company pays “straight time” for the first 40 hours worked by each employee and pays
“time-and-a-half” for all hours worked in excess of 40 hours. You are given a list of the employees of the
company, the number of hours each employee worked last week and the hourly rate of each employee.
Your program should input this information for each employee and should determine and display the
employee’s gross pay.
By:
Hafiz Muhammad Furqan
Assignment Computers & Programming (EE-163)
NED University of Engineering & Tech. Department of Electrical Engineering
Spring Semester-2019 FE-EE
Sample Output:
Q12: Write a program that ask user to enter an integer number and evaluates its factorial. Your program
should print the output as below,
Enter an integer : 5
5 x 4 x 3 x 2 x 1 = 120
Q13: Write a program that ask user to input the number of elements in a Fibonacci sequence and then
generates a Fibonacci sequence up-to the given number of elements.
(Hint: In Fibonacci sequence, the next element is the sum of two previous values)
Sample Output:
Q14: Write a program that reads three non-zero double values and determines and prints whether they
could represents sides of triangle.
[Hint: a,b and c represents sides of triangle if following criteria is met,
a+b>c
a+c>b
b + c > a]
Sample Output:
By:
Hafiz Muhammad Furqan
Assignment Computers & Programming (EE-163)
NED University of Engineering & Tech. Department of Electrical Engineering
Spring Semester-2019 FE-EE
Q15: Write a program that reads three non-zero double values and determines and prints whether they
are sides of right triangle. The program should verify the results up to 4 decimal places.
[Hint: Use Pythagoras theorem to determine whether the three sides form right triangle.]
Sample Output:
Q16: Write a program that ask user to input a floating point number and computes exponential of that
number using Taylor series as below,
=1+ + + +⋯
1! 2! 3!
Also, prompt the user for desired accuracy of e (i.e., the number of terms in summation).
Sample Output:
Q17: Write a program that ask user to input angle in radians and computes its sine using Taylor series as
below,
(−1)
sin( ) =
(2 + 1)!
Also, prompt the user for desired accuracy of sine. (i.e., the number of terms in summation).
Sample Output:
By:
Hafiz Muhammad Furqan
Assignment Computers & Programming (EE-163)
NED University of Engineering & Tech. Department of Electrical Engineering
Spring Semester-2019 FE-EE
Q18: Write a program that prints the following pattern as shown below,
* ********** ********** *
** ********* ********* **
*** ******** ******** ***
**** ******* ******* ****
***** ****** ****** *****
****** ***** ***** ******
******* **** **** *******
******** *** *** ********
********* ** ** *********
********** * * **********
You can make separate programs for all these four patterns. Extra Credit: If all the four patterns are
printed in a single program.
[Hint: Use nested for loop].
Q20: Modify the program in Q19 to read an odd number in the range of 1 to 19 to specify the number of
rows in the diamond, then display a diamond of appropriate size.
Q21: A right triangle can have sides that are all integers. A set of three integer values for the sides of a
right triangle is called a Pythagorean triple. These three sides must satisfy the relationship that the sum of
the squares of two of the sides is equal to the square of the hypotenuse. Find all Pythagorean triples for
side1, side2 and hypotenuse all no larger than 500. Use a triple-nested for loop that tries all
possibilities.
By:
Hafiz Muhammad Furqan