Computer science 10th

Computer science 10th
Prepared by: SYED ALI RAZA
(BSCS) Virtual University (pk)
mailto:[email protected]
Chap no 1:
Administrator: SOHAIL ASHRAF
Takbeer Science Academy &School
(M.B.DIN)
Problem Solving
Some basic symbols of flow chart
Start and end
Process
Input / Output
Decision making
Connector
Off page/ On page
Connector
Predefined process
Arrow for direction
HONESTY
IS THE BEST POLICY
Question no 1: (in book ques no:08)
Draw a flow chart to find the largest of three numbers
Sol:
start
I/P a,b,c
IF
a>b
a>c
NO
IF
b>a
b>c
NO
YES
Print a
IF
c>a
c>b
Print b
Print c
END
Question no 2: (in book ques no:09)
Write an algorithm to calculate the area of a circle whwn the radius is given
(area= π r 2 )
Sol:
Type
Start
Input
Process
Output
Stop
work / action
start procedure
input (value of radius)
compute area of circle
print area
end the procedure
Question no 3: (in book ques no:10(x) )
Write an algorithm to calculate the distance covered by car moving at an average
speed of v ms −1 in time t .The program should input average speed v and t .
Hint ( s = vt ) where s is the distance traveled.
Sol:
Type
Start
Input
Process
Output
Stop
work / action
start procedure
input (average speed and time v , t )
compute distance ( s )
print the value of s (distance )
end the procedure
Prepared by: SYED ALI RAZA
TAKBEER SCIENCE SCHOOL
(M.B.DIN)
Chap no 02:
Data type ,Assignment and Input /Output statement
Question no 1:( in book ques no : 09)
Write a program to read ten values specified in Data statement and display the sum
of these values on the screen.
10 cls
20 Read a,b,c,d,e,f,g,h,,I,j
30 S=a+b+c+d+e+f+g+h+i+j
40 print “The sum of ten values is=”;S
50 Data 1,2,3,4,5,6,7,8,9,10
60 end
(declare variable using read data statement)
(process)
(For display result)
(assign values to variables)
Output:
The sum of ten values is=55
Question no 2:( in book ques no : 10(ix) )
Write a program that asks for the name,roll number,class,section and marks in
different subjects of a student of class 10.The program should calculate and display
total marks and percentage of a student ( using INPUT statement)
10 cls
20 input “plz enter student’s name:”;n
30 input “plz enter student’s roll no:”;r
40 input “plz enter student’s class:”;c
50 input “plz enter student’s section:”;s
60 input “plz enter obt marks in eng:”;e
70 input “plz enter obt marks in phy:”;p
80 input “plz enter obt marks in mth:”;m
90 input “plz enter obt marks in pak st:”;pk
100 input “plz enter obt marks in comp:”;cs
110 input “plz enter obt marks in urdu:”;u
120 input “plz enter obt marks in chem:”;ch
130 total=e+p+m+pk+cs+u+ch
140 avg=(total/850)*100
150 print “the total marks is=”;total
160 print “the percentage is=”;avg
170 end
Question no 3:( in book ques no : 10(x) )
Write a program to calculate the distance by a car moving at an average speed of
v ms −1 in time t. the program should input average speed and time (using input
statement)
10 cls
20 input “plz enter the value of v=”;v
30 input “plz enter the value of t=”;t
40 S=v*t
50 print”the total distance is =”;S
60 end
Output :
plz enter the value of v=4
plz enter the value of t=3
the total distance is =12
Question no 4:( in book ques no : 11 )
Write a program to calculate the volume of cylinder .the program should get the
value for height of the cylinder and radius of its base from the user through INPUT
statement.
Hint:( volume = π r 2 h )
10 cls
20 pi=3.14
(fix value)
30 input “plz enter the value of height=”;h
40 input “plz enter the value of radius=”;r
50 V=pi*r^2*h
60 print “The volume of the cylinder is=”;V
70 end
Output:
plz enter the value of height=2
plz enter the value of radius=2
The volume of the cylinder is=25.12
Question no 5:( in book ques no : 12 )
Write a program to calculate the square of given number.the program should get
the number from the user through INPUT statement.
10 cls
20 input “plz enter the number do u want to square =”;n
30 let S=n*n
40 print “The square is =”;S
50 end
Output:
plz enter the number do u want to square =5
The square is =25
Question no 6:( in book ques no : 13 )
Write a program to calculate and print the sum and average of three number using
LET statement.
10 cls
20 let a=2
30 let b=3
40 let c=4
50 let d=a+b+c
60 let avg=d/3
70 print “the sum of three numbers is=”;d
80 print “the average of three numbers is=”;avg
90 end
Output:
the sum of three numbers is=9
the average of three numbers is=3
Prepared by: SYED ALI RAZA
TAKBEER SCIENCE SCHOOL
(M.B.DIN)
Chap no 3:
Control Structures
Question no 1:( in book ques no : 8 )
Write a program to calculate the area of the triangle.the program should get the
values for base and altitude of the triangle from the user and the result.
Hint :(area =1/2*base*altitude)
10 cls
20 input “plz enter the value of base=”;b
30 input “plz enter the value of altitude=”;a
40 area=1/2*b*a
50 print “The area of the triangle is=”;area
60 end
Output:
plz enter the value of base=2
plz enter the value of altitude=3
The area of the triangle is=3
Question no 2:( in book ques no : 9 )
Write a program to calculate the area and circumference of the circle.the program
should get the radius of the circle and display result.
Hint:(cir= 2π r and
2
area= π r )
10 cls
20 input “plz enter the value of radius=”;r
30 pi=3.14
40 A=pi*r^2
50 C=2*pi*r
60 print “The area of the circle is=”;A
70 print “The circumference of the circle is=”;C
80 end
Output:
plz enter the value of radius=3
The area of the circle is=28.26
The circumference of the circle is=18.84
Question no 3:( in book ques no : 10 )
Write a program to print first ten odd numbers using WHILE WEND loop.
10 cls
20 A=1
30 While A<=19
40 print A
50 A=A+2
60 Wend
70 end
Output:
1
3
5
7
9
11
13
15
17
19
Question no 4:( in book ques no : 11 )
Write a program to print the sum of squares of first five even numbers using FOR
NEXT loop.
10 cls
20 sum=0
30 For A=2 to 10 step 2
40 SUM=SUM+A
50 Next A
60 S=SUM*SUM
70 Print “the sum of first five even numbers is=”;SUM
80 Print “the square of sum of even numbers is=”;S
90 end
Output:
the sum of first five even numbers is=30
the square of sum of even numbers is=900
Question no 5:( in book ques no : 12 )
Write a program to find the larger of two numbers. The program should get the
numbers from the user.
10 cls
20 input “plz enter the first number=”;a
30 input “plz enter the second number=”;b
40 IF a>b then largest=a
50 IF b>a the largest=b
60 print “the larger number is =”;largest
70 end
Output:
plz enter the first number=6
plz enter the second number=8
the larger number is =8
Question no 6:( in book ques no : 13 )
Write a program to print the table of the given numbers .the program should get the
number from the user.
10 cls
20 input “plz enter the number=”;n
30 For T=1 to 10
40 print n, “*”,T, “=”,t*n
50 Next T
60 end
Output :
plz enter the number=3
3 * 1= 3
3 * 2= 6
3 * 3= 9
3 * 4= 12
3 * 5= 15
3 * 6= 18
3 * 7= 21
3 * 8= 24
3 * 9= 27
3 * 10= 30
An other solution in which user selects the starting and ending point of table.
10 cls
20 input “Give the number for table=”;a
30 input “Give the starting number =”;b
40 input “Give the number for count=”;c
30 For T=b to c
40 print a, “*”,T, “=”,t*a
50 Next T
60 end
Output :
Give the number for table=4
Give the starting number =3
Give the number for count=6
4 * 3 =12
4 * 4 =16
4 * 5 = 20
4 * 6= 24
Chap no 4:
ARRAYS
Question no 1:( in book ques no : 14 )
Write a program to print a list of odd numbers from the given numbers
6,42,4,77,32,9,21,22,8,45,15,46
Sol:
10 cls
20 DIM A(12)
30 FOR B=1 to 12
40 Read A(B)
50 IF A(B) mod 2 <>0 then print A(B)
60 Next B
70 Data 6,42,4,77,32,9,21,22,8,45,15,46
80 end
Output :
77
9
21
45
15
Question no 2:( in book ques no : 17 )
Find out the errors in the following program segments if any?
10 DIM N$(10)
20 FOR K=4 TO 15
30 INPUT N$
40 NEXT I
SOL:
Error in line no 40. NEXT K instead of NEXT I
10 FOR J=K TO 15
20 K(J)=J
30 PRINT K(J)
40 NEXT J
SOL:
Error in line no 20 in which subscript is out of range (error message occurred)
during program running.
Chap no 5:
SUB-PROGRAM AND FILE HANDLING
Question no 1:( in book ques no : 11 )
Write a program to get full name of any person and return the number of
characters in his first name.
Sol:
10 cls
20 input “plz enter any name:”;N$
30 T$= “A”
40 WHILE T$<>” “
50 C=C+1
60 T$=MID$(N$,C,1)
70 WEND
80 print”The no of characters is=”;C-1
90 end
Output:
plz enter any name: takbeer science
The no of characters is=7
Question no 2:( in book ques no : 14 )
Write a program that changes temperature in Celsius to Fahrenheit. Use DEF FN
statement to define function for the convection formula.
Hint : f=9/5*C+32
SYNTAX(DEF FN)
DEF FN name (arguments) expression
10 cls
20 DEF FN A(c)=9/5*C+32
30 input “plz enter the temp in Celsius =”;C
40 print “The temp in Fahrenheit =”;FN A(c)
50 end
Output:
plz enter the temp in Celsius =4
The temp in Fahrenheit =39.2
Chap no 6
GRAPHICS IN BASIC
Question no 1:( in book ques no : 9 )
Find out the errors in the following if any?
a). LINE (140,100)-(300-100),2,BF,4
SOL:
Symbol (-) that is placed between co ordinates (300-100) should be replaced by
(,) hence it is (300,100)
LINE (140,100)-(300,100), 2, BF, 4
b).
10 screen 2
20 color 1,2
30 draw “U10 R10 D10 L10”
SOL:
PSET (250,50) is used to draw box should be placed in the LINE no.20 instead
color 1,2
c)
10 screen 1
20 A=20
30 DRAW “U=A R=A,D=A L=A”
DRAW “U20 R20 D20 L20” should be placed in line no 30 instead of
DRAW “U=A R=A,D=A L=A”
Question no 2:( in book ques no : 10 )
What will be the output of the following:
a)
10 SCREEN 2
20 PSET(250,50)
30 DRAW “G50 R100 H50”
40 END
Output:
b)
10 SCREEN 2
20 FOR I=30 TO 180
30 CIRCLE (1,100), 50
40 NEXT I
Output:
Question no 3:( in book ques no : 15 )
Write a program to produce five concentric circles of different radii.
Sol:
10 cls
20 screen 1
30 circle (100,100),10,5
40 circle (100,100),30,4
50 circle (100,100),50,3
60 circle (100,100),70,2
70 circle (100,100),90,1
80 end
Question no 4:( in book ques no : 16 )
Write a program to draw a parallelogram by using DRAW statement;
10 cls
20 SCREEN 2
30 LINE (10,150)-(200,175),1,B
40 PSET (160,100)
50 END
GOOD LUCK