0% found this document useful (0 votes)
2 views2 pages

Lab 06

Uploaded by

abdulhamid.jamon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Lab 06

Uploaded by

abdulhamid.jamon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CS2311 Computer Programming 2024-25A

Lab 6 Arrays
Please test the correctness of your programs in Q-2 and Q-3 on PASS.
Q-1.
Write a program that defines and initializes an array of 10 integers.
int num[10] = {5, 10, 2, 5, 8, 8, 7, 9, 1, 5};
a) Write a for-loop to print out the contents of the array, one element in one line.
b) Modify the programs in question a), such that it prints a bar chart for the values in
the array as follows.

*****
**********
**
*****
********
********
*******
*********
*
*****

Hint: You may use nested for loops.

Q-2.
Write a program to read students’ mid-term test score (a whole number ranging
from 0 to 50), calculate the average score and prints the corresponding bar chart
for the grades as in Q-1-b.

Hint-1. The number of students will not exceed 20.


Hint-2. Display two decimal places of the average score by using std::fixed and
std::setprecision.

Expected Outputs:
Example-1
Number of students?
3
Student 1:
30
Student 2:
20
Student 3:
50
Average = 33.33
******************************
********************
**************************************************

1/2
CS2311 Computer Programming 2024-25A

Q-3.
Write a program that reads two sets of integer elements (10 elements for each
set) and finds the intersection of two sets.

Hint-1. The elements of set A and B should be unique according to set properties.
Hint-2. The intersected element is the common element in both sets.

Expected Outputs:
Example-1
Enter 10 Elements of Set A:
1 2 3 4 5 6 7 8 9 10
Enter 10 Elements of Set B:
11 12 13 14 15 16 17 18 19 20
The Intersected Element of Set A and B are not Found.
Example-2
Enter 10 Elements of Set A:
1 2 3 4 5 6 7 8 9 10
Enter 10 Elements of Set B:
1 2 3 4 5 6 7 8 9 10
The Intersected Elements of Set A and B are:
1 2 3 4 5 6 7 8 9 10
Example-3
Enter 10 Elements of Set A:
1 2 3 4 5 6 7 8 9 10
Enter Elements of Set B:
1 3 5 7 9 11 13 15 17 19
The Intersected Elements of Set A and B are:
1 3 5 7 9
Example-4
Enter 10 Elements of Set A:
-1 -2 -3 -4 -5 -6 -7 -8 -9 -10
Enter Elements of Set B:
-1 -3 -5 -7 -9 -11 -13 -15 -17 -19
The Intersected Elements of Set A and B are:
-1 -3 -5 -7 -9

2/2

You might also like