Skip to main content

Full text of "10th Class Computer Science Subjective Model Paper 7"

See other formats

SS eeeee-”™--—-~—L 

10th Class 
Computer Science | Model Paper 7 | Paper: Il 
Time: 1.45 Hours | (Subjective Type)| |‘ Marks: 40) 


>. Write short answers to any FOUR (4) questions: ~ (8) 
Write short answers to any FOUR “) apeenone: - (8) 
. Why we need IDE? 

EMIE> We need IDE because it consists of tools that help a . 

programmer throughout’ the phases of writing, executing and 

testing a computer program. 

(ii) What is difference between Real Constants and 
Character Constants? : 

Ans, 3 
Real constants are the 
values including a decimal 
point. They can be Eas or 

Any single small case 
letter, uppercase letter, digit, 
punctuation mark, special symbol 
enclosed within ‘' is considered a 
| character constant. 
‘aga’, ‘*X’, ‘l, ete. 

Example: ' 

3.14, 15.396GaernetOr 
1575.76, 7941.2345, etc. 7 
(iii) | Whatis formation of escape sequence? 

iS Escape sequence consists of two characters: 

1. The first character is always back slash (\). 

2. The second character varies according to the functionality 
that we want to achieve. 
Back slash (\) is called escape character which js 


associated with each escape sequence to notify about escape. 
Escape character and character next to it are not displayed on - | 

screen, but they perform specific task assigned to them. 

(iv) Can we display output on multiple line with multiple 
printf statement in the absence of escape sequence? 

Ans4 In the absence of an escape sequence, even if we have 

multiple printf statement, their output is displayed on a single 

line. Following example illustrates this point. 

Scanne: d with CamScanner 


void main() 

-printiMy name is 

| ey name is Ahmad. 
(v) | What is difference between multiplication operator 
and addition operator?’ 
E Multiplication - operator Addition Operator 
(*) is a binary operator which | calculates the sum of two 
| performs the product of two | operands. 
numbers. , 
It is denoted by *. Itis denoted by (+), 
(vi) | Which operator is applied on three operands? 

C language also offers a ternary operator that is applied 
- onthree operands. ~— . 

3.__ Write short answers to any FOUR (4) questions: (8) 
(i) Define associated code. — . 
The associated code in if statement is. any valid C- 
language set of statements, - 
(ii). Write name of Selection statements types. 
. Two types of selection statements are: 

7 1. If statement _ _ 2. [f-else statement 
‘ (iii) Define block or compound statement. 

A set of multiple instructions €nclosed in braces is called 
@ block ora compound statement. 

(iv) Differentiate between sequential and_ selection 

Scanne d with CamScanner 

___ Sequential Control se — Seloction Statements 

Soquential control is the |The. statements “which 
default control structure In C |help us to decide — whieh 
Janguage, According to the | statements should be 
sequential control, all the | executed next, on the basis of 
statements are executed in the | conditions, are called selection 
Lgiven sequence. | Statements een 
(v) What is Data Type? 
EE pata type is the type of data that we want to store In the array. 
(vi) Write down the method to initialize an array. 

Ci An array can be initialized at the time of its declaration, or 
later. Array Initialization at the time of declaration can be done 

in the following manner: 

data_type array_name [N] © {valuet, value2, values, ..., valueN}; 
ag Pee ont ee NG I NN vote per recency ene te tA SAL IA TE ALLL TNE A 
4, Write short answers to any FOUR (4) questions: (8) 

(i) How to access an array element? 
EME Each element of an array has an index that can be used 
with the array name as array name [index] to access the data 

stored at that particular index. | 
First element has the index 0, second element has the 

index 1 and so on. Thus height[0] refers to the first element of 
array height, height[1] refers to the second element and so on. 
(ii) What is difference between arguments and parameters? 
EXE> The values passed to the function are called arguments, 
whereas variables in the function definition that receive these 
values are called parameters of the function. 

(iii) Can there are multiple return statements in a 


EX There may be multiple return statements in a function 
but as soon as the first return statement is executed, the 
function call. returns and further statements in the body of 
function are not executed, , 

(iv) Write down the output of following code. 


int x ® 20; 

Scanned with CamScanner 

es int y = 10; st. Ge 
printf(“%d %d", y, x + 2): 

swap(int x,int y) 
int temp; : 
temp = x; 
_ » y=temp; 
} > 
i> Output: . 

10 © 22 (duplicate copy of. arguments aré generated on 
calling a function). 
(v) _ Identify the error from the following code. 

Int max (int a; int b) 

if (a> b) 
return a; 
return b; 

ya. eae 4 
EMS Errors: 5, . 
_ Use comma instead of semicolon between parameters. 
_ (vi) How can we handle the complexity of the problem? 

if we write the whole program as a single procedure, 
management of the program becomes difficult. Functions divide | 

the program into smaller units, and thus reduce the complexity 
ofthe problem. 

(Part-I) get ges 
NOTE: Attempt any TWO (2) questions. 
Q.5. What are ~ the Operators? Describe assignment 

operators and arithmetic operators in details. (8) 

Operators: _ . 

The name computer Suggests that computation is the 
most important aspect of computers. We need to perform 
Computations on data through programming. We have a lot of 

Scanne d with CamScanner 

mathematical functions to perform calculations on data. We o- 
also perform mathematical operations in our programs, 
language offers numerous operators to manipulate and 
data. Following is the list of some basic operator types: 
¢ Assignment operator , 
¢ Arithmetic operators 
¢ Logical operators 
¢ Relational operators 

- Assignment Operator: » 

Assignment operator is used to assign a value to a! 
Variable, or assign a value of Variable to another variable. | 
Equal sign (=) is used as assignment operator in C. | 
Consider the following example: ) er 
int sum = 5; hte By ae . at 
Value 5 is assigned to a variable named ‘sum after, 
executing this line of code. Let’s have a look at another example: 4 
int sum = 6; of se OF 

int var =sum; | . ' ? 
| First, value 6 is assigned to variable sum. In the next line, . 
the value of sum is assigned to variable var. | 

Arithmetic Operators: = q 

Procegy | 

Arithmetic operators are used to perform arithmetic: 
operations on data. Following table represents arithmetic: 
operators with their description. Es oa 

Operators | __Name | 

Division Operator . 

Multiplication Operator 

It is used to divide the value on 
left side by the value on right side. | 

It is used to multiply two values, 
Addition Operator ' It is used to add two values, 

ar eae 
. we Subtraction Operator | It is used to subtract the value of 

right side from the value on left side.- 

Modulus Operator ‘| It gives remainder value after 
dividing the left. operand’ by 
| right operand. | 

Table: Arithmetic Operators, 


Division: - ) , | 
Division operator (/) divides the value of left operand by 
the value of right operand. e.g., look at the following statement. 



Scanne d with CamScanner 

ee ————_—______ 

float result = 3.0 / 2.0: 

After this statement, the variable result contains the value 1.5. 

Multiplication operator (*) is a binary operator which 
performs the product of two’ numbers. Look at the following 

int multiply = 5* 5: 

After the execution of statement, the variable multiply 
contains value 25. 


Addition operator (+) “blouletan the sum of two operands, 
Let's look at the following statement: 

int add = 10 + 10; 

- Resultant value in variable add is is’ 20. 

Subtraction operator (-) subtracts right operand from the 
left operand. Let's look at the following statement: 

int result = 20 — 15; 

After performing subtraction, value 5 is assigned to the 
variable result. 
‘Modulus operator: : 

Modulus operator (%) performs division of left operand _ ne 
the right operand and returns the remainder value after division. 3 
Modulus operator works on integef data types. 3 <a 

'. int remaining = 14% 3 

As, when we divide 14 by 3, we get a remainder of 2,so. * 

_ the value stored in variable remaining is 2. 

Q.6. Write a program that'takes the type of consumer and 
number of units consumed as input. The program 

FE eats the clectricity bill of the user.__.” (8). 
Ans4 #include<stdio.h> | 

void main() 

“int units, unit price, bill: 
‘char user_type: 

_ printf("Please enter h for home user and ¢ for 
commercial user:”): a 
Scanf(“%c’”, & user type); 


Scanne d with CamScanner 

printi(‘Please enter the number of units consumed:’): 
scanfC%d", &units): 
if(units <= 200) 

_ if(user_type = = ‘h’) 

unit_price = 12: 
else if (user_type = = ‘c’) 
unit_price = 15; | 
. else if (units > 200 && units <= 400) 
if(user_type==‘h’) - ~~ | 
unit_price = 15; _ 
else if (user_type = = ‘c’) 
_unit_price = 20: 
if(user_type = =‘h’) 

_ + unit_price = 15; 
else if (user_type = = ‘c’) 
unit_price = 24: 
_ bill= units * unit_price; 
~ printf(“Your electricity bill is %d”, bill); 

= : . : a : 
Q.7. What is loop structure? Describe the Structure of a 
for loop. (8) 

Ans Loop Structure: iam). | 
lf we need to repeat one or more Statements, then we use 
‘oops. For example, if we need to write Pakistan thousand times 

on the screen, then instead of writing printf(“Pakistan”); a 
thousand times, we use loo 

ps. C language provides three kind 
of loop structures: nay 
1- For loop 
2- While loop 

3- DoWhile loop 
General syntax of for loop: ; : 

In C programming language, for loop has the following 
general syntax: : ee 

p eiseation: condition; incrementdecrement) 

Code to repeat 

Scanned with CamScanner 


In order to understand the for loop structure, let's look at 
the following flow chart: | 



[Initia Initialization 
(pale a 

(pale a 

secislabie adie: Code 

From the. flow chart, we can observe the: following 
sequence: - 

4. . Initialization is the first ait to be executed in a for loop, 
Here we. initialize our counter variable: and then move to © 

the condition part. 
2: Condition is checked, and if it turns out : be false, then 

we come out of loop. 

3.. ‘Ifthe condition js true, then body of the em is executed. 

4. After executing:the body of loop, the counter variable is 
increased or decreased depending on the used logic, and 
then we again move to the step 2: Lp : 

After executing the body of /oop, the counter variable. is. 
increased or decreased depending on the used sare and then 

we again move to the step 2. , 


‘for (int i = 0; i< 3; i++) 
| ‘3 
e printf(‘Pakistan\n” ); 


Scanne d with CamScanner