CMS Class VII Additional Booklet
CMS Class VII Additional Booklet
BASIC 256 7
LESSON
Learning Outcomes
Introduction to programming language
By the
Haveendyou
of this
everlesson, you will
wondered how becomputers
able to: work? Can they make a decision and
• doWrite syntax-based programs.
their work alone? No, the computer can’t do their work alone. They don’t
• have
Take any
inputintelligence.
from users. Computers depend on humans to tell them what to do
• and
Perform
howarithmetic and string
to do it. “Telling” theoperations
computers on“what
data. to do ‘’ is termed as Instructions.
• ToDisplay numerical,
instruct textual we
the computer andneed
graphical output. called programming language.
a language,
Programming language is a tool, used to write instructions for computers.
Programming languages are of three types
Tejas, Jyoti and their classmates are excited as they are about to learn a new programming
language• called BASIC.
Machine The application called BASIC-256 is opened on a computer by
language
Moz. All of them surround the computer and see that the window of this application has
• Assembly language
some familiar options like New, Open, Save, etc.
They also• notice
High-Level language
some new options like Run.
BASIC 256
3
_CBSE_CM_Level-6.indd 139 10/26/2017 5:35:45 PM
Moz: Now that you have understood the print statement, go ahead and try it
Title bar: Displays the name of the program. Default name on the title bar is
out some more.
“Untitled 1-BASIC-256”
Tejas: Should we start a new program?
Menu bar: menu bar contains File, Edit, View, Run, and Help options.
Moz: You can add more statements and run the same program or you can
The options
start awhich are frequently
new program used
(using New). Youarecan displayed below(using
also save programs the menu bar. It is a
movableSave)
toolbar, weacan
and load savedchange
programits position.
later (using Open).
PROGRAM OUTPUT
Jyoti: In the
Multiple statement Print
operators
Concatenation * (50+68+35)/3, BODMAS
Print 250 + (250 - 100) * rule850is used to evaluate
the arithmetic expression and20then
/5
the result is displayed.
The ‘+’ operator, when used with strings, joins them together. This operation is
Arithmetic Operators In concatenation two or more strings are joined together
called concatenation.
Moz:to make
Now trya out thesestring.
longer statements.
Arithmetic operation Operator BASIC-256 program and text output
PROGRAM OUTPUT
PROGRAM OUTPUT
Addition +
Print "Jyoti and Tejas " + "are learning BASIC." Jyoti and Tejas are learning BASIC.
Print 256 + 567 + 678 1501
Info
PROGRAM OUTPUT
PROGRAM
Subtraction – OUTPUT
Print 1000 - 750 250
Print "Today the price of 12 apples is = Rs. " + Today the price of 12 apples is = Rs. 60
(5 * 12)
PROGRAM OUTPUT
Multiplication ×
Print 250 * 20 5000
PROGRAM OUTPUT
Print "The area of a rectangle of length 12 units The area of a rectangle of length 12 units and
and breadth 8 units = "+ (12 * 8) + " square units" breadth 8 units = 96 square units
Tejas: In these statements, phrases (strings) are combined to get a full sentence.
142 Computer Masti
BASIC 256
Jyoti: In the second statement, the price of 12 apples is calculated and printed. 5
Moz: The ‘+’ operator, when used with strings, joins them together. This
CBSE_CM_Level-6.indd 142
Class VII.indd 5
operation is called concatenation. In concatenation, two or more strings 10/26/2017 5:35:54 PM
12-05-2022 17:34:35
are joined together to make a longer string.
String Operation
Start
End
Read A
Moz: Use the example values where A = 346 and B = 478.
PROGRAM OUTPUT
Read B
Sum of A + B = 824
A = 346
Moz: What are you instructing the computer to do in the first and second
Thestatements?
first statement is instructing the computer to store 346 in
Sum = A + B a variable
Jyoti: named
144
The first statement A. The
is instructing the second
computer instruction Memory similarly instructs
Computer Masti
numbers
Tejas: Next, we areAinstructing
and Bthe and store
computer thetheresult
to add two ofMemory
the addition in a
variable named sum.
numbers, A and B, and store the result of the addition Sum 824
End in the variable named Sum. (346+478)
Thethevariable
Next, we are instructing computerin to which we store text is called string variable.We put a ‘$’ sign at
add the two
Memory
Computer Masti
10/26/2017 5:35:58 PM
COMPUTER MASTI
6
Jyoti: When
Jyoti: When we start a new program, the output of the previous program isprogram
still
cls and clgwe
displayed. Is
start
statements
it
a new
possible to
program,
clear the
the output
Text Output
of the previous
area?
is still
displayed. Is it possible to clear the Text Output area?
Moz: cls clears the Text Output area and clg clears the Graphics Output area.
Whenclswe
Moz: startthe
a new programme, theclgoutput of the previous programme is still
Youclears
can also useText
theseOutput area
statements in and
programs clears
to clearthe
theGraphics
Text and Output area.
displayed.
You can‘els’
Graphics clears
also
Output use the text
these
areas. outputinarea
statements and ‘clg’
programs clears
to clear the the
Textgraphics
and output
area. Graphics Output areas.
PROGRAM OUTPUT
PROGRAM
cls OUTPUT
clg
cls
clg
PROGRAM OUTPUT
Memory
NamePet$ = “Prince” Prince is my pet.
it comes OUTPUT
When I call my pet by its name Prince,
PROGRAM
Print NamePet$;
running to me. NamePet$
Print " is my pet."
Input statement- To take inputPrince
from the user
Print "When I call my pet by its name ";
NamePet$ = “Prince” is my pet.
Prince Memory
Print NamePet$;
Print
Print ",NamePet$;
it comes running to me." When I call my pet by its name Prince,
it comes running to me. NamePet$
Input
Print " is a statement
is my pet." to retrieve the string or numbers that the user types.
Print A
Jyoti: "When
valueI call my pet by
assigned to its name ";variable is enclosed in quotes.
a string Prince
Print NamePet$;
PROGRAM
Print While
Tejas: ", it comes running to
retrieving have to give the stringOUTPUT
weme." variable name in a statement
Printto“Please
retrieve theyour
enter value. We”;have to keep in mind
name: Pleasethat
enterstring variables
your name: | are
Jyoti:Input
AName$
value
also assigned
case sensitive tonumeric
like a stringvariables.
variable is enclosed in quotes.
Print “Hello,";
Tejas:
Input
PrintWhile
Name$ retrieving we have to give the string variable name in a statement
Statement – To take Input from the User
to retrieve the value. We have to keep in mind that string variables are
Jyoti: Wealsowant
PROGRAM
casethe
sensitive
computerlike numeric
to take variables.
input from Input given by the user
the keyboard and print the
OUTPUT
sum of the numbers. What is the statement to take input?
Memory
Input
Moz:Statement
Print
The“Please
answer – To
enter intake
is your Input
name:
your ”; from
question. Inputthe User
Please
is the enter your
statement name: Jyoti
to retrieve the
Input Name$ Hello, Jyoti Name$
strings
Print or numbers that the user types. Enter the following programs and
"Hello,";
Print
runName$
them. Find out how each statement is executed. Jyoti
Jyoti: We want the computer to take input from the keyboard and print the
sum of the numbers. What is the statement to take input?
146 PROGRAM Computer Masti
OUTPUT Cursor
Moz: The answer is in your question. Input is the statement to retrieve the
Input Name$ |
Printstrings
“Hello ” or numbers that the user types.
+ Name$ Enter the following programs and
02_CBSE_CM_Level-6.indd 146
run them. Find out how each statement is executed. 10/26/2017 5:36:04 PM
PROGRAM OUTPUT
Memory
Input Name$ Jyoti
Print “Hello ” + Name$ Hello Jyoti Name$
Jyoti
Jyoti:
BASIC 256We enter a name at the cursor. The name that we enter is stored in the
7
string variable Name$.
Tejas: Next, a message is displayed using the name that was stored in Name$.
Class VII.indd 7
The string stored in Name$ is retrieved and displayed. 12-05-2022 17:34:35
Graphics output area has X and Y coordinates ranging from Oto 299 each, starting
from the top-left corner. The greed of X and Y coordinates are given below.
Graphics OutputTejas:
area in There is a XGraphics
axis Output area in X axis
(0,0) (299,0)
C-256 program interface. the(0,0)
BASIC-256 program interface.(299,0)
we get output on this area? How do we get output on this area?
(50,50) (50,50)
Y Y
amiliar with x and y
Moz: You are
a familiar with x and y a
es. The Graphics Output coordinates.
x
The Graphics Output x
i i
and y coordinates, area has
s x and y coordinates, s
(200,150)
om 0 to 299 each, startingranging from 0 to 299 each, starting (200,150)
op-left corner. (200,125)
from the top-left corner. (200,125)
ew the grid of x and y
es? Jyoti: Can we view the grid of x and y
(0,299)
coordinates? (0,299)
an. You have to enable the
Moz:
Window Grid Lines optionYes, youView
in the can.menu.
You have
Now, to enable
enter the the
statements.
EnableWindow
Graphics the Graphics
Grid Lineswindow
option in thegrid line
View option
menu. in the
Now, enter the View menu. Now enter the
following
following statements.
statements.
clg: statement clears the graphics
output area.
color: Statement specifies the
drawing colour and direct draws a
rectangle in blue.
rect statement: draws a rectangle,
where 0,0 are the X and Y
coordinates of the rectangles
top left corner and the next two
numbers, 300,300 are its length and
breadth. In this case they are equal.
Hence we have a square.
PROGRAM OUTPUT
clg (0, 0)
X
color blue
rect 0,0,300,300
300
tatement clears the Graphics Output area. The next statement, 300
COMPUTER MASTI
8 Jyoti: Next, the colour is changed to yellow. The circle statement draws a circle.
The first two numbers (145, 150) must be the (x, y) coordinates of the
02_CBSE_CM_Level-6.indd 149 10/26/2017 5:36:10 PM
centre. The third number (150) is the radius.
Moz: Yes. The (x, y) coordinates of the centre and the radius of the circle have
to be given to draw a circle.
Class VII.indd 8 12-05-2022 17:34:36
Tejas: Next, another colour, red, is specified. Then a red-coloured circle of
radius 100 is drawn. It has the same centre (145, 150), as the previous
circle.
PROGRAM OUTPUT
The first two numbers (145, 150) must be the (x, y) coordinates of the
centre. The third number (150) is the radius.
Moz: Yes. The (x, y) coordinates of the centre and the radius of the circle have
to be given to draw a circle.
Circle Statement Tejas: Next, another colour, red, is specified. Then a red-coloured circle of
radius 100 is drawn. It has the same centre (145, 150), as the previous
Circle Syntax:
statement: circle.
Circle x, draws
y, radiusa
OUTPUT
circle. The first two numbers PROGRAM
0
15
with its centre y) and the circle 145,150,100 r
Next colour
specifiedred is specified that
radius.
a red coloured circle of the radius 100 is drawn. It has the same centre (145,150)
as the previous circle. 150 Computer Masti
Tejas: In all these statements, the radius and the (x, y) coordinates of the centre
Syntax: circle
areX,already
Y, radius.
given.
The Circle statement uses the current drawing colour
02_CBSE_CM_Level-6.indd 150 10/26/2017 5:36:12 PM
Jyoti: Let us try whether we can draw a circle and rectangle by taking values
and Rodraws a filled circle with its centre at (X, Y) and (x, y)
from the user instead.
the specified radius. x r
Moz: Which statement will you use to take values from the user?
Note: We can take values from the user using an input
Tejas: Input
statement statement.
to draw a rectangle, square and a circle.
Moz: Go ahead and try it.
PROGRAM OUTPUT
Memory
Rem To draw a rectangle Text Output
Print "Give the x and y coordinates of the Give the x and y coordinates of x1 0
top-left corner of the rectangle: " the top-left
y1 0
Input "x coordinate: ", x1 corner of the rectangle:
Input "y coordinate: ", y1 x coordinate: 0 length1 200
y coordinate: 0
Input "Length of the rectangle: ", length1
Length of the rectangle: 200 breadth1 250
Input "Breadth of the rectangle: ", Breadth of the rectangle: 250 x2 200
breadth1 Give the x and y coordinates of
Color Yellow the centre: y2 150
Rect x1, y1, length1, breadth1 x coordinate of centre: 200 r 100
Rem To draw a circle y coordinate of centre: 150
Radius of circle: 100
Print "Give the x and y coordinates of the
centre:” Graphics Output
Input "x coordinate of centre: ", x2
Input "y coordinate of centre: ", y2
Input "Radius of circle: ", r
Color Green
Circle x2, y2, r
Tejas: By using the input statement, the user can give values and draw a circle
or a rectangle.
Moz: Now use all the statements that you have learnt and write a program.
You can also use graphical statements with other kinds of statements in
your program.
BASIC 256
9
02_CBSE_CM_Level-6.indd 151 10/26/2017 5:36:13 PM
WORKSHEET
1. Some BASIC-256 commands are given below. Select the correct output area for each
command.
(a) Print “Hello there.” Text Output area / Graphics Output area
(b) Rect 100, 100, 200, 50 Text Output area / Graphics Output area
(c) Input “Enter a number: ”, A Text Output area / Graphics Output area
2. Given here are some BASIC-256 commands and their possible outputs. Circle the
correct output for each.
i) 142.5 i) 1740
ii) 214 ii) Syntax error around character 15.
iii) 274 iii) (54535)3
iv) 200+(75+10)/5-3 iv) (545+35)*3
3. Anand has written a program to find the profit or loss for a given selling price and
154cost price. When he ran the program it gave an error as shown below. Computer Masti
PROGRAM OUTPUT
CostPrice$ = 500 Error assigning a string to a numeric
SellingPrice$ = 450 variable.
02_CBSE_CM_Level-6.indd 154 10/26/2017 5:36:20 PM
Loss = CostPrice$ - SellingPrice$
Print Loss
Upon seeing the error message he realised that he had made more such errors. Can
you correct all the errors in the program?
X axis
Rem My little red car! 100
(0,0) 50 150 200 250 300
clg
Rem to draw the top portion of the car
Color Red Y 50
a
Rect 100, 0, 100, 50 x
Rem to draw the lower portion of the car i 100
s
Color Red
150
Rect 50, 25, 200, 50
Rem to draw wheels 200
color black
circle 100, 75, 25 250
circle 200, 75, 25
300
7. Given here is a program which finds the perimeter and area of a rectangle.
PROGRAM OUTPUT
# Program to find the area and perimeter of a rectangle. Length of the rectangle = 50
Print "Length of the rectangle = 50" Breadth of the rectangle = 5
Print "Breadth of the rectangle = 5" Area = 250
Area = 50*5 Perimeter = 110
Perimeter = 2*(50+5)
Print "Area = "+ Area
Print "Perimeter = "+ Perimeter
COMPUTER MASTI
12
(a) Change and write the program, so that the length and breadth can be given by
Class VII.indd 12
the user. Give your own input for the program in the Text Output area, and 12-05-2022 17:34:37
calculate the area and perimeter.
(b) Find how many tiles with the dimensions given by you in the above program are
Color Red
150
Rect 50, 25, 200, 50
Rem to draw wheels 200
color black
circle 100, 75, 25 250
circle 200, 75, 25
300
7. Given here is a program which finds the perimeter and area of a rectangle.
PROGRAM OUTPUT
# Program to find the area and perimeter of a rectangle. Length of the rectangle = 50
Print "Length of the rectangle = 50" Breadth of the rectangle = 5
Print "Breadth of the rectangle = 5" Area = 250
Area = 50*5 Perimeter = 110
Perimeter = 2*(50+5)
Print "Area = "+ Area
Print "Perimeter = "+ Perimeter
(a) Change and write the program, so that the length and breadth can be given by
the user. Give your own input for the program in the Text Output area, and
calculate the area and perimeter.
(b) Find how many tiles with the dimensions given by you in the above program are
needed to cover the floor of a room of length 1000 units and breadth 500 units.
PROGRAM OUTPUT
# Program to find the number of tiles.
RoomArea=1000*500
Print "Area of the room=" + RoomArea
TileArea=________________
Print "Area of the tile=" + TileArea
TileNumber=RoomArea/TileArea
Print "Number of tiles=" + TileNumber
(c) Write a similar program to find the area and perimeter of a triangle.
BASIC 256
13
Lab Activity:
LAB ACTIVITY Lab Activity:
ACTIVITY 1. Create a simple dart board using Basic-256 graphical user interface.
1. Create a simple dart board using Basic-256 graphical user interface.
1. Create
1. Attempt the following:
a simple dart board using Basic-256 graphical user interface.
(a) Run the following program and find out its display.
clg
circle 35,20,8
clg
circle 45,20,8
clg
circle 55,20,8
clg
circle 65,20,8
clg
circle 75,20,8
(b) Change the clg command to cls and then run the program. What do you observe?
(c) What will you do2.to makeCreatethe object light
a traffic moveusing
alongBasic
the Y-axis
256 instead?
2. Savani, Ali and Asmit went for a picnic. Each one
carried
2. Create `100 towards
a traffic expenses.
light using Write a program to
Basic 256
2. Create
find the following. Include a traffic
proper lightsousing
comments that Basic 256
others are able to understand your program.
(a) At the picnic they went on a ride. The cost of
each ticket was `30. Find the amount left with
each after the ride.
(b) Savani had an ice cream that cost `20,
Ali had orange juice that cost `25, and
Asmit had an ice cream that cost `30.
Then they returned home.
How much money is left with each of
them now?
3. Group Activity Activity and Project
(a) Use some coloured marble papers and glue to make the patterns given below.
COMPUTER MASTI
14 You have to meet the following conditions while making these patterns –
i) You can use only rectangles and circles.
Activity and Project
ii) You have to arrange the papers one above the other to make the required
Class VII.indd 14 12-05-2022 17:34:37
pattern.
iii) Then, write programs to make similar patterns using BASIC-256.
ACTIVITY
1. Attempt the following:
(a) Run the following program and find out its display.
clg
circle 35,20,8
clg
circle 45,20,8
clg
circle 55,20,8
clg
circle 65,20,8
clg
circle 75,20,8
(b) Change the clg command to cls and then run the program. What do you observe?
(c) What will you do to make the object move along the Y-axis instead?
2. Savani, Ali and Asmit went for a picnic. Each one
carried `100 towards expenses. Write a program to
find the following. Include proper comments so that
others are able to understand your program.
(a) At the picnic they went on a ride. The cost of
each ticket was `30. Find the amount left with
each after the ride.
(b) Savani had an ice cream that cost `20,
Ali had orange juice that cost `25, and
Asmit had an ice cream that cost `30.
Then they returned home.
How much money is left with each of
them now?
3. Group Activity
(a) Use some coloured marble papers and glue to make the patterns given below.
You have to meet the following conditions while making these patterns –
i) You can use only rectangles and circles.
ii) You have to arrange the papers one above the other to make the required
pattern.
iii) Then, write programs to make similar patterns using BASIC-256.
Explore!
02_CBSE_CM_Level-6.indd
Class VII.indd 16 158 10/26/2017 5:36:35
12-05-2022 PM
17:34:37
NOTES