0% found this document useful (0 votes)
22 views

Assignment 2

The document contains instructions for completing 15 tasks as part of an assignment for a Bachelor's degree in Information Technology. The instructions specify that students must submit both soft and hard copies of the assignment, and explain how the assignment will be evaluated and graded. It then lists the 15 tasks which involve writing C++ programs to perform various operations on integer and float arrays, such as calculating sums, checking for palindromes, finding largest/smallest values, and manipulating array contents.

Uploaded by

baknidoknu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Assignment 2

The document contains instructions for completing 15 tasks as part of an assignment for a Bachelor's degree in Information Technology. The instructions specify that students must submit both soft and hard copies of the assignment, and explain how the assignment will be evaluated and graded. It then lists the 15 tasks which involve writing C++ programs to perform various operations on integer and float arrays, such as calculating sums, checking for palindromes, finding largest/smallest values, and manipulating array contents.

Uploaded by

baknidoknu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

SUPERIOR UNIVERSITY LAHORE

Bachelor’s in Information Technology


Due Date: 22nd Feb, 2022
Subject: Introduction to Communication Technologies
dd
BSIT-1A & BSIOT-1A
(ASSIGNMENT 2)

Inst
Instructions:
a. You are required to submit this assignment in both soft and hard form. Your
hard copy will be hand-written.
b. Soft copy of your assignment will consist of a single PDF document
containing images of the hand-written assignment (Use CamScanner app
from PlayStore for this purpose)
c. Your assignment will be marked on the basis of your code-understanding,
get prepared to present any program in the coming lab after due date.
d. Your assignments are lengthy, try to divide your work on all days, otherwise
it would be hard to complete in a single day.

Assignment Tasks
Task #1
Write a C++ program which takes user input into an integer array of size 10, it then prints the
sum of all elements in an array.

Example:

Input:

Arr[10] = {3, 4, 1, 7, 6, 2, 8, 7, 1, 9 }

Output: 48

Task #2
Write a C++ program which takes user input into an integer array of size 9, it then checks
whether that array’s values are a palindrome or not. And prints a message accordingly.

Example 1:

Input: arr = { 1, 2, 3, 4, 5, 4, 3, 2, 1}

Output: arr is indeed a palindrome.


Example 2:

Input: arr = { 4, 2, 8, 4, 5, 4, 3, 2, 1}

Output: arr is not a palindrome.

Task #3
Write a C++ Program which takes input from user into an integer array of size 10, it then takes
user input into two integers ‘var1’ and ‘var2’.

1. Check if these values are present in array, if either of them aren’t then prompt user to
input var1 and var2 again.
2. After this, swap the indices where ‘var1’ and ‘var2’ values are present in the array.
3. print the whole array to show.
Example 1:

Input:

arr= {1,2,3,4,5,6,7,8,9,10}

var1=1, var2=4

Output:

arr= {4,2,3,1,5,6,7,8,9,10}

Task #4
Write a C++ program which takes input from user into an integer array of size 8, it then finds the
top 3 largest numbers in that array, and it prints the sum of them.

Example:

Input:

Arr = {4, 8, 5, 2, 9, 1, 3, 4}

Output:

Three Largest Values 9 + 8 + 5

Sum = 22

Task #5
Write a C++ program which takes input from user into an integer array of size 9, it then finds the
first 3 minimum integers in that array, and it prints the sum of it.

Example:

Input: arr = {4, 8, 2, 1, 5, 6, 7, 9, 10}

Output:

Three Smallest values in array 1 + 2 + 4

Sum = 7

Task #6
Write a C++ program which takes input from user into a float array of size 5, it then finds the
average of float array values and prints the closely related value in the array and its index.
Example:

Input:

Arr = { 1.3, 2.4, 3.5, 4.6, 5.2}

Output:

Value = 3.5
Index = 2

Explanation:

Average of the given array is 3.4, and most closely related value to the average is
3.5 on index 2.

Task #7
Write a C++ program which takes input from user into an integer array of size 8, it then finds the
unique values in that array and prints them, you must not print the duplicates.

Example:

Input:

Arr3 = {1, 1, 2, 3, 4, 5, 5, 6}
Output:

2, 3, 4, 6

Task #8
Write a C++ program which takes input from user into an integer array of size 7.
• Check those value divisible by 7, store sums of quotients in ‘sum7’.
• Check those value divisible by 3 store sums of quotients in ‘sum3’.
• After this, sum of all other values in ‘sumRest’.
• Add all the sum values and print the final Total Value.
Example:

Input:

Array= {7,14,21,2,5,4,6}

Output:

Sum of quotient divisible by 7 = 6

Sum of quotient divisible by 3 = 9

Sum of rest = 11

6 + 9 + 11 = 26

Task #9

Write a C++ program which takes input from user into an integer array of size 8, takes user input
of integer varible ‘index’. The program then:-
• prints the sum of indices before that ‘index’
• prints the product of indices after that ‘index’

Example:

Input:

arr = {4, 8, 2, 1, 5, 6, 7, 9, 10}

index = 5

Output:

Sum = 20
Product = 630

Task #10

Write a C++ program which takes input from user into an integer array of size 12, You need to
print the product of those elements with values ranging from 50-60, and sum of all other
elements of array. You are restricted to use only one for-loop after input.

Example:

Input:

Arr= {1,2,3,45,56,67,76,55,69,59,81,60}

Output:

Product of numbers in range of 50-60 i.e. (55 * 56 * 60) = 10903200

Sum of remaining numbers = 344

Task #11
Write a C++ program which takes input from user into an integer array of size 12. Now take
another integer input from the user in variable ‘n’. Now find all the elements in the array which
are complete multiplies of ‘n’ and print their sum.

Example:

Input:

Arr= {1,2,3,45,56,67,76,55,69,59,81,60}

n = 3

Output:

Multiplies of n in the array are: 3, 45, 69, 81, 60

Sum of all multiplies of n = 258

Task #12
Write a C++ program in which you input marks as value for 15 students and depending on the
marks value, print stars accordingly in front of the roll number.
[Note: Marks cannot exceed 5 as array values.]
[Note: This example uses only 3 students for demo, but you must use 15 for your solution.]
Example:

Input:

Students[0] = 3

Students[1] = 2

Students[2] = 5

Output:

#0 marks = ***
#1 marks = **
#2 marks = *****

Task #13
Write a C++ program which takes input from user into an integer array of size >= 5. It then
prints the product of all elements in an array.

Example:

Input:

Arr = {2, 5, 2, 7, 1}

Output:

140

Task #14
Write a C++ program that takes 10 integer inputs from the user and stores it in an array. After
that your program takes two more inputs from the user,
1. any index of the array in variable ‘ind’
2. a new integer number in variable ‘n’
Now your program replaces the old value in array on index ‘ind’ with new taken value in ‘n’
Example:

Input:

Arr = {1, 5, 2, 7, 1, 5, 8, 3, 2, 10}

ind = 3

n = 11

Output:

Arr = {1, 5, 2, 11, 1, 5, 8, 3, 2, 10}

Task #15
In a C++ program take two arrays Arr1 & Arr2, both of size 10. Take input for both the arrays in
a single for loop. After that take first value from Arr2 and subtract it from first value of Arr1, and
repeat the process till last index.
• Value of Arr2[0] from value of Arr1[0]
• Value of Arr2[1] from value of Arr1[1]
• .
• .
• .
• Value of Arr2[9] from value of Arr1[9]

In performing each subtraction, check the answer and do the following


• If answer is positive number print it in output
• If answer is negative do not print the answer, instead you need to print number of the first
array for that subtraction. (See the example given below)

Example:

Input:

Arr1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

Arr2 = {2, 3, 4, 5, 6, 7, 8, 8, 9, 7}

Output:

1, 2, 3, 4, 5, 6, 7, 0, 0, 3

You might also like