You are on page 1of 3

PAK-TURK MAARIF INTERNATIONAL SCHOOLS & COLLEGES H-8/1

Name: ____________________ Class: HSCC-II


Subject: Computer Time: 80 MIN
Session 2023-24
Total Marks: 40
Crash Test: #3(Chapter 4&Chapter 9)
Section-A (7)
Q1: Choose the correct answer from the following
1. Which of the following is an exit-controlled loop?
A. for B. while
C. do-while D. all of the mentioned
2. What is the way to suddenly come out of or quit any loop in C++?
A. continue; statement B. break; statement
C. leave; statement D. quit; statement
3. . What will be the output of the following C++ code?
int main() {
int n ;
for (n = 5; n < 0; n--)
{ cout << n;
if (n == 3)
break; } return 0;}
A. 543 B. 54
B. 5432 D. 53

4. In C++, what is the result of the following code snippet?


int sum = 0;
for (int i = 1; i <= 5; i++) {
sum += i;
}
A. 5 B. 15 C. 10 D. 0

5. Identify the header file needed to read, write, and manipulate the file:

A. Ifstream C. Istream
B. Ofstream D. Fstream

6. If a file named as testdata.bin is to be opened in a binary mode to add data, then the C++
code to be used will be
A. ofstream myfile; myfile.open("testdata.bin" , ios::out | ios::app | ios.binary);
B. ifstream myfile; myfile.open("testdata.bin" , ios::in | ios::app | ios.binary);
C. ofstream myfile; myfile.open("testdata.bin" , ios::out | ios::ate | ios.trunc);
D. ifstream myfile; myfile.open("testdata.bin" , ios::in | ios::ate | ios.trunc);
7. Which of the following options is CORRECT about the output of eof()?
I. It returns true when there is no more data to be read from the input file.
II. It returns false when there is no more data to be read from the input file.
III. It returns true when there is data to be read from the input file.
IV. It returns false when there is data to be read from the input file.

A. I only C. I and IV
B. III only D. II and III

8. If the file is opened for output operations and its contents are deleted and replaced by the new
ones, then the file opening mode used will be

A. ios::ate C. ios::app
B. ios::out D. ios::trunc

SECTION-B(3*8=24)
i. Rewrite the following program segment using conditional operator.
if (a > b) large = a; else large = b;
ii. Write the output of below code.
int main() {
int n ;
for (n = 5; n < 0; n--)
{ cout << n<<endl;
if (n == 3)
break; } return 0;}
iii. Write a C++ program that prints sum of squares of integers from 1 to 10.
iv. How switch and else-if is different from each other, also write syntax of both
v. Differentiate between Binary file and Text file ?
vi. Write down the output of the following code?

a) int funny = 7, serious = 15; b) int i,j;


funny = serious % 2; for(i=1;i<= 4;i++)
switch (funny) { { for(j=1;j<=i;j++)
case 1: cout<<i * i<<" "; cout<<"\
cout<< "That is funny"; break; n"; }
case 7:
cout<< "That is serious"; break;
case 30:
cout<< "That is seriously funny";
break;
default :cout<< funny <<endl;
}

vii. What is stream? Write down the purpose of the following functions:
a. getline( ) b. get( )
viii. Trace the errors form the following code or rewrite the code.
int a{10},
i; cout >> ” enter ten numbers
for (i = 1; i < 10: i++)
cin << a{i};
SECTION-C (5*2=10)
1. (a) Write a C++ program that
 creates a text file named as Test.txt
 writes the following line in the file.
 I Love Pakistan closes the file.
(b) . A library charges a fine for every book returned late. For first 5 days the fine is 50
rupees, for 6-10 days fine is one rupee and above 10 days fine is 5 rupees. If you return the
book after 30 days your membership will be cancelled. Write a program to accept the number
of days the member is late to return the book and display the fine or the appropriate message.
2. (a) ) Write a C++ program that displays the following menu:

 Geometry Calculator
 Display Area of Circle
 Display Area of Rectangle
 Quit Enter your choice (1-3):
If user enters 1, the program should ask for the radius of the circle and then display its area. Use
formula: area = πr2 , use 3.14 for π.

If user enters 2, the program should ask for the length and width of the rectangle and then
displays its area, use formula: area = length x width.
Display an error message if the user enters a number outside the range of 1 – 3
(b) Differentiate between While Loop and Do-While Loop.

You might also like