10th Class Comp SC Notes
10th Class Comp SC Notes
NOTES FOR
CLASS 10th
1
CHAPTER PAGE
Chapter 1 3
Programing
techniques
Chapter 2 10
Programming in
C
Chapter 3 Input 17
and Out put
handling
Chapter 4 26
Control Structure
UNIT #5 30
LOOP
STUCTURE
Chapter No.6 34
Logic Gates
Chapter 7: 36
World
wide Web
2
Chapter 1 Programing techniques
Q.No.2 Give short answers to the following questions
i: Define problem analysis?
Ans: Computer is not as much intelligent that it can solve the problem itself.
It is the human, The programmer who writes instruction to solve a particular
problem. To analysis the problem a programmer must know the causes. i.e.
what is the problem about?
How frequently it occurs?
When and where does it occurs?
Who is effected?
ii: How the solution of the problem is planned?
Ans: After analysis the problem is planned. There may be various solution for
a problem but the most effective solution will be cost effective, speedy and
less complex.
iii: Define candid solution of a problem?
Ans: There may be several alternative solution of a problem but the best
solution will be the candid solution of a problem. Selecting and adopting the
best possible solution is called candid solution of the problem.
iv: Define any three problem solving techniques?
Ans: (1)Analogy: Using a solution that solved an analogous problem.
(2) Divide and conquer: Breaking down a large, complex problem for which
solutions exist
(3) Trial-and-error: Testing possible solution until.
v: List various factor are importance for selecting the best solution of any
problem.
Ans: Following factors are importance for selecting of best solution of
problem.
1) Speed: To check whether the solution is the best one for its uses, Speed
is the major measure if selecting the best solution.
2) Cost: It includes space and other hardware and software environment.
A solution is said to be the best solution if it produces optimal desired result
with minimum cost.
3
3) Complicity: It means resources “time and space” required by the
solution of a problem.
Q3: Define an algorithm explain the role of algorithm in problem solving:
Ans: Algorithem: An algorithm is a well defined set of steps to solve particular
problem. It is a written in simple English language. It is used to solve daily life
problems for computer. It is rough work or plan for solving a problem.
Role of Algorithm: An algorithm makes easier to solve complex problem by
dividing it into series of steps e.g. to calculate the average of 20 number,
algorithm will be written as follows.
step1: Read 20 number
step2: Add these numbers
step3: Calculate average
step4: Print average
step5: Exit
4
the logic clear. The step are lined with the help of arrow lines which show
relation and flow of steps.
Symbols used in flowchart.
1) OVAL: It is used to show the start and end of a flowchart.
3) Process box: It is also called rectangle show the process in a flowchart. Here in
process box formula or expression is written or a variables is initialized.
5) Arrow: These are used to link different steps in flow chart and show the flow of
steps.
5
Example Flow Chart No 8
START
Input N, E
P=1 , K=1
P=P*N , K=K+1
IS K≤E YES
NO
Output P
STOP
6
Q6: Write an algorithm to calculate the factorial of given number and
draw flowchart for it.
Ans: Algorithm:
Step1: Read the number N.
Step2: Set factorial and K: F
F=1 and K=1
Step3: Repeat step 3 through step 5 until K<=N
Step4: F=F*N
Step5: K=K+1
START
Input N
F=N , K=1
F=F*K , K=K+1
IS K<N YES
NO
Output F
STOP
7
Step6: Print Factorial (F)
START
Input a,b,c
−𝑏 + √𝑏2 − 4𝑎𝑐
𝑥1 =
2𝑎
−𝑏 − √𝑏2 − 4𝑎𝑐
𝑥2 =
2𝑎
Output x1, x2
STOP
8
Q8: Write an algorithm and draw a flow chart to find average marks of
eight subjects for a student?
Ans: Algorithm:
Step1: Read the marks of eight subjects Step2: calculate the sum of eight subjects
Step3: Avg=sum/ 8
Step4: print Avg
Step5: stop
Flowchart
Start
Avg=sum/subjects
Display Average
Stop
9
Chapter 2 Programming in C
Q2: Give short answers to the following questions:
I. Different between program syntax and programming semantic.
Ans:
ii. Different between Low Level Language (LLL) and High Level Language
(HLL)?
Ans:
10
once and can be used again and again. It is a modern and easy way to write a
program. Example are C++ and JAVA.
The programming technique in which objects and classes are used is called object oriented
programing.
Compiler Interpreter
It is a translation software used to translate It is also a translation software used to
high level language source program into translate high level language program into
machine language object program. It machine language but line by line. Example:
translates the over all program at one time. Basic, Visual Basic
Examples of languages using compiler are C,
C++ etc
11
ix. What are reserved words?
Ans: These are also called keywords. They have special meaning to compiler.
e.g. int, float, if, else, switch are reserved words. If we write int as INT, it will
generate an error other keywords are given as under case, include, getch,
clrscr, while, continue, do, break etc.
So reserved word is defined as “The word which are already created and
defined inside a language translator are called reserved words.
Reserved words can not be used as variable names.
x. writer rules for variable name ?
12
1. LOW LEVEL LANGUAGE
2. HIGH LEVEL LANGUAGE
There are two types of Low Level Language.
i. Machine Language
ii. Assembly Language
13
v. JAVA Language: JAVA is an object oriented programming language
developed by Sum microsystem in early 1991. It is very similar to C++
language used to design web pages, JAVA applet is as JAVA program
that is run inside another program e.g. web browser. applets are used
to rotate languages for animation and used to access online data
bases.
Q5: What is the basic structure of C Program? Also explain different types of
preprocessor directives?
14
Q6: WHAT ARE CONSTANT AND VARIABLES? DIFFERENT THEM WITH EXAMPLE.
Ans:
Constant:
i. Constant is a quantity which does not change during execution of program.
ii. Constant is the value that is stored in location i.e. variable.
iii. Constant are of two main types. (1) Numeric Constant (2) Character Constant
iv. Example of numeric constant are 2,3,5,65.
v. Example of character constant are ‘a’, ‘t’, ‘I’, ‘q’, “Tank” etc
Variable:
i. Variable is a quantity whose value many changes during execution of a program.
ii. A variable represent the memory location in the computer memory.
iii. There are two main types of variable (1) Numeric Variable (2) Character Variable
iv. Example of Numeric variables are Roll No., Marks, Percentage.
v. Example of Character variable are name, father name, address.Q7:
Explain different data types used in C Language with example.
Ans: There are three(3) main data types in C Language
i) int
ii) float
iii) char
int (int, long):
Int stands for integer having no decimal point. It takes two bytes
in computer memory range of int is -32768 to +32767.Long is another use of
integer data having range of -2,147,480,648 to +2,147,480,647. It takes a bytes
in computer memory syntax int variable.
Float:
15
Syntax: char ch;
Q8: What is type casting? Explain with example.
Ans: The casting is the process of converting one data type into another.
There are two types of type casting.
1) Implicit Type Casting
2) Explicit Type Casting
Implicit type casting is done by compiler automatically e.g. If a user declare a
statement as c=a+b; where the type of a is int where b is long. Compiler will
automatically convert type int to long.
Explicit type casting is done on the part of programmer e.g. if user declares a
statement as n=10.1; and y=5.3; then n%y shows an error massage. Then
programmer uses cast operator to convert. The type float into int as follows
Int (n) % int(y)
‘n’ will be converted to 10 and y to 5 and the result will be 0;
Q9: How variables are declared and initialized in C language give example.
Ans: Variable Declaration:
17
Where string is a string constant or variable
LONG QUESTIONs
Q3: What are operators? Explain different types of operators with
examples?
18
Ans: Operator:
Operators are special symbols used to perform an operation
on operands for example x+y is an expression, where x and y are operands and
+ is an operator.
Types of operator:
i. Arithmetic Operator:
These operator perform arithmetic operation like +, -, *, /, %.
Here:
OPERATION OPERATOR DESCRIPTION
Addition + Adds the values
Subtraction - Subtract one value from other value
Multiplication * Multiply two values
Division / Divide one value by another value and returns the quotient
Modulus % Modulus is used for remainder division
v. Logical Operator:
These operators are used to evaluate compound condition or relational operators.
&&, ||, ! are logical operators:
Example:
if((a>b)&&(a<c))
The result will be true if both the conditions are true.
If((a>b)||(a>c))
The result will be false if both the condition will false.
if!(a>b)
The result will be true if condition will be false and false if condition will true.
vi. Increment Operator:++
19
Increment Operator is used to add 1 to the value of variable. There are two modes in
which increment operator is used.
a. Prefix Increment Operator: Prefix increment operator is used to add 1 to
the value of a variable before it is used in an expression.
b. Postfix Increment Operator: Postfix increment operator is used to add 1 to
the value of variable after it is used in an expression
vii. Decrement Operator:
The decrement operator is represented by a double minus (--) sign. It is used to
subtract 1 from the value of an integer variable. The decrement statement is written
as.
x--; OR --x;
a. Prefix Decrement Operator: When a decrement operator is used in prefix
mode in an expression, it subtracts 1 from the value of the variable before
the value of the variable is used in an expression.Sum = a+b+--c;
b. Postfix Decrement Operator:When a decrement operator is used in postfix
mode in an expression, it subtracts 1 from the variable after the value of the
variable has been used in an expression.
For Example: Sum = a+b+c--;
viii. Conditional Operator:
It is an alternate of if-else structure. It is the combination of ? and :
It is also called Ternary Operator.
c. Syntax:
(condition) ? true-case : false-case;
Example: (a>b) ? printf(“a is greater”) : printf(“b is greater”);
Syntax;
printf(“escape_sequence/format_specifier/strings”,variables);
OR
20
Example: printf(“I love programming”);
printf(“The result is %d”,sum);
printf(“product of 2 numbers = %d”,a*b);
ii. Puts() function:
Puts() function is used to print a string on the screen.
Syntax: puts(string);//where string may be a string constant or string variable.
Example: puts(“My passion is programming”);
NOTE: <string.h> is the header file used with puts() function
iii. Cout<<:
It is an object of C++. It is an output function used to print string, variableor
expression on default output device (monitor). It is used with insertion operators
<<
Syntax: cout<<variable<<”string”<<expression;
Example: cout<<”I love Pakistan”;
Cout<<”The sum of a and b =”<<a+b;
I) scanf()
It is an input function of C language used to read value of
variable. i.e. numeric or character from keyboard and assign it to
variable. This function waits till the user input value from keyboard.
Syntax:
Scanf(“format_specifier”,&variable1,&variable2…….&variablen);
Example:
Scanf(“%d%d”,&a,&b);
II) getchar()
It is an input function used to read a single character from keyboard
with echo. It needs an enter after inputting a character.
Syntax:
getchar();
III) cin>>
++
It is an input function of C language used to take the value of
variable. It is also aC++ object.It is used with extraction operators >>
Syntax:
Cin>>var1>>var2>>var3;
Example:
Cin>>a>>length>>width;
Q7: Write a program that reads three number and prints their sum,
product and average.
Ans:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,sum,pro;
float avg;
22
printf(“Enter value of a,b and c \n”);
scanf(“%d %d %d”,&a,&b,&c);
sum=a+b+c;
pro=a*b*c;
avg=sum/3;
printf(“The sum = %d \n”,sum);
printf(“The product = %d \n”,pro);
printf(“The average = %f \n”,avg);
getch();
Q8: Write a program that reads the base and height of a triangle and prints
its area.
Ans #include<stdio.h>
#include<conio.h>
void mani()
{
Float b,h,area;
clrscr();
printf(“Enter the base and height of triangle \n”);
scanf(“&f %f” ,&b,&h);
area=(b*h)/2;
printf(“The area of the triangle is %f”,area);
getch();
}
23
float fah,cal;
clrscr();
Q10: Write a program that reads name and address of a student and prints it
on the screen using gets() and puts() function.
Ans: #include<stdio.h>
#inlcude<conio.h>
#inlcude<string.h>
void main()
{
char name[20],address[30];
printf(“Enter your name please: \t”);
gets(name);
24
Sample OUTPUT
Enter your name please Muhammad
Enter your address Dera Ismail Khan
Muhammad
25
Chapter 4 Control Structure
Q2: Write a C-Program to input three integers. Find out the largest among
these integer using if-else structure and print on the screen.
Ans: #include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;
1
The largest value is 9.
26
Q3: Write a program in C to input a single character and print a massage “it
is a vowel” or “it is a consonant”. Using if-else statement.
Ans: #include<stdio.h>
#inlcude<conio.h>
void main()
{
char ch;
clrscr();
printf(“Enter any character \n”);
scanf(“%c”,&ch);
if(ch==’a’||ch==’A’|| ch==’e’||ch==’E’|| ch==’i’||ch==’I’|| ch==’o’||ch==’O’||
ch==’u’||ch==’U’)
{
char ch;
printf(“Enter any character \n”);
scanf(“%c”,&ch);
printf(“Enter any character \n”);
27
switch(ch)
{
case ‘A’:
case ‘a’:
case ‘E’:
case ‘e’:
case ‘I’:
case ‘i’:
case ‘O’:
case ‘o’:
case ‘U’:
case ‘u’:
getch();
}
SAMPLE OUTPUT
Enter any character
M
The character M is a consonant
28
c=13
if((a==b)&&(a>c))
printf(“Condition is True \n”);
else
{
printf(“a is equal to b \n”);
printf(“a is not greater than c \n”);
}
}
Ans: OUTPUT
a is equal to b
29
UNIT #5 LOOP STUCTURE
Q2: Explain different types of looping structures with example.
Ans: There are three types of looping statements in C-Language
1. For LOOP
2. While Loop
3. Do-While Loop
For Loop:
It is a type of loop structure which is used to repeat a statement or a set
of statement for known number of times. It is used in a situation where we
already know how many time we want to repeat a statement or a set of
statements.
Syntax:
For(initialization; condition; increment/decrement)
{
Body of the loop;
}
Example:
#include<stdio.h>
#include<conio.h> OUTPUT
void main()
1 2 3 4 5 6 7 8 9 10
{
int x;
clrscr();
for(x=1;x<=10;x++)
printf(“%d \t”,x);
getch();
}
While Loop
It is a type of loop used to repeat statement(s) for a number of times
until the given condition remains true. It is used in a situation when we don’t
know in advance how many times the loop will be executed.
Syntax:
While(condition)
{
Body of the while;
}
30
Example:
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
n=1; OUTPUT
Pakistan
while(n<=5) Pakistan
{ Pakistan
Pakistan
printf(“Pakistan \n”); Pakistan
n++;
}
getch();
}
Do While Loop:
Do-while loop is used to repeat a statement or set of statements until
condition remains true. In this loop body of the loop occurs before condition.
So body of the loop executed one time even if the condition becomes false at
the very first time.
Syntax:
do
{
statement(s);
increment/decrement;
}
while(condition);
Example:
a=0;
do
{
printf(“%d”,a);
a=a+1;
}
while(a<0);
31
Q3: Differentiate between the do-while and while loops. Explain with
program example.
Perimeter while loop do-while loop
Checking It first needs to check the The execution of
of condition, and only then can we statement(s) occurs at least
Condition execute the statement(s). once. After that, the
checking of the condition
occurs.
Semicolon while(condition) while(condition);
No semicolon is present at the A semicolon is present at the
end ofthe while loop. end of the do-while loop.
Do While Loop:
Example:
a=0;
32
do
{
printf(“%d”,a);
a=a+1;
}
while(a<0);
Q4: write a program in C to calculate and print the product of the even
numbers from 1 to 100 by using the while loop.
Ans : #include<stdio.h>
#include<conio.h>
void main()
{
int n, pro;
Pro=1;
While(n<=100)
{
//Here is the condition to check Even number
if(n%2 == 0)
printf(" %d ",n);
pro=pro*n;
}
Printf(“\n Product = %d” ,pro);
getch();
}
33
Chapter No.6
Logic Gates
Q2. How data is represented in computer?
Ans : Data is represented in computer in the form of binary digits 0 and 1 .
Computer can only understand the language of 0 and 1. When we enter data in any of the
form i.e text , pictures, audio or video all the data is converted into machine language
before processing by the CPU.
eg when we type A it is converted into binary form 100001.
Q.N3. What are the three basic logic gates Describe in detail with Function and diagram
and Truth table ?
Diagram a
B F=a.b
2) OR Gate : It is that type of logic gate which performs logical addition on input
signals . It takes two or more input signals and produces only one output signal.
Output will be 0 if all the inputs are 0 otherwise output will be 1 if any of the
input is 1.
It can be represented mathematically as
F= a+b ( For two input signals)
Input Output
x y F=x+y
0 0 0
0 1 1
1 0 1
1 1 1
Diagram
F=x+y
34
Not gate : It is also called inverter gate it is used to convert high voltage to low
voltage ie if input signal is x then not gate will change it into .
Diagrammatically it is shown as
X O
Input x Output
0 1
1 0
35
Chapter 7: World wide Web
Q: Define www?
Ans: World wide web is an information system on the Internet allow the
document to the connected to other document by hyperlinks, enabling the
user to search information by moving from one document to another
document on the Internet. Created in Hypertext Markup Language, HTML.
HTML is the main language to develop these document for (www).
Q: Define Web Page?
Ans: Web page is a document on Internet that can be accessed through a web browser
every document has its own unique web address called URL.
Web page contains text, image, sound, graphics and video clips all at one place.
Q: Define Website?
Ans: Web site is a collection of related web page, hosted on a web server. It is accessed
through web address or URL e.g. www.khyberphkhtunkhwa.gov.pk
Q. Define URL?
Ans. URL means unique address for a file accessible on internet by URL a
web page can be accessed by writing it on address bar of browser general
formal of URL is :Protocol://hostname / other information.
Example: http://www.disep.com.pk /main.
Have http mean hyper text transfer protocol specifies how the information
from the likes is the domain name computer where resource is located.
36
Q . Define Search Engine?
Ans. To find information on internet search engine is used which is a Software. It is an
application which is used help users to find information on web. Finding exact information
on web is not an easy task therefore user just type keyword in search engine it displays a
list of websites with a title and a description user just click on a website that he/she wants
to open.
Example of search engine are Google and yahoo.
Ans. Website.
A website is a collection of related web pages hosted on a web
server. It is accessible through an Internet address know as URL. For example a websites.
“ WWW. Khyberpakhtunkhwa.gor.pk
There are different types of website on the internet. Each websites is providing
information about different topic, some are used for on net page.
i) Web portals.
These web portals provide different types of services and a point of
access to information on web the services provided on these website are online
shopping , news , stock prices, email and search engine etc, for example a web
portals of a university may contain information about background, admissions,
fee Structure , facilities, curriculum ,, programs etc. www.aiou.edu.pk is web
portal of Allama Iqbal open university
ii) News website.
News websites provide information about current events and
opinions these sites provide allow the user or visitors to provide their views
and feed back about the current affairs, some example of these website are
www.urdupaint.com , e.jang.com.pk , marsitriq.com.pk ETC.
iii) Information websites.
Informational websites provide information on any topic in the form
of text, graphics, sound and videos. sometimes these websites also provide a
facility to edit articles.
iv) Educational website.
This website is created for educational purposes Such websites are organized to
impart knowledge about any topic and to educate people. These website contain animations,
slide presentations , audio video lecture and tutorials about certain topic some examples are
www.educationworld.com , www.ilmkidunya.com and www.knowledgepk.com etc.\
v) Personal website
The website is created and maintained by individuals for their personal use. A
person can Provide some information about this interests, hobbies, quantification,
publication etc. person website individual can share personal information to family and
37
friends on a personal website. These websites are open to all the visitors and people can
access it anywhere any time
38
Q.4. Create a web page in HTML that displays image of a printer the Width of
image of should be 250 pined and night is 150 pined.
Ans.
<html>
<head>
<title> image of printer </title>
</head>
<body>
<img src=”printe.jpg” width=250 height= 150 alt =”image of a printer”>
</body>
</html>
Output is
Q.5. Describe how background color and image are applied for web page.
Ans.
39
<html>
<head>
<title>background image</title>
</head>
<body background= “image.jpg”>
This image will show in the body of the page
</body>
</html>
…………………………..
<html>
<head>
<title> link tag</title>
</head>
<body>
<a href= “Http” // www.aust.edu.pk><image src =”logoaust.jpg”></a>
<br>
click on fine image to visit the site of abbottabad university website
</body>
</html>
Q.7. Create a web page in html that contain unordered and ordered lists.
Ans.
<html>
<head>
<title>
Creating unordered list </title>
<head>
<body>
<h3> types of Computer Lagnuages <h3>
<ol>
<li> low level language </li>
40
<ul>
<li> machine language</li>
<li> Assembly language
</ul>
<li> High level language </li>
<ul>
<li> FORTRAN </li>
<li> c/c++</li>
<li> java </li>
</ul>
</ol>
</body>
</html>
<head>
<title>
hyperlink to three websites
</title>
</head>
<body>
<a href= “Http // www.bisep.edu.pk”> BISE Peshawar </a>
</body>
</html>
42
<td>Urdu</td>
<td>CS</td>
<td>Islamiat</td>
<td>CHD</td>
</tr>….. and so on
</body>
</html>
The End
43