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

Assignment 4 (XII) - Ch4

This document is an assignment for Class XII Computer Science at Islamabad Model College for Boys, detailing instructions and questions related to control structures. It includes multiple choice questions, programming tasks, and guidelines for submission, emphasizing the importance of originality and deadlines. The assignment is due on January 28, 2025, and consists of various programming exercises focused on loops and control statements.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment 4 (XII) - Ch4

This document is an assignment for Class XII Computer Science at Islamabad Model College for Boys, detailing instructions and questions related to control structures. It includes multiple choice questions, programming tasks, and guidelines for submission, emphasizing the importance of originality and deadlines. The assignment is due on January 28, 2025, and consists of various programming exercises focused on loops and control statements.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Islamabad Model College for Boys F-10/4, Islamabad

Street 30, F-10/4, Islamabad


Contact No. 051-9266460 Email: [email protected]

Class: XII Assignment No. 4 (January) Subject: Computer Science


Instructor: Saad ur Rehman Marks=30 Due Date: 28 Jan, 2025

Instructions
• Ensure your Roll Number, Full Name, and Section are clearly written on the first page of your assignment.
• Use proper sheets for your work.
• Maintain neat and organized handwriting. Use a marker for headings.
• Plagiarism is strictly prohibited. Submissions found to be copied from others will result in a zero mark for all
involved.
• Late submissions will not be entertained, and a zero mark will be awarded for assignments submitted after the
deadline.

Chap: 4 – Control Structures

Q1. Multiple Choice Questions (MCQs). Only write correct answers in answer sheet.
[5 Marks: 1 mark each]

1. A while loop is more appropriate to use than a for loop when:


a. the body of the loop is to be executed at least once
b. termination condition occurs unexpectedly
c. the program executes at least once
d. the number of loop iterations are known in advance

2. In which situation a do while loop is more appropriate to use?


a. when the body of the loop is to be executed at least once
b. when termination condition occurs unexpectedly
c. when the program executes at least once
d. when the number of loop iterations are known in advance

3. In which situation a for loop is more appropriate to use?


a. when the body of the loop is to be executed at least once
b. when termination condition occurs unexpectedly
c. when the program executes at least once
d. when the number of loop iterations are known in advance

4. Which of the following transfers control to the beginning of the loop, skipping the remaining
statements?
a. exit function b. continue function c. break function d. nested loop

5. Which of the following can be used to replace ternary operator?


a. if b. if-else c. else-if d. switch
Q2. Write a program to print sum of numbers from 15 to 80. (Hint: Use Loop)

(5 Marks)

Q3. Write a program that prints a table for a number taken from a user. (Hint: Use Loop)

Example: Enter a number: 5

5x1=5
5 x 2 = 10
5 x 3 = 15
.
.
.
5 x 10 = 50

(5 Marks)

Q4. Write a program that repeatedly ask user for a number and then prints its square. The program will
terminate and say goodbye only when user enters 0. (Hint: Use while loop for repetition)

Example: Enter a number: 2


Square is 4

Enter a number: 5
Square is 25

Enter a number: 3
Square is 9

Enter a number: 0
Goodbye!

(5 Marks)
Q5. Write a program that works as calculator. The program should take 2 numbers and an operator from user,
and then print the result based on the operator used. After each result the program should ask user whether he
wants to continue or not. (Hint: Use Switch Statements based on operator and while loop to ask repeatedly)

Example: Enter 1st number: 5


Enter operator: -
Enter 2nd number: 3

5–3=2

Do you want to continue (Enter Y or N): Y

Enter 1st number: 4


Enter operator: *
Enter 2nd number: 6

4 x 6 = 24

Do you want to continue (Enter Y or N): N


Goodbye!

(5 Marks)

Q6. Write a program that gives the below output: (Hint: Use nested loop)

Example: 12345
1234
123
12
1

(5 Marks)

You might also like