C++ Assignment
C++ Assignment
Assignment 7 - Functions
Questions:
1. Write a function to get an array of integers as input parameters and print it.
2. Write a function to display an array in reverse order.
3. Write a function to find the sum of all elements of the array.
4. Write a function to copy the elements of one array into another array.
5. Write a function to count a total number of duplicate elements in an array.
6. Write a function to print all unique elements in an array.
7. Write a function to merge two arrays of same size sorted in decending order.
8. Write a function to count the frequency of each element of an array
9. Write a function to find the maximum and minimum element in an array.
10. Write a function to separate odd and even integers in separate arrays.
11. Write a function to sort elements of array in ascending order.
12. Write a function to sort elements of the array in descending order.
13. Write a function to insert New value in the array (sorted list )
14. Write a function to insert New value in the array (unsorted list ).
15. Write a function to delete an element at desired position from an array.
16. Write a function to find the second largest element in an array.
17. Write a function to find the second smallest element in an array.
18. Write a function to get input from user for a 2D array of size 3x3 and print the matrix.
19. Write a function to add two Matrices of same size.
20. Write a function to subtract two Matrices
21. Write a function to multiply two square Matrices.
22. Write a function to find transpose of a given matrix.
23. Write a function to find sum of right diagonals of a matrix
24. Write a function to find the sum of left diagonals of a matrix.
25. Write a function to find sum of rows an columns of a Matrix.
26. Write a function to print or display the lower triangular of a given matrix.
27. Write a function to print or display upper triangular matrix
28. Write a function to calculate determinant of a 3 x 3 matrix.
29. Write a function to accept two matrices and check whether they are equal.
30. Write a function to check whether a given matrix is an identity matrix.
31. Write a function to find a pair with given sum in the array
32. Write a function to find the majority element of an array.
33. Write a function to find the number occurring odd number of times in an array.
34. Write a function to find the largest sum of contiguous subarray of an array.
35. Write a function to find the missing number from a given array. There are no duplicates in list.
36. Write a function to merge one sorted array into another sorted array.
37. Write a function to find the two repeating elements in a given array
38. Write a function to find two elements whose sum is closest to zero
39. Write a function to find the smallest positive number missing from an unsorted array
40. Write a function to find a subarray with given sum from the given array.
41. Write a function to find a given number using liner search
42. Write a function to find a given number using Binary search
43. Write a function to move all zeroes to the end of a given array
44. Write a function to find the row with maximum number of 1s in a 2D Array
45. Write a function to print all unique elements of an unsorted array
——————————————————————————————————————————————
—————————
For Me : https://www.w3resource.com/c-programming-exercises/array/index.php
Assignment 6
Links To Study:
For understanding how Arrays work, please check this link:
1. https://www.tutorialspoint.com/cplusplus/cpp_multi_dimensional_arrays.htm
2. https://www.tutorialspoint.com/cplusplus/cpp_multi_dimensional_arrays.htm
Questions:
1. Write a program in C to store elements in an array and print it.
2. Write a program in C to read n number of values in an array and display it in reverse order.
3. Write a program in C to find the sum of all elements of the array.
4. Write a program in C to copy the elements of one array into another array.
5. Write a program in C to count a total number of duplicate elements in an array.
6. Write a program in C to print all unique elements in an array.
7. Write a program in C to merge two arrays of same size sorted in decending order.
8. Write a program in C to count the frequency of each element of an array
9. Write a program in C to find the maximum and minimum element in an array.
10. Write a program in C to separate odd and even integers in separate arrays.
11. Write a program in C to sort elements of array in ascending order.
12. Write a program in C to sort elements of the array in descending order.
13. Write a program in C to insert New value in the array (sorted list )
14. Write a program in C to insert New value in the array (unsorted list ).
15. Write a program in C to delete an element at desired position from an array.
16. Write a program in C to find the second largest element in an array.
17. Write a program in C to find the second smallest element in an array.
18. Write a program in C for a 2D array of size 3x3 and print the matrix.
19. Write a program in C for addition of two Matrices of same size.
20. Write a program in C for subtraction of two Matrices
21. Write a program in C for multiplication of two square Matrices.
22. Write a program in C to find transpose of a given matrix.
23. Write a program in C to find sum of right diagonals of a matrix
24. Write a program in C to find the sum of left diagonals of a matrix.
25. Write a program in C to find sum of rows an columns of a Matrix.
26. Write a program in C to print or display the lower triangular of a given matrix.
27. Write a program in C to print or display upper triangular matrix
28. Write a program in C to calculate determinant of a 3 x 3 matrix.
29. Write a program in C to accept two matrices and check whether they are equal.
30. Write a program in C to check whether a given matrix is an identity matrix.
31. Write a program in C to find a pair with given sum in the array
32. Write a program in C to find the majority element of an array.
33. Write a program in C to find the number occurring odd number of times in an array.
34. Write a program in C to find the largest sum of contiguous subarray of an array.
35. Write a program in C to find the missing number from a given array. There are no duplicates in list.
36. Write a program in C to merge one sorted array into another sorted array.
37. Write a program in C to find the two repeating elements in a given array
38. Write a program in C to find two elements whose sum is closest to zero
39. Write a program in C to find the smallest positive number missing from an unsorted array
40. Write a program in C to find a subarray with given sum from the given array.
41. Write a program in C to find a given number using liner search
42. Write a program in C to find a given number using Binary search
43. Write a program in C to move all zeroes to the end of a given array
44. Write a program in C to find the row with maximum number of 1s in a 2D Array
45. Write a program in C to print all unique elements of an unsorted array
——————————————————————————————————————————————
—————————
Assignment 5
Links To Study:
For understanding how for loops work check this link: https://beginnersbook.com/2017/08/cpp-for-
loop/
For understanding how while loops work check this link: https://beginnersbook.com/2017/08/cpp-
while-loop/
For understanding how do-while loops work check this link: https://beginnersbook.com/2017/08/cpp-
do-while-loop/
Questions:
Shape 1:
*
**
*
**
***
Shape 2:
*
*
***
***
***
Shape 3:
1
12
123
1234
12345
1
23
456
7 8 9 10
Shape 6: (Half Diamond - Input row size from user)
*
***
*****
*
***
*****
***
*
Challenge Questions:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Important:
Don’t cheat from google. Try yourself and ask me incase you’re not understanding anything.
Assignment 4
For understanding how if-else works, please check this link: https://www.programiz.com/cpp-
programming/if-else
For switch statement please check this link: https://www.programiz.com/cpp-programming/switch-case
Questions:
1. Take values of length and breadth of a rectangle from user and check if it is square or not?
2. Take two int values from user and print greatest among them?
3. A company decided to give bonus of 5% to employee if his/her year of service is more than 5 years.
Ask user for their salary and year of service and print the net bonus amount.
4. A school has following rules for grading system:
a. Below 25 - F
b. 25 to 45 - E
c. 45 to 50 - D
d. 50 to 60 - C
e. 60 to 80 - B
f. Above 80 - A
Ask user to enter marks and print the corresponding grade.
5. Take input of age of 3 people by user and determine oldest and youngest among them?
6. Write a program to print absolute value of a number entered by user?
7. A student will not be allowed to sit in exam if his/her attendance is less than 75%
Take following input from user:
Number of classes held
Number of classes attended.
And print percentage of class attended, Is student allowed to sit in exam or not?
8. Modify the above question to allow student to sit if he/she has medical cause. Ask user if he/she has
medical cause or not ( 'Y' or 'N' ) and print accordingly.
9. Write a program to check whether an entered character is lowercase ( a to z ) or uppercase ( A to Z )?
10. Take number input from user and check if that number is fully divisible by 10 or not?
11. Take input from user a 5 digit number in one variable and print its inverse?
12. Take input from user a string and print if its a palindrome or not?
13. Write a program to check if a given year by user is leap year or not? If year is exactly divisible by 4
and not divisible by 100, then it is leap year. Or if year is exactly divisible by 400 then it is leap year.
14. Write a C program to print day of Week name using switch case?
15. Write a C program to print total number of days in a month using switch case?
16. Write a C program to check whether an alphabet is vowel or consonant using switch case.
17. Write a C program to find maximum between two numbers using switch case.
18. Write a C program to check whether a number is even or odd using switch case.
19. Write a C program to check whether a number is positive, negative or zero using switch case.
20. Write a C program to create Simple Calculator using switch case.
Challenge Questions:
1. What is the outputted of following code? (There could be a compile time error as well - Don’t copy
paste the code in IDE. I trust you.)
A.
Int x=5;
if(x=6){
print “I can be a good programmer”
}
else {
print “I am a good programmer”
}
B.
Int x=5;
if(x){
print “Hello World”
}
C.
Int x=5;
if(x)
print “Hello World”
print “Hello World Again”
else
print “Hello World with else case”
D.
if(1)
print “Hey You!”
else
print “Not You!”
Important:
Don’t cheat from google. Try yourself and ask me incase you’re not understanding anything.
——————————————————————————————————————————————
—————————
Assignment 3
Questions:
1. Write a program in C++ to print the sum of two numbers using variables?
2. Write a program in C++ to swap two numbers?
3. Write a program in C++ to calculate the volume of a sphere by taking input of radius from user?
Volume: 4πr3
4. Write a program in C++ to calculate the volume of a cube? Volume: side3
5. Write a program in C++ to find the Area and Perimeter of a Rectangle? Area: Length * Width —
Perimeter: 2 * (Length + Width)
6. Write a program in C++ to find the area and circumference of a circle? Area: πr2 Circumference: 2πr
7. Write a program in C++ to convert temperature in Celsius to Fahrenheit? celsius = ((Fahrenheit * 5.0)-
(5.0 * 32))/9
8. Write a program in C++ to find the third angle of a triangle? ang3=180-(ang1+ang2)
9. Write a program in C++ that converts kilometres per hour to miles per hour? milesPerHour =
(KilometersPerHour * 0.6213712)
10. Write a program in C++ to compute quotient and remainder? quotient=dividend / divisor and
remainder=dividend % divisor
11. Write a program in C++ to compute the total and average of four numbers?
12. What is typecasting? Give at least 2 examples using code?
13. Write a program in C++ that takes a number as input and prints its multiplication table up to 10?
14. Input a 5 digit number from user and print its reverse? Please don’t use arrays as we’ve not studied
them yet. Do it with operators?
Challenge Questions:
1. Give two solutions to swap the values of two variables without using third variable?
A=5
B = 10
Case 2
A=a
Case 1
A = a+b - 15
B = a-b - 5
A = a-b = 10
Important Instructions:
Assignment 2 (Need to memorise it - You will get use to of it by using some of them most of the times
but memorise all - I recommend it fully to memorise all)
Questions:
1. What are data types?
2. What are common/important datatypes (Please mention names here)
3. what is difference between variable and constant?
4. What is difference between declaration & initialisation?
5. What happens when you declare a variable? (Understand the memory management - difficult for u at
this stage but give it a try otherwise I’ll explain.)
6. What is sizeOf() use for? (Important: understand here what are sizes of data types in memory)
7. What is an operator?
8. What is an operand?
9. How many types of operators?
Additional Questions (Bonus :p) - These will differentiate you from others and I guarantee, it will put you
in a A CLASS Coder circle.
1. What is stack & heap memory?
2. Which space in computer is called volatile and why?
3. Your variable declarations & Initialisations are stored where? (Heap or stack or anywhere else)
4. When I declare an integer let say 4 in my c++ program, What actually is happening here (Deep dive as
max as you can!!!) - I loved this understanding. Special respect for those who has this level of
knowledge.
5. Where are operators and operands saved? (Kind of same question as Point # 3)
Tasks:
Special Tasks:
- I recommend if you want to become a really good developer/software-Engineer, keep this in mind,
C/C++ are one of the most difficult high level languages in this world just because of memory
management and pointers. You get the full access of memory in C/C++. So your concept of memory
management for variables in a C/C++ program should be damn clear - I repeat Damn CLEAR!!!
——————————————————————————————————————————————
——————————————
Assignment 1
Please find the following as our next steps/plan. Let me know incase you’ve any concerns or queries in
it.
I’ll share some questions/code most of the times with you and you’ll do your research on it to solve
them. After that I’ll ask you three questions and If you will give me right answer, we’ll go to the next
topic.
For a quick start or a warmup, I’ve added some information below. Please go through it and give
yourself a kick to get ready for programming. We’re literally gonna control the machines :p haha thats a
fancy line but It is true as we will be coding to make machine work for us what ever we want. At the end
we can have a money making machine (Now thats a joke :p).
So let’s start!!!
Just simply go through, no need to memorise everything for a decade. Just understand what it is, how
and why?
Ask me any question as many as times you want. (I’ll prefer calls for these btw as it will save my time for
typing :p but can answer you via email as well.)
That’s it. After we’re done with these pre-requisites, we are good to go for a 3 questions steps :-) May
favourite part. You’ll like it too as its too much informative and has great impact. (Sounds like apnay mo
miyan meetho but you’ll see :p)
Step 2: If you’re done with step 1, write a hello world program in DevC++ using C++ Language.
You can get help from anywhere - not an issue. but need to explain me how you solved it and why.