CS1002-Programming FundamentalsAssignment 1
CS1002 – Programming Fundamentals
Assignment Number 1
Spring 2026
Maximum Marks: 120 Due Date: 20 February 2026
Instructions:
● Partially or fully copied assignments will be marked as zero.
● Only handwritten solution on page A4 will be accepted.
● Use the title page provided with this assignment.
● Late submissions are not allowed.
● Solve all the questions in the given order.
Taxonomy
No. Course Learning Outcome (CLO) Statement
Level
Apply iterative structures, arrays, and string operations to write C++
1 C3
programs for solving basic computational problems.
Question Number 1 (CLO1) (5 + 10 = 15 marks)
a) Implement a program to print a hollow rectangle pattern of asterisks (*) with a given
width w and height h using nested loops. For example, if the user enters width = 5 and
height = 4, the pattern should be:
* * * * *
* *
* *
* * * * *
b) Write an efficient C++ program to print the following pattern with the help of nested
loops.
a b c d e f X 1 2 3 4 5 6
a b c d e X X X 1 2 3 4 5
a b c d X X X X X 1 2 3 4
a b c X X X X X X X 1 2 3
a b X X X X X X X X X 1 2
a X X X X X X X X X X X 1
X X X X X X X X X X X X X
National University of Computer and Emerging Sciences – FAST, CFD Campus 1
CS1002-Programming FundamentalsAssignment 1
Question Number 2 (CLO1) (10 + 5 + 5 = 20
marks)
a) Implement a C++ program for an industrial system containing 15 voltage sensors that
accept voltage readings interactively. Apply validation rules to detect invalid voltages,
where a voltage is considered invalid if it is negative or greater than 150 volts.
Terminate program execution when three consecutive invalid voltage values are
encountered. Using validated data, compute and display:
● The average voltage value
● The total number of invalid voltage entries
Further, classify and determine the number of voltage readings that fall within the
following ranges:
● Less than 60
● Greater than or equal to 60 and less than 70
● Greater than or equal to 70 and less than 80
● Greater than or equal to 80 and less than 90
● Greater than or equal to 90
b) During program testing, apply an appropriate array initialization technique to simplify
input handling instead of entering 15 voltage values interactively each time. Identify
and justify the method used.
c) Modify the program developed in Question 1(a) to handle the scenario where no
voltage is present. Propose a suitable sentinel value to represent the absence of
voltage and demonstrate how the program logic should be adjusted to exclude such
values from computation and counting.
Question Number 3 (CLO1) (15
marks)
A circuit may contain a maximum of 20 resistors and the power dissipated in each resistor is
stored in a 1D array. Write a C++ program to:
● Ask the user to enter the number of resistors.
● Validate the input. In case of invalid input, continuously ask for re-entry.
● Input power values
● Use nested loops to rank resistors from highest to lowest power
● Classify resistors as:
o Safe (power is less than or equal to 25 watts)
o Warning (power is greater than 25 watts but less than or equal to 40 watts)
o Overloaded (power is more than 40 watts)
● Skip resistors with zero power
● Count and display the number of resistors in each category.
● Display the total, average, minimum, and maximum dissipated power.
Question Number 4 (CLO1) (20
marks)
A circuit has 5 nodes, each connected to 4 branches. Branch currents entering a node are
positive and leaving each node are negative. All the branch currents are stored in a 2D array.
Write a C++ program to:
● Apply KCL at each node using nested loops.
● Compute the algebraic sum of currents at every node.
National University of Computer and Emerging Sciences – FAST, CFD Campus 2
CS1002-Programming FundamentalsAssignment 1
● Declare a node “balanced” if the net current is within an acceptable tolerance level (±
0.01 A).
● Stop checking further nodes if imbalance exceeds the tolerance level.
Question Number 5 (CLO1) (30
marks)
Write a program that can be used to assign seats for a commercial airplane. The airplane has
13 rows, with six seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are
business class, and rows 8 through 13 are economy class. Your program must prompt the user
to enter the following information:
● Ticket type (first class, business class, or economy class)
● Desired seat
Output the seating plan in the following form:
Row A B C D E F
Row 1 * * X * X X
Row 2 * X * X * X
Row 3 * * X X * X
Row 4 X * X * X X
Row 5 * X * X * *
Row 6 * X * * * X
Row 7 X * * * X X
Row 8 * X * X X *
Row 9 X * X X * X
Row 10 * X * X X X
Row 11 * * X * X *
Row 12 * * X X * X
Row 13 * * * * X *
In this seating plan, * indicates that a seat is available, while X indicates that a seat is
occupied. You are required to create a menu-driven program that displays the available
options to the user and allows them to make appropriate selections, such as choosing a ticket
type, selecting a seat, and viewing the updated seating plan. The program should interactively
guide the user through these choices and update the seating arrangement accordingly.
Question Number 6 (CLO1) (20
marks)
The math teacher at your university needs a C++ program to grade a True/False test for a
large class. The program must use character arrays to store and process all data.
a. Data Input
● The program should first input a 20-character array representing the correct answers
to the test (e.g., TFFTFFTTTTFFTFTFTFTT).
● The user will then specify the number of students to be graded.
(The program should be able to handle more than 150 students.)
● For each student, the program should input:
National University of Computer and Emerging Sciences – FAST, CFD Campus 3
CS1002-Programming FundamentalsAssignment 1
o A Student ID (stored in a character array).
o The student’s responses stored in a 20-character array.
Note: A student may leave a question unanswered; such responses are
represented by a space or the character ‘X’.
b. Marking Scheme
The test consists of 20 questions, and the maximum score is 40 marks.
● Correct answer: +2 marks
● Incorrect answer: −1 mark
● Unanswered question (X): 0 marks
c. Grading Scale
The program should calculate the percentage score for each student and assign a letter grade
according to the following scale:
● 90% – 100% → A
● 80% – 89.99% → B
● 70% – 79.99% → C
● 60% – 69.99% → D
● 0% – 59.99% → F
d. Program Output
For each student, the program must display:
1. The Student ID
2. The Student’s Responses
3. The Total Score
4. The Final Letter Grade
National University of Computer and Emerging Sciences – FAST, CFD Campus 4
CS1002-Programming FundamentalsAssignment 1
Sample Output:
<< Good Luck >>
National University of Computer and Emerging Sciences – FAST, CFD Campus 5