Computer Science HSSC-II Solution
Computer Science HSSC-II Solution
SOLUTION OF SECTION – A
Q.1 Choose the correct answer i.e. A / B / C / D by filling the relevant bubble for each question
on the OMR Answer Sheet according to the instructions given there.
Each part carries one mark.
2. Which one of the following types of processing has grouped transactions, executed in a
sequence?
A. Real-time ⃝ B. Batch ⃝
C. Time-sharing ⃝ D. Distributed ⃝
3. Which one of the following DOS commands is used to display content of the directory?
A. DIR ⃝ B. CD ⃝
C. MD ⃝ D. VIEW ⃝
4. Identify the type of system conversion in which the old system is directly replaced by the new
system:
A. Pilot ⃝ B. Parallel ⃝
C. Direct ⃝ D. Phased ⃝
A. 1 ⃝ B. 9 ⃝
C. 10 ⃝ D. 11 ⃝
6. Which one of the following statements transfers the control to the start of loop body?
A. Switch ⃝ B. Continue ⃝
C. Break ⃝ D. Exit ⃝
1
7. If x = 5, which one of the following accesses the seventh element stored in an array A?
A. A[x++] ⃝ B. A[++x] ⃝
C. A[7] ⃝ D. A[x] ⃝
8. The phenomenon of having two or more functions in a program with the same name but
different numbers and types of parameters is called:
10. Which one of the following indicates the address of a variable “temp” of type float?
A. float temp& ⃝ B. &temp ⃝
C. &float temp ⃝ D. temp& ⃝
11. Which one of the following is the default access specifier of C++ class?
A. Private ⃝ B. Public ⃝
C. Protected ⃝ D. Default ⃝
12. The ability of a class to hide the information from outside interference and misuse is called:
A. Encapsulation ⃝ B. Polymorphism ⃝
C. Inheritance ⃝ D. Abstraction ⃝
13. Which one of the following classes inherits the base class capabilities?
A. Abstract ⃝ B. Parent ⃝
C. Super ⃝ D. Child ⃝
14. Identify the header file needed to read, write, and manipulate the file:
A. Ifstream ⃝ B. Ofstream ⃝
C. Istream ⃝ D. Fstream ⃝
15. Which one of the following functions is used to write a single character to a file?
A. get( ) ⃝ B. gets( ) ⃝
C. put( ) ⃝ D. write( ) ⃝
2
SOLUTION OF SECTION - B
Q. 2. Attempt any TWELVE parts from the following. All parts carry equal marks. (12*3=36)
ANSWER
ii. Differentiate between process and thread along with one example of each. (2+1)
ANSWER
Context switching Processes require more time for context Threads require less time for context
time switching as they are heavy then thread. switching as they are lighter.
Memory Processes are totally independent and A thread may share some memory
Sharing don’t share memory. with its peer threads.
Blocked If a process gets blocked, remaining If a user level thread gets blocked, all
processes can continue execution. of its peer threads also get blocked.
iii. Write down the reasons of the following invalid variable names: (3)
i. 3a ii. S$ iii. float
3
ANSWER
iv. What will be the output of the following program segment? (1+1+1)
int x = 3, y = 17;
cout << x / y << y / x << (y / x) + (x % y);
ANSWER
058
vi. Write a C++ program that prints sum of squares of integers from 1 to 10. (3)
ANSWER
#include<iostream>
void main()
{
int i, sum=0,s;
for(i=1;i<=10;i++)
{
s=i*i;
sum+=s;
}
cout<<"\n Sum of square of integers = "<<sum;
}
vii. Rewrite the following program segment using conditional operator. (3)
if (a > b) large = a; else
large = b;
ANSWER
large = (a > b) ? a : b;
4
viii. Compare strcpy( ) and strcat( ) functions with examples. (1+2)
ANSWER
strcpy()
is the string copy function. It copies one string into another string.
Syntax:
strcpy(string1, string2);
The two parameters to the function, string1 and string2, are strings. The function will copy the string
string2 into the string 1.
strcat()
is the string concatenate function. It concatenates strings.
Syntax:
strcat(string1, string2);
The two parameters to the function, string1 and string2 are the strings to be concatenated. The above
function will concatenate the string string2 to the end of the string string1.
ANSWER
ANSWER
xi. Write down the syntax of function prototype for the following functions: (1+1+1)
a. A function named table with one integer parameter by value.
b. A function named area with no parameters and returns a float.
c. A function named large with two floating point numbers by reference.
5
ANSWER
a. void table(int);
b. float area();
c. void large(float &, float &);
xii. If ptr is a pointer variable, what will be the output of the following statements? (1.5+1.5)
ANSWER
cout << *ptr ; this pointer variable will print the value of variable n.
ANSWER
Public and private are called access specifiers which define the accessibility or visibility level
of class members. By default the class members are private.
If the class members are public, it can be accessed from outside the class. But private class members
are not accessible from outside.
xiv. Define a class Student that contains private and public data members including function get( ). (3)
ANSWER
class Student
{ private:
int age = 0; float height = 0.0;
public:
get(int age, float height);
};
xv. Write down the use of bof() and eof() functions. (1.5+1.5)
ANSWER
C++ provides a special function, eof( ), that returns nonzero (meaning TRUE) when there are no more
data to be read from an input file stream, and zero (meaning FALSE) otherwise.
The BOF property is automatically set to true when the record pointer is before the first record in the
record set. The BOF property is also true if the record set is empty.
xvi. Write down the purpose of any three modes of file opening. (3)
6
ANSWER
a. ios::app
Append mode. All output to that file to be appended to the end.
b. ios::ate
Open a file for output and move the read/write control to the end of the file. c.
ios::in
Open a file for reading.
d. ios::out
Open a file for writing.
7
SOLUTION OF SECTION – C
Note: Attempt any THREE questions. All questions carry equal marks. (3 * 8 = 24)
Q 3. What are the objectives of System Development Life Cycle? Explain the following phases of SDLC:
i. Feasibility Study ii. Requirement Engineering ANSWER
The Software Development Life Cycle, or SDLC for short, has cemented itself as the de-facto process to help
build information systems, systems engineering and software engineering from the ground up by encompassing
key phases that can be grouped in planning, implementation, and maintenance of the system solution. An
SDLC has three primary business objectives: - o Ensure the delivery of high quality systems o Provide strong
management controls o Maximize productivity.
i. A feasibility study is part of the initial design stage of any project/plan. It is conducted in order to objectively
uncover the strengths and weaknesses SWOT Analysis. A SWOT analysis is used to study the internal and
external environments of a company and is part of a company’s strategic planning process. In addition, a of a
proposed project or an existing business. It can help to identify and assess the opportunities and threats present
in the natural environment, the resources required for the project, and the prospects for success. It is conducted
in order to find answers to the following questions:
Does the company possess the required resources and technology?
Will the company receive a sufficiently high return on its investment?
A feasibility report should include the following
sections: o Description of the
Product/Service o Technology
Considerations o Product/ Service
Marketplace o Identification of the
Specific Market o Marketing Strategy
o Organizational Structure
o Schedule o Financial
Projections
ii. Requirement engineering is the process of collecting, validating and managing the requirements essential for
the development of the software, specified by the clients or the end-users. This task is performed at the initial
stages of software development.
Requirement engineering provides the appropriate mechanism to understand: o what
the customer desires
o analyzing the need, and assessing feasibility, o negotiating a
reasonable solution, o specifying the solution clearly,
o validating the specifications and managing the requirements
Thus, requirement engineering is the disciplined application of proven principles, methods, tools, and notation to
describe a proposed system's intended behavior and its associated constraints.
ANSWER
A loop is a control structure that repeatedly executes a sequence. Looping structure are more appropriate
where repetition of statement is required. Following are the types of loops
FOR LOOP:
8
For loop is also called iteration loop. It is used to execute one or more statements for a specific number
of times. It is more suitable for a situation where number of iteration is known. Starting and ending
points are given. Loop will check the counter value with ending point. The loop will continue until
counter variable meets the ending point. Its syntax is:
SYNTAX:
For(initialization; condition; interval )
{ Block of statements }
Example:
#include <iostream.h>
#include <conio.h>
void main ()
{ int k;
for ( k=1; k<5;k++)
{
cout<<”I m a student”;
cout<<”I was born in 2004” ;
}
getche();
}
While Loop
It is also known as conditional loop. In this loop, condition is checked at the beginning. The body keeps
on executing until the condition is true.
Syntax
while(condition)
{
Block of Statements
}
Example:
#include <iostream.h>
#include <conio.h>
void main ()
{
int k = 1;
while(k<5)
{
cout<<”I m a student”;
cout<<”I was born in 2004”
k = k + 1;
}
getche();
}
9
Q 4. (b) Write a C++ program that reads a number and prints whether it is prime or composite.
ANSWER
#include <iostream>
void main()
{ int n, i, m=0, flag=0;
cout << "Enter the Number to check Prime: ";
cin >> n;
m=n/2;
for(i = 2; i <= m; i++)
{
if(n % i == 0)
{
cout<<"Number is Composite"<<endl;
flag=1;
break;
}
}
if(flag==0)
cout << "Number is Prime."<<endl;
}
10
Q 5. Determine the output of the following C++ program and fill the columns of the given table. (2+3+3)
void main(void)
{ int a [6] = {12,27,36,55,72,83};
int i, s = 0, v=0;
for (i = 0 ; i <= 5; i++)
{
if(a [i] % 3 == 0)
{
cout<<a [i] ;
s = s + a [i];
v = s * 3 – a [i] % 7;
}
cout << s << “\t” << v;
}
}
ANSWER
i a[i] s V
0 12 12 31
1 27 39 111
2 36 75 224
3 75 224
4 72 147 439
5 147 439
11
Q.6 Write a C++ program to calculate the factorial of a number. The program inputs a number and
pass it by reference to a user-defined function factorial.
ANSWER
#include<iostream>
using namespace std;
void findFct(int, int *);
int main()
{
int num, fact=1;
cout<<"Enter the Number: ";
cin>>num;
findFct(num, &fact);
cout<<"\nFactorial = "<<fact;
cout<<endl;
return 0;
}
void findFct(int n, int *f)
{
int i;
for(i=n; i>=1; i--)
*f = (*f)*i;
}
12