ASSIGNMENT -1
ISSUE DATE : 12/03/2025 SUBMISSION DEADLINE : 27/03/2025
1. Which of the following are invalid identifier:
(i) 12amd
(ii) Intel1
(iii) Pentium 3
(iv) Pentium_4
v) Email
(vi) %age
vii) no return
(viii) I am Correct
Modify the invalid identifier such that it becomes a valid identifier, by adding, removing,
or modifying no more than 2 characters.
2.Write C++ programs for:
(i) Input radius and height of a cylinder and compute its surface area and
volume.
(ii) Compute the sum and average of 100 given numbers.(you may make array)
(iii) The computer should ask you about what you would do if found a moneybag?
Display the question and your answer on the screen.
(iv) Input a student’s marks out of 400 and display the percentage.
3. Write a program that reads the radius of a circle as a float data type. The program then
computes and prints the diameter, circumference, and area of the circle. If the user
enters a negative value of radius, an error message must be printed.
4. Write a C++ program to find the square of the numbers from 1 to 10 using
a) while loop
b) do..while loop
c) for loop
5. Write a C++ program to find the sum of the first 20 terms of the following series:
SUM=1 – (1/1!) + (2/2!) – (3/3!) + (4/4!)…………..(n/n!)
6. Write three separate C++ programs to compute the factorial of a number ‘n’. The
programs should read ‘n’ from the user(should include all possibility of n such as n is
negative ,zero, positive) and must use the following for their implementation
(i) for-loop
(ii)while-loop
iii) do-while loop
7. Write a program in C++ to check whether a given 5 digit number is a Palindrome or not
using a do…while loop. Check your program for 37873 and 37837.
8. Write a C++ program to change the letter case (upper case to lower case and vice
versa).
9. Write a C++ program to print 50 multiplication tables upto 10 using double for loop.
10. Write a program in C++ to read a set of 10 positive integers and display them all. If
the number entered is nonnegative, the program continues, but when the user inputs a
negative number the program stops further reading and displays – “A NEGATIVE
NUMBER ENTERED”.
11. Write a C++ program that reads three nonzero double values and determines and
prints whether they could represent sides of a triangle.
12. Write a C++ program to calculate the roots of a quadratic equation ax^2 +bx +c =0.
Include all cases, a+0, a ≠ 0, equal roots, unequal roots, real or complex.
13. Write a C++ program to read a number n and digit d and check whether d is present
in n. If it is so, find out the position of d in number n.For example in the case of n=45678
and d= 5 , the digit 5 is present in the number at the position 4 from right.
14. Write functions float sphere_volume( float radius), cylinder_volume ( float radius,
float height) and cone_volume ( float radius, float height). Give the value of π using
define directive. Write main to test these functions. Also display the output.
15. Write a function DotProduct which takes four parameters of float type and
computes the dot product of two two-dimensional vectors and returns the dot product
as float type. The parameters are: x1, y1, x2 and y2. Write another function with the
same name which takes six parameters of float type and computes the dot product
of two three-dimension vectors and returns the dot product as float type. The
parameters are: x1, y1, z1, x2, y2 and z2.
16. (i)What is the difference between passing parameters by value and by
reference in a function? Use suitable examples to demonstrate the difference.
(ii)Write two versions of a function that multiply the next higher values of its two
integer parameters: int prod (int x, int y) [parameters passed by value, result returned
after changing x to x+1 and y to y+1 within the function] and int prod1(int& x, int& y)
[parameters passed by reference, carrying out the same multiplication as earlier].
Call these functions in the main and display the output. Demonstrate the difference
in the value of the parameters after calling of these two functions in the main.
17. Write functions int rectangle_area( int length, int height), float rectangle_area(
float length, float height), void rectangle_area( int length, int height). The task of
these functions is to calculate the area of the rectangle. Write main to execute these
functions and display the output.
18. Write inline functions square_ and cube_ which take int as parameters. These
functions return square and cube of integer, respectively. Also write functions
square_of_integer and cube_of_integer which take integer as parameters and return
square and cube of integer to main, respectively. Write main to test these functions.
Understand how these functions are called in the main.
19. Write main to test each of these recursive functions.
(i) the greatest common divisor of two integer
(ii) factorial of an integer number,
(iii) fibonacci number
(iv) power of an integer number
(v) to convert a decimal integer number into a binary number
20. Write a function int rectangle_area with default parameters to compute the
area of the rectangle having length and height equal to 1 (one). How this function
can be called in the main to compute the area of the rectangle having (i) length = 10
and (ii) length = 10 and width = 5.
21. Write a function descendingSort of type void which uses bubblesort technique
to sort an integer array in descending order. Write main to test this function and to
display the unsorted and sorted array.
22. Write functions: i) ReadMatrix to read elements of matrix row-wise, ii)
DisplayMatrix to display the matrix row-wise, ii) AddMatrices to add two matrices,
and iv) MultMatrices to multiply two matrices. Give size of rows and column as const
int global variables. All these functions are of void type. The functions should carry
out addition and multiplication of two matrices. The result should be displayed inside
the function DisplayMatrix. Write a main to test these functions.