0% found this document useful (0 votes)
504 views4 pages

Bahria University CS Assignment 2020

1) The document provides instructions for a take home assignment with 4 questions for a Computer Programming course. 2) Question 1 asks students to write an algorithm and flowchart to calculate the sum of number sets partitioned into equal groups. 3) Question 2 asks students to write a C++ program to display a hollow pyramid star shape based on user input size until the user enters "No". 4) Question 3 asks students to write a program using an array and function to re-order positive numbers in a sorted array based on maximum, minimum, second maximum etc. 5) Question 4 asks students to write a program using switch statements to calculate grace marks for a student based on their class and number of

Uploaded by

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

Bahria University CS Assignment 2020

1) The document provides instructions for a take home assignment with 4 questions for a Computer Programming course. 2) Question 1 asks students to write an algorithm and flowchart to calculate the sum of number sets partitioned into equal groups. 3) Question 2 asks students to write a C++ program to display a hollow pyramid star shape based on user input size until the user enters "No". 4) Question 3 asks students to write a program using an array and function to re-order positive numbers in a sorted array based on maximum, minimum, second maximum etc. 5) Question 4 asks students to write a program using switch statements to calculate grace marks for a student based on their class and number of

Uploaded by

Umar Farooq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • Assignment Questions
  • Assignment Instructions

BAHRIA UNIVERSITY (KARACHI CAMPUS)

MIDTERM EXAMINATION –SPRING SEMESTER – 2020


(Computer Programming: CSC-113)

Take Home Assignment

Class: BS (IT) – 1-A (Evening)


Course Instructor: Tarwan Kumar Submission Deadline: 31-May-2020
Max Marks: 20

Note: Attempt all Questions. Answer each Question on a new page of the same document.

Read Carefully:
The deadline for this assignment is Sunday, May 31, 2020 on LMS.

WARNING: This is an individual assignment; you must solve it by yourself. Any form of
plagiarism will result in receiving zero in the assignment.

WARNING: Late submission will not be accepted. Any assignment submitted after the
cutoff time will receive zero by default (LMS).

This assignment has 04 questions that you have to answer and submit the solution on the
LMS within due deadline.

Question No: 01 [5-MARKS]


Assume that there are hundred numbers partitioned into equal sets (equal number of element in
each Element Set) and each Element Set is defined in the following order. Using counter
controlled loop concept, you are required to compute the sum of each order set.

Order Element set


1 1 2 3 4 5 6 7 8 9 10
2 11 12 13 14 15 16 17 18 19 20
3 21 22 23 24 25 26 27 28 29 30
4 31 32 33 34 35 36 37 38 39 40
5 41 42 43 44 45 46 47 48 49 50
6 51 52 53 54 55 56 57 58 59 60
7 61 62 63 64 65 66 67 68 69 70
8 71 72 73 74 75 76 77 78 79 80
9 81 82 83 84 85 86 87 88 89 90
10 91 92 93 94 95 96 97 98 99 100

Page 1 of 4
Write a step by step ALGORITHM and draw a FLOWCHART based on the above scenario.

Question No: 02 [5-MARKS]


Write a C++ SOURCE CODE using Nested Event Controlled Loop to display the hollow
pyramid star in the shape of diamond according to user choice. The program must be continued
to display hollow pyramid star of different size based on the user choice until and unless user
hits keyword “No” using computer input device. Display the output screen as following.
Note: Size of the pyramid must be read from user.

Question No: 03 [5-MARKS]


Write a C++ Source Code using Array and Function that can Re-Order the positive numbers
of a given sorted array list as following (See given output Screen). Array list must be read from
user and written using the event controlled loop. The maximum length of an array should be
“10”. You are required to declare and define a user defined function with name “RE-
ARRANGE_MAX_MIN” having two formal parameters as an list of elements and a number

Page 2 of 4
to be re-arranged/compared e.g. “RE-ARRANGE_MAX_MIN (Int Elements[], int number)”.
The program must be continued with its working based on the user choice until and unless user
hits keyword “No” using input device.

Note: In Final RE-Arranged Array list, 1st number should be of maximum value and 2nd
number should be of minimum value, 3rd number in the array list should be the 2nd maximum
value and 4rth number in the array list should be the 2nd minimum value and so on (See the
output screen).

Question No: 04 [5-MARKS]


Write a C++ Source Code to find the grace marks for a student using SWITCH statement.
The user should enter the class obtained by the student and the number of subjects he has failed
in (See output screen). Your program should assign the grace marks to student based on the
following rules.

Page 3 of 4
1. Rule 01:
a. If the student fails in more than three subjects and gets first class then, no grace
marks will be awarded to student.
b. If the student fails in less than or equal to three subjects, then student will be
awarded grace of 5 marks per subject.
2. Rule 02:
a. If the student fails in more than two subjects and gets second class then, no
grace marks will be awarded to student.
b. If the student fails in less than or equal to two subjects, then student will be
awarded grace of 4 marks per subject.
3. Rule 03:
a. If the student fails in more than one subject and gets third class then, no grace
marks will be awarded to student.
b. If the student fails in one subject only, then student will be awarded grace of 5
marks per subject.
4. If user enters 4th class as input for student, then your program must display a message
(“You have entered wrong class for the student! Please try again Thank you.”).

Good Luck 

Page 4 of 4

Common questions

Powered by AI

User input plays a crucial role in driving the interactive nature of the program, allowing dynamic control over the array operations and the repetition of loops. The program solicits user input to determine array elements, drive structure modifications, and choose operational continua, effectively making the user a significant factor in the computational workflow .

Using counter and event-controlled loops without adequate user input validation may lead to infinite loops or logical errors as the loops execute based on unexpected or invalid input. Without validation, inputs that should terminate or redirect logic may be mishandled, potentially causing inefficient execution or overuse of system resources .

When designing algorithms and drawing flowcharts for loop-based computations, key considerations include clearly delineating the control flow, setting loop invariants, and handling edge cases. Additionally, the algorithm should specify loop initiation, execution, and termination conditions. Flowcharts should visually represent these steps with accurate logic control symbols, ensuring clarity in how the input is transformed to output over loop iterations .

To compute the sum of numbers in specific order sets using counter controlled loops, one can iterate over each Element Set of 10 numbers using a for-loop that increments by 10. For each set, initialize a sum variable to zero, and iterate over the elements in that set, adding each element to the sum variable. This operation effectively partitions the 100 numbers into 10 sets and computes their sums .

A switch statement can efficiently determine the grace marks by evaluating the student's class input. Each case within the switch corresponds to a class level and invokes logic for checking the number of subjects failed. Based on these, the switch assigns marks according to predefined rules, handling various cases in a structured and readable manner, ensuring that incorrect inputs are managed by a default case that prompts the user to correct their input .

Arrays and functions can be utilized to reorganize a sorted array by defining a function, such as RE-ARRANGE_MAX_MIN, that takes the sorted array and a number as arguments. This function will iterate through the array, alternating between picking the maximum and minimum remaining values. These picked values are placed in the results array, maintaining the max-min order as specified. This structured approach allows complex array manipulations to occur within a modular framework .

The C++ code applies specific rules for grace marks based on the student's class and the number of subjects failed: For first class students, if they fail more than three subjects, no grace marks are given; otherwise, they receive 5 marks per subject. For second class, more than two failures result in no grace, otherwise, 4 marks per subject. For third class, failing more than one subject results in no grace, otherwise, 5 marks per subject are awarded. Entering fourth class returns an error message .

The program ensures correctness of the hollow pyramid's size by continuously prompting the user for inputs and displaying the pyramid as per the specified size until the user opts out. The event-controlled loop setup inherently repeats the pyramid size input prompt, verifies the input through output checks, and maintains control flow to allow user decisions to directly dictate program behavior .

Modularity in programming facilitates clear separation of concerns, allowing complex tasks to be broken into reusable components. Implementing RE-ARRANGE_MAX_MIN within a modular framework enables encapsulation of specific array operations while maintaining independence from the main program flow. This reduces complexity, enhances readability, and allows easy debugging and testing of the function .

The C++ program employs a nested event-controlled loop, where the user is continuously prompted for the size of the hollow pyramid until they choose to exit by entering 'No'. This involves using a loop that checks for user input after constructing the pyramid, allowing for dynamic response to user interaction to either display another pyramid or terminate the program .

Page 1 of 4 
 
 
 
 
 
 
 
 
 
 
Read Carefully: 
The deadline for this assignment is Sunday, May 31, 2020 on LMS. 
 
WARNI
Page 2 of 4 
 
 
Write a step by step ALGORITHM and draw a FLOWCHART based on the above scenario.  
 
Question No: 02
Page 3 of 4 
 
to be re-arranged/compared e.g. “RE-ARRANGE_MAX_MIN (Int Elements[], int number)”. 
The program must be cont
Page 4 of 4 
 
1. Rule 01: 
a. If the student fails in more than three subjects and gets first class then, no grace 
marks

You might also like