Function Definition
In C language, function must be defined before it is used in the program. The
definition contains the actual code for the function. The definition consists of a
line called the declarator, followed by the function body. The body of the function
is a set of statements enclosed in braces. The general format is:
type function-name(parameter list)
{
body of the function
}
Where,
type specifies the type of value that the return statement of the function returns.
function-name is the name which makes it possible to call the function.
parameter list is a comma-separated list of variables of a function referred to as its
arguments.
Here is an example of a function definition:
void sum(int a,int b)
{
int t;
t=a+b;
printf(“Value of A = %d\n”,a);
printf(“Value of B =%d\n”,b);
printf(“Sum is %d\n\n”,t);
}
Calling a Function
In order for a function to be used, it must be called by another function. To call a function,
one enters the name of the function followed by a matching pair of parentheses inside
which is the list of parameter values to be passed to the function. The parameters included
in function declarations are called formal parameters while parameters listed in a function
call are called the actual parameters.
For example, in order to invoke a function whose prototype is of the following format:
void sum(int, int);
the function call statement can be used:
sum(a,b);
JBD
Computer Studies-10 201
Solved Example#include<stdio.h>
#include<conio.h>
int area(int, int);
void main()
{
int l,b,a;
clrscr();
printf(“Enter a length”);
scanf(“%d”,&l);
printf(“Enter a breadth”);
scanf(“%d”,&b);
a=area(l,b);
printf(“Area is:%d\n”,a);
getch();
}
int area(int c, int d)
{
int k;
k=c*d;
return (k);
}
Passing Arguments to a Function
When a function is invoked, the program may send values to the function.
Such values are called arguments. There are two different methods to pass the
arguments to a function. They are:
• Call by value
• Call by reference
Call by Value
A process of passing value of variables is known as call by value. When arguments
are passed by value, the called function creates a new copy of variable of the
same type as the arguments and copies the arguments values into it. The changes
made to the parameters of the called function have no effect on the variables used
to call the function.
JBD
202 Computer Studies-10
Solved Example # include <stdio.h>
# include <conio.h>
void change(int,int);
void main()
{
int a=15;
int b=20;
clrscr();
printf(“Before calling function\n”);
printf(“Value of a=%d\n”,a);
printf(“Value of b=%d\n”,b);
printf(“After function called\n”); change(a,b);
printf(“After returning from function\n”); printf(“Value
of a =%d\n”,a);
printf(“Value of b =%d\n”,b);
}
void change(int a,int b)
{
int t;
t=a;
a=b;
b=t;
printf(“Value of a =%d\n”,a); printf(“Value
of b =%d\n”,b);
}
Call by Reference
A process of passing addresses to a function is known as call by reference. When
arguments are passed by reference, the address of each argument is copied to the
argument of the function. The changes made to the parameter of the function will
effect on the variables used at the calling function because called function can
access the original variables of the calling function.
JBD
Computer Studies-10 203
Solved Example /* Function called by reference*/
# include <stdio.h>
# include <conio.h>
void change(int &,int &);
main()
{
int a=15;
int b=20;
clrscr();
printf(“Before calling function\n”);
printf(“Value of A=%d\n”,a);
printf(“Value of B=%d\n”,b);
printf(“After function called\n”);
change(a,b);
printf(“After returning from function\n”);
printf(“Value of A =%d\n”,a);
printf(“Value of B =%d\n”,b);
}
void change(int &a, int &b)
{
int t;
t=a;
a=b;
b=t;
printf(“Value of A =%d\n”,a);
printf(“Value of B =%d\n”,b);
}
JBD
204 Computer Studies-10
C Dompu- ictionary
C-Language : A general-purpose programming language designed
by Dennis Ritchie in early 70’s at the Bell Telephone
Character set Laboratories for use with the Unix operating system.
Keywords
Variable : Character set is a set of valid characters that a language
Constant can recognize.
Data type
: Words, which have special meaning for the compiler.
: Variable refers to a storage area whose contents can
vary during processing.
: Constant is a data item which does not change its
value during the execution of a program.
: Data type is defined as the set of possible values a
variable can hold.
Recap
• C language was designed by Dennis Ritchie in early 70’s at the Bell Telephone
Laboratories for use with the Unix operating system.
• Character set is a set of valid characters that a language can recognize.
• Words, which have special meaning for the compiler, are known as keywords.
• Variable refers to a storage area whose contents can vary during processing.
• Constant is a data item which does not change its value during the execution
of a program.
• String literal is a sequence of zero or more characters surrounded by double
quotes.
• Data type is defined as the set of possible values a variable can hold.
• A modifier is used to change the meaning of the basic data type according to
the requirement of the program.
• Operators are the symbols or letters which makes the compiler perform a
specific operations on operands (variables) in a program.
• Arithmetic operators are used for various mathematical calculations.
• Relational operator is used to compare two values and the result of this
comparison is always logical i.e. either true or false.
• Logical operator is used to connect two relational or logical expressions.
• Selection statements allow your program to choose different path of execution
based upon the outcome of an expression or the state of a variable.
JBD
Computer Studies-10 205
Review Yourself
1. Answer the following questions.
a. What is C language? What are the characteristics of C language?
b. What are the important elements of C language?
c. What is a variable? What the rules for naming a variable in C language?
d. What is a constant? What are the different types of constant available in C
language?
e. What is a data type? Name the basic data types in C language.
f. What are operators? What are the different types of C operators?
g. What do you mean by selection statement? List the selection statements
of C program.
h. What do you mean by looping? Name the looping statements provided by C.
i. What do you understand by an array? How is an array declared in C program?
j. State the difference between call by value and call by reference.
2. Point out errors, if any, in the following programs, after executing them on your computer.
a. include <stdio.h>
main()
{
int i,p,r,t;
p=1000;
r=10;
t=4;
i=(p*r*t)/100;
printf(“Interest is %d”,i);
}
b. main()
{
top:
int a=2,c=1;
printf(“%d\t”,a);
a=a+2
c=c+1
if(c<=100)
goto top;
}
JBD
206 Computer Studies-10
3. Write down the output of following programs.
a. a. # include <stdio.h>
# include <conio.h>
void main()
{
clrscr();
int outloop=1;
do
{ int inloop=1;
do
{
printf(“%d”,inloop);
inloop=inloop+1;
}
while(inloop<=outloop);
outloop=outloop+1;
printf(“\n”);
}
while(outloop<=5);
getch();
}
b. #include<stdio.h>
#include<conio.h>
void main()
{
int l;
int n[5]={4,6,99,3,2};
int g=0;
for (l=0;l<=4;l++)
{
if(n[l]>g)
g=n[l];
clrscr();
printf(“Greatest number=%d”, g);
}
getch();
}
JBD
Computer Studies-10 207
4. Solve the following problems.
a. Write a C program to find the area and circumference of the circle.
b. Write a C program to check whether the candidate ‘s age is greater than
17 or not. If yes, display message “Eligble for voting”.
c. Write a program in C to input sales amount for a salesman. Print sales
commission using the following ranges of values.
Sales Amount Commission
Below 1000 5%
>=1000 and <10000 10%
>=10000 15%
d. Write a program in C program to input three numbers and print the
greatest number among them.
e. Write a C program to generate the following series:
1,.03, .005,.0007, .00009
f. Write a C program that prints the sum of the first ten natural numbers.
g. Write a C program that prints the multiplication table of 2 upto ten multiples.
h. Write a C program to print the prime numbers from 1 to 200.
i. Write a C program to input a number and find the sum of its individual digits.
j. Write a C program to generate the following patterns:
i. ii.
5 5 4 3 2 1
5 5 5 4 3 2
5 5 5 5 4 3
5 5 5 5 5 4
5 5 5 5 5 5
iii. iv.
1 1
12 121
123 12321
1234 1234321
12345 123454321
v. vi.
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
JBD
208 Computer Studies-10
Solved Model Test Paper
Group A
Computer Fundamental (22 marks)
1. Answer the following questions. 5 x 2 = 10.
a. What is guided media? Give examples.
Ans: Guided media is any network media that travels in a contained conductor.
Some of the examples of guided media are twisted pair wire, coaxial cable
and fiber optic cable.
b. What is video conference?
Ans: Video conference is the transmission of image/video and speech/audio back
and forth between two or more geographically dispersed persons.
c. What is virtual reality in the field of multimedia?
Ans: Virtual reality is a computer simulation of a real or imaginary system that
enables a user to perform operations on the simulated system and shows
the effects in real time.
d. What is a backup?
Ans: Backup is a computer security protection method whereby several duplicate
copies of data on different storage media or additional hardware resources
ready to take over if the main system fails.
e. What is a computer virus? What are the common routes for virus infiltration?
Ans: A computer virus is a computer program designed to copy itself into other
programs, with the infection of causing mischief or damage.
The common routes for virus infiltration are floppy disk, email attachments,
pirated software and shareware.
2.
a. Convert as indicated. 2x1=2
i. (7EA)16 into Decimal ii. (1111010)2 into Octal
Ans: (2026)10 (172)8
b. Perform the binary operations. 2x1=2
i. (11011111×1101)-1100111 ii. 10100111 ÷ 101
Ans: (101011101100)2 Q=(100001) and R=(10)
JBD
Computer Studies-10 209
3. Match the following. 4 x 0.5 = 2
Group A Group B 4 x 0.5 = 2
Internet Power protection device
Infrared Telnet
Internet Service Unguided media
UPS File Service
Mother of all networks
Ans: Group B
Group A Mother of all networks
Internet Unguided media
Infrared Telnet
Internet Service Power protection device
UPS
4. Choose the correct answer.
a. Which is not the protocol?
i. TCP/IP ii. HTML
iii. HTTP iv. AppleTalk
Ans: HTML
b. Which form of law protects invention?
i. copyright ii. patient
iii. trade secret iv. intellectual property
Ans: Patient
c. Which is not the network connector?
i. RJ45 ii. ST
iii. BNC iv. PBX
Ans: PBX
d. Which of the following is hardware security?
i. Backup ii. UPS
iii. Scandisk iv. Password
Ans: UPS
JBD
210 Computer Studies-10
5. Write down the technical terms of the following. 4 x 0.5 = 2
a. A program that allows to log into another computer on the internet.
Ans: Telnet
b. Sending and receiving messages through computer.
Ans: Email
c. The technique used to provide medical information and services through
the Internet.
Ans: E-medicine
d. Software used to display HTML document.
Ans: Web Browser
6. Write the full forms of the following abbreviations. 4 x 0.5 = 2
a. EMI
Ans: Electromagnetic Interference
b. ISP
Ans: Internet Service Provider
c. CSMA/CD
Ans: Carrier Sense Multiple Access/Collision Detection
d. ISDN
Ans: Integrated Service Digital Network
Group ‘B’
Database Management (10 Marks)
7. Answer the following questions. 3x2=6
a. What is a database system? What are the advantages provided by a database
system?
Ans: A database is a collection of interrelated data and a database system is
basically a computer based record keeping system.
The advantages provided by a database system are:
a. Reduced data redundancy
b. Controlled data inconsistency
c. Shared data
d. Standardized data
JBD
Computer Studies-10 211
b. What is field size? What is the use of ‘Format’ field property?
Ans: Field size is used to set maximum size for data stored in a fixed set to the
text, number or auto number data type. The use of ‘Format’ Field property
specifies how data displays in a table and prints.
c. What is a report in Microsoft Access?
Ans: Report is an Access database object that presents information in a printed
format. It is a summary of the data contained in one or more tables or queries.
It will often provide answers about the information in your database such
as the yearly sales for a specific product or the payroll data.
8. State True or False. 4 x 0.5 = 2
a. Maximum field size of memo field is 256 characters.
Ans: False
b. A customizable database object that is used to enter, edit and view data is
called Report.
Ans: False
c. Combination of one or more primary key is composite key.
Ans: True
d. A query which retrieves records from a table is called update query.
Ans: False
9. Match the following. 4 x 0.5 = 2
Group A Group B
Field Smallest unit of information
Design view Data entry
Form Change the table structure
Query Each column in a table
Show final report
Ans: Group B
Group A Show final report
Report Data entry
Form Change the table structure
Design view Each column in a table
Field
JBD
212 Computer Studies-10
Group ‘C’
Programming (18 Marks)
10. Answer the following questions.
a. Define actual and formal parameters. 1
Ans: Actual parameters are the variables or constants which are used to pass real
value or data to the procedure. Formal parameters are variables which are
used to specify or declare types of data to be passed to the procedures.
b. What do mean by string literal in C language? 1
Ans: String literal is a sequence of zero or more characters surrounded by double
quotes. When a string literal is assigned to an identifier declared as a
constant, then it is known as a string constant.
c. Write down the function of the following statements: ` 1
i. COMMON ii. DIM SHARED
Ans: The COMMON statement is a non-executable statement that declares
variables as global, so that they can be shared between main program,
subprograms and functions.
The DIM SHARED statement makes the variable accessible to all the
modules. It appears in the main program.
11. Write the output of the following program.
DECLARE FUNCTION vcount (a$)
x$=”SCHOOL”
y$=”INSTITUTE”
IF vcount(x$)>vcount(y$) THEN PRINT x$ ELSE PRINT y$
END
FUNCTION vcount (a$)
n$=UCASE$(a$)
FOR x= 1 TO LEN (n$)
c$=MID$(n$, x, 1)
IF c$=”A” OR c$=”E” OR c$=”I” OR c$=”O” OR c$=”U” THEN
v=v+1
END IF
NEXT x
vcount = v
END FUNCTION
JBD
Computer Studies-10 213
Ans: The output of the above program is INSTITUTE (Since it compares the number
of vowels presenting in the given two strings and display the one which has more
vowels).
12. Debug the following program. 2
DECLARE FUNCTION sum (n ( )) DIM n (10)
FOR j= 1 TO 10
INPUT “Enter any 10 number:”; n(j)
NEXT j
PRINT “Sum of even numbers:”; sum(n(10))
END
FUNCTION sum (n ( ))
s=0
FOR k= 1 TO 10
IF n (k) mod 2 < > 0 THEN
s$=s$+n (k)
END IF
NEXT k
s=sum
END FUNCTION
Ans:
DECLARE FUNCTION sum (n ())
CLS
DIM n (10)
FOR j= 1 TO 10
INPUT “Enter any 10 number:”; n(j)
NEXT j
PRINT “Sum:::”; sum(n())
END
FUNCTION sum (n ())
s=0
FOR k= 1 TO 10
IF n (k) mod 2 = 0 THEN
s=s+n (k)
END IF
NEXT k
sum= s
END FUNCTION
JBD
214 Computer Studies-10
13. Read the following program and answer the following questions: 2x1=2
DECLARE FUNCTION result (n)
PRINT result (16)
END
FUNCTION result (n)
WHILE n<>0
a= n MOD 2
n=n\2
e$=STR$(a)
f$=e$+f$
WEND
rt=val (f$)
result=rt
END FUNCTION
a. Write the output of the above program.
Ans: The output of the above program is 10000 since it coverts the decimal
number into binary equivalent.
b. What happens if we write the statement f$=e$+f$ as f$=f$+e$
Ans: The output will be 00001 since the string concatenation is done in reverse
process.
14.
a. Write a program using FUNCTION...END FUNCTION to input the principal, rate of interest
and the number of years and find the simple interest by using expression method. 3
Solution:
DECLARE FUNCTION prt! (p!, r!, t!)
INPUT “Enter a principal”; p
INPUT “Enter a time”; t
INPUT “Enter a rate”; r
interest = prt(p, r, t)
PRINT “The interest is=”; interest
END
FUNCTION prt (p, r, t)
i = (p * r * t) / 100
JBD
Computer Studies-10 215
prt = i
END FUNCTION
b. Write a program to find the HCF and LCM of any two numbers using SUB procedure. 3
Solution:
DECLARE SUB HCL (A,B)
INPUT “Enter any two numbers:”; A,B
CALL HCL (A,B)
END
SUB HCL (A,B)
C=A: D=B
AA:
R= C MOD D
IF R = 0 THEN
PRINT “ Hcf:” ; D
PRINT “Lcm:”; (A*B)/D
END IF
C=D
D=R
GOTO AA
END SUB
c. Write a program which reads records from the file “RESULT.DAT” having the fields name,
and marks of three different subjects and display only those records whose percentage is
greater than 60 and less than 80. Also count the total number of records present in that data
file. 3
Solution:
OPEN “result.dat” FOR INPUT AS #1
DO UNTIL EOF(1)
INPUT #1, a$, b, c, d
c=c+1
p= (b+c+d)/3
IF p>60 AND p<80 THEN PRINT a$, b, c, d
LOOP
PRINT “Total records:”; c
CLOSE #1
JBD
216 Computer Studies-10
Unsolved Practical Test Paper
Group ‘A’
Microsoft Access (10 Marks)
1. a. Create a table ‘student’ having following structure. 2
Field Name Data type
R oll_No Number F_Name Text
Address Text
Gender Yes/No
b. Add five records in the table. 2
c. Make a query “query_asc” to display all the records in ascending order by their F_
Names. 2
d. Create a query “query_grt” to display all the records having the Roll_No greater than
3. 2
e. Create a report including all the fields using wizard. 2
Group ‘B’
QBASIC (15 marks)
2.
a. Write a program to calculate and print total surface area of a box using SUB...END
SUB statement.
[Hint: a= (lb+bh+lh)] 3
b. Write a program to print the following series of numbers using SUB...END SUB
statement. 3
2,22,222,...up to 5th terms.
c. Write a program to find out the cube root of an input number using FUNCTION ...
END FUNCTION statement. 3
d. Write a program to store employees’ name, address, phone, age and service year in a
sequential data file ‘emprec.dat’. 3
e. Write a program to display all the records having age greater than 60 and service year
greater than or equal to 20 years from the data file created in question no 2.(d).
3
JBD
Computer Studies-10 217
Project Work a. Add Books
Sajilo Departmental Store dealing This option adds a new item to the
in a variety of Nepal goods need to
computerize their stock system so that stock file. It asks the item code, item
all their transaction and records are description and the stock quantity.
maintained regularly, accurately and After adding one record it asks the
efficiently. The stock file contains item user “Do you want to add more
code, item description and the stock records (y/n)?. If the user presses Y,
quantity. it allows to add new record and if he
The program should have a menu that presses N, it goes back to the main
allows the user to perform the following module.
tasks:
a. Add new records to the file.
b. Display the contents of the entire file.
c. Modify any record in the file.
d. Delete any unwanted records from
the file.
e. Search for a particular item and
display it.
Solution:
Main Module
QBASIC program consists of module-
level code and a number of procedures.
The module-level code is the main
program controlling the computer. The
program should have a menu as shown
below:
1. Adding Record
2. Display records
3. Modify Record
4. Delete Record
5. Search Record
JBD
218 Computer Studies-10
b. Display
This option displays all the records
in a tabular format. It displays the
item code, item description and the
stock quantity.
b. Modify
This option ask the user to “Enter
the item code”. If it finds the record,
then it will ask you to modify the
stock otherwise gives the message
“Record Not Found” and then press
any key to continue.
JBD
Computer Studies-10 219
d. Delete
This option is used to delete the
record. It asks the item code to be
deleted. It also asks the user that if he
wants to delete more records or not.
e. Search
This option provides a choice of
searching item according to the item
code number. It ask the user for the
item code, if finds it, then it should
display the record otherwise it
should display the message”Record
Not Found”.
JBD
220 Computer Studies-10
Sample Data: Record 2 PRINT “4. DELETE RECORD”
Record 1 I02 LOCATE 12, 20
I01 Monitor PRINT “5. SEARCH RECORD”
Scanner 3500 LOCATE 13, 20
2000 PRINT “6. EXIT”
LOCATE 15, 20
Record 3 Record 4 INPUT “Enter the choice 1-6”; ch
I03 I04 SELECT CASE ch
CPU Mouse CASE 1
300 5000 CALL add1
CASE 2
Program Code: CALL display
DECLARE SUB add1 () CASE 3
DECLARE SUB display () CALL modify
DECLARE SUB modify () CASE 4
DECLARE SUB delete () CALL delete
DECLARE SUB search () CASE 5
CLS CALL search
LOCATE 3, 20 CASE 6
PRINT “Stock Management Program” END
LOCATE 8, 20 END SELECT
PRINT “1. ADD RECORD”
LOCATE 9, 20 SUB add1
PRINT “2. DISPLAY ALL RECORDS” OPEN “O”, #1, “stock.dat”
LOCATE 10, 20 WHILE NOT UCASE$(choice$) = “N”
PRINT “3. MODIFY RECORD” INPUT “Item Code Number : “; icode
LOCATE 11, 20 INPUT “Item description : “; ides$
INPUT “Total stock quantity : “; n
WRITE #1, icode, ides$, n
INPUT “Add more record (y/n)”; choice$
WEND
CLOSE #1
END SUB
SUB display
PRINT “item_code”, “description”,_
“stock quantity”
JBD
Computer Studies-10 221
PRINT STRING$(50, “-”) OPEN “O”, #2, “temp.dat”
OPEN “I”, #1, “stock.dat” tem = 0
WHILE NOT EOF(1) WHILE NOT EOF(1)
INPUT #1, icode, ides$, n INPUT #1, icode, ides$, n
PRINT icode, ides$, n IF (icode <> ncode) THEN
WEND WRITE #2, icode, ides$, n
CLOSE #1 ELSE
END SUB PRINT icode, ides$, n
tem = 1
SUB delete INPUT “Edit this record”; y$
CLS IF UCASE$(y$) = “Y” THEN
INPUT “Enter the item code”; ncode INPUT “Enter new item code “; nicode
tem = 0 INPUT “Enter new description”; nides$
OPEN “I”, #1, “stock.dat” INPUT “Enter new quantity”; nn
OPEN “O”, #2, “temp.dat” WRITE #2, nicode, nides$, nn
WHILE NOT EOF(1) PRINT “Record Modified...”
INPUT #1, icode, ides$, n ELSE
IF ncode = icode THEN WRITE #2, icode, ides$, n
PRINT “Record is deleted” END IF
tem = 1 END IF
ELSE WEND
WRITE #2, icode, ides$, n IF tem = 0 THEN
END IF PRINT “Record Not Found”
WEND END IF
IF tem = 0 THEN CLOSE #1, #2
PRINT “Record Not Found” KILL “stock.dat”
END IF NAME “temp.dat” AS “stock.dat”
CLOSE #1 END SUB
CLOSE #2
KILL “stock.dat” SUB search
NAME “temp.dat” AS “stock.dat” tem = 0
END SUB OPEN “I”, #1, “stock.dat”
INPUT “Enter book code to search”;
SUB modify
CLS ncode
INPUT “Enter the item code”; ncode WHILE NOT EOF(1)
OPEN “I”, #1, “stock.dat” INPUT #1, icode, ides$, n
IF ncode = icode THEN
JBD
222 Computer Studies-10
PRINT STRING$(35, “-”)
PRINT “item code : “; icode
PRINT “Description : “; ides$
PRINT “Total Quantity :”; n
PRINT STRING$(40, “-”)
tem = 1
END IF
WEND
IF tem = 0 THEN
PRINT “Record Not Found”
END IF
CLOSE #1
END SUB
JBD
Computer Studies-10 223
SLC Specification Grid
S.No. Type of Questions Topics No. of Questions Marks
2 4
1. Subjective Group A (Fundamentals) 2
1 4
1.a. Computer Networking 2 4
8
and Telecommunication 2
2
1.b. Email and Internet 16 x .5
1.c. Multimedia and application
Cyber law and ethics
1.d Computer Security
1.e Computer Virus
2. Number System
a. Conversion
b. Binary calculation
2. Objective 3. Matching
4. Multiple Choice/True or False
5. Technical Terms
6. Full Forms
3. Subjective Group B (Database)
7. a.b Introduction 2 4
Creating database
Entering and Editing data
7.c Querying database 1 2
Creating and using forms
Creating and printing reports
Objective 8. Multiple choice/True or False 8 x .5 4
9. Matching
4. Subjective Group C (Programming)
10.a,b Conceptual Questions 2 x 1 2
(QBASIC/C)
Function of QBASIC statements 2 x 0.5 1
11. Debug 1 x 2 2
12. Output 1 x 2 2
13. Analytical Type 2 x 1 2
14. Writing program 3 x 3 9
a,b,c (One question from each:
FUNCTION and SUB procedures and
Sequential data file handling)
Note:
a. In writing program one question from FUNCTION or SUB procedure should be without looping and conditional
statements.
b. Conceptual question from C Language should be asked from the following topics.
- Introduction
- Data types
- Simple features of C Language.
JBD
224 Computer Studies-10