You are on page 1of 87
Computer Science Notes For Class X Qu: Ans: Ans: E Chapter #1 Write all the problem solving techniques. Following are the main problem solving techniques. 1. Abstraction: solving the problem in a model of the system before applying it to the real system is called abstraction. 2. Divide and conquer: Breaking down a large and complex prablem into small and solvable problem is called Divide and Conquer. 3. Reduction: Transforming the problem into another problem for which solutions exist is called Reduction. 4. Analogy: Using a solution that solved a similar problem. 5. Brainstorming: Suggestion large number of solutions and developing them until an ‘optimal solution is found. Research: Employing existing ideas or adopting existing solution to similar problems. Trial and Error: Testing possible solution until the right one is found. Write the important factors for selecting the best solution. The following factors are very important in selecting the best solution of any problem. 1. Speed To develop an efficient solution for solving the problems, the time it uses is the major measure of the efficiency of that solution. 2. Cost Cost of a solution includes space and other hardware and software requirements. The solution will be considered to the best one if it gives optimal desired result with minimum cost. 3. Complexity Complexity of the solution means the resources required by the solution, most commonly known as the time — how many steps it needs and the space ~ how much memory it takes. What is Algorithm? Write the role of algorithm in problem solving. Algorithm: Algorithm is a well-defined list of steps for solving a particular problem. An algorithm is a sequence of computational steps that transform the input into the ‘output. Algorithm is a tool for solving well-specified computational problems. By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 1 Computer Science Notes For Class X Qu: Ans: Ans: E Chapter #1 Write all the problem solving techniques. Following are the main problem solving techniques. 1. Abstraction: solving the problem in a model of the system before applying it to the real system is called abstraction. 2. Divide and conquer: Breaking down a large and complex prablem into small and solvable problem is called Divide and Conquer. 3. Reduction: Transforming the problem into another problem for which solutions exist is called Reduction. 4. Analogy: Using a solution that solved a similar problem. 5. Brainstorming: Suggestion large number of solutions and developing them until an ‘optimal solution is found. Research: Employing existing ideas or adopting existing solution to similar problems. Trial and Error: Testing possible solution until the right one is found. Write the important factors for selecting the best solution. The following factors are very important in selecting the best solution of any problem. 1. Speed To develop an efficient solution for solving the problems, the time it uses is the major measure of the efficiency of that solution. 2. Cost Cost of a solution includes space and other hardware and software requirements. The solution will be considered to the best one if it gives optimal desired result with minimum cost. 3. Complexity Complexity of the solution means the resources required by the solution, most commonly known as the time — how many steps it needs and the space ~ how much memory it takes. What is Algorithm? Write the role of algorithm in problem solving. Algorithm: Algorithm is a well-defined list of steps for solving a particular problem. An algorithm is a sequence of computational steps that transform the input into the ‘output. Algorithm is a tool for solving well-specified computational problems. By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 1 Computer Science Notes For Class X Role of Algorithm in problem solving: Algorithm plays an important role in developing solution to a problem. For example, If we have a complex situation which requires a lot of information to be gathered and a lot of data to be processed. Then by dividing each activity of this information gathering and data processing into steps will make the problem solving an easy task. “Divide and Conquer” a very famous rule that takes the problem solving an easy task.For instance let we take an example of finding the average of 20 numbers. If this process is defined in small discrete steps then we can make the solution very easily. 1. Select any 20 numbers 2. Add all the numbers 3. Divide the result of step 2 by total no of observation i.e., 20 4. The average will be calculated Q4: Write the criteria for measuring efficiency of an Algorithm. Ans: Efficiency af an algorithm is measured on the basis of speed and space, furthermore its efficiency can also be measured on the basis of the following factors. A. Inputs needed: The amount of time an algorithm takes depends on how large is the Input on which the algorithm must operate. For example, multiplying huge matrices takes longer than multiplying small ones, etc. B. Processing to be completed The time required to complete the operation is a measure for efficiency of an algorithm. C. Decision to be taken Problem solving and decision-making are important skills to imprave the efficiency of an algorithm and get optimal result. D. Outputs to be provided An algorithm is said to be correct if, for every input instance, if ends with the correct ‘output. The algorithmic solution that provides correct desired output will be considered as the best solution for the problem to be solved. Problem 1 To find the sum, product and average of five given numbers. Algorithm: Given five numbers ni, n2, n3, n4 and nS. This algorithm finds sam SUM, product PRO and average AVG of these numbers. Step 1. Read nl, n2, n3, 4, nS bess By: Muhammad Suleman Me Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 2 Computer Science Notes For Class X Step 2. Set SUM =nl+n2+n34n44n5 Step 3. Set PRO =nl *n2#n3*n4*n5. Step 4. Set AVG =SUM/5 Step 5. Write SUM, PRO, AVG Step 6. Exit Problem 2 To display the larger one out of the three given unequal numbers. Algorithm: Given three unequal numbers ni, n2 and n3. This algorithm finds the largest LARG number out of the three numbers. Step 1. Read nl, 2, n3 | Step 2. If nl>n2 AND nl>n3 then Set LARG=n1 Else if n2>n3 then Set LARG=n2 Else Set LARG=n3 i [End of If structure] » Step 3. Write LARG ~ Step 4. Exit | Problem 3 | ‘To find acceleration of a moving object with given mass and the | By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 3 Computer Science Notes For Class X 8 EE UNITE: PROGRAMMING "EM a m finds acceleration ACCE the force FORCE applied. L of a moving object Algorithm: This algort with given mass MASS and step1. Read MASS, FORCE Step 2. Set ACCEL= FORCE / MASS Step 3. Write ACCEL, Step4. Exit | Problem 4 To find the volume of a cube, cylinder or sphere. Algorithm: This algorithm finds the volume of a cube VC of edge length A and volume of a sphere VS of radius R. : Step 1. Read A,R. Step 2. Set VC= AtAtA | Step 3, Step 4. VS= 4/3 * 3.14*R*RAR Write Vc, vs Exit : This algorithm finds the F the base of the Wiangle area AREA of a tiangle Whete B is and H is ‘ight or © Of the id HT is the he ht or a titud f thi By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahagi Peshawar Page 4 Computer Science Notes For Class X Step I. Read B, H Step 2. Set AREA= B*H/2 f Step 3. Write AREA Step 4. Exit Problem 6 To find the area of a parallelogram. Algorithm: This algorithm finds the area AP of a parallelogram: having base B and height H. Step 1. Read B, H Step 2. Set P= B*H Step 3. Write AP | Step 4. Exit | _ Problem 7 To find the area of a rhombus or trapezium. Algorithm: This algorithm finds the area ATRAP of a trapezium having A isa F and B are the lengths of the parallel sides, and H is the height (the | Perpendicular distance between these sides.) By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 5 | Step 2- | Step 3. seep 4. Problem § : | Toassgn grade toa subject based on the achieved | Algorithm: This algorithm assigns Computer Science Notes For Class X 2 UD yy get ATRAP =a x write ATRAP Exit marks, grade GRADE to a subject based on the | achieved marks SUBMARKS. | Step}. Read SUBMARKS Step2. If SUBMARKS>=80 Set GRADE= A+ Else if SUBMARKS>=70 Set GRADE= A Else if SUBMARKS>=60 Set GRADE= B Else if SUBMARKS>=50 Set GRADE=C Else if SUBMARKS3=40 Set GRADE= D Ele if SUBMARKS>=33 Set GRADE= f Else Set GRADE=FAIL (End of If structure] 5 Write GRADE By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 6 Computer Science Notes For Class X EF mo Yo find the interest on an amount. Algorithea: ‘This algorithm finds the amount of interest J where principal amount is P the rate is R and the time is T. gwepl. — Read PLR, T | Swp 2. Set l= P*R*T sep. Writel Step 4. Exit | Problem 10 | To calculate the exponent of a given number. Algorithm: This algorithm calculates exponential power EXP of a given” number NUM having exponent X. Step i. Read NUM, X Step 2. Set EXP= NUM * X (4 Carrot is used for power) Step 3. Write EXP i Step 4. Exit = Problem 11 To find a sequence of odd numbers starting from a given number. Algorithm: This algorithm finds a sequence SEQ of odd numbers starting | By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 7 Computer Science Notes For Class X SS ————— ‘sep |. Read NUM, N Repeat Steps 3 and 4 while NUM<=N : Step 3. Write NUM E Step4. SetNUM=NUM+2 [End of while loop) | Swps. Exit 2 count multiples MUL of a given number lying between two | Algorithm: This algorithm counts multiples M of a given number NUM lying between two numbers NI and N2, where N2 is greater than NI. | Stepl. Read NUM, Ni, N2 Sep2, ” SetM=0 [Initialize Mt] | For A=N1 to N2 Set MUL= NUM % 4 NMUL = 0 Then Meaty Next A Write M By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahagi Peshawar Page 8 Computer Science Notes For Class X Ea : . produce a multiplication table TAB for a given number. Algorithm: This algorithm produces a multiplication table TAB for a given | umber NUM. Step |. Set C=1 [Initialize counter.] Step 2. Read NUM |Step3. Repeat Steps 4,5 and 6 while C<=10 | Step 4. Set TAB= NUM*C Step 5. Write NUM ‘*’ C ‘=’ TAB Step 6. C=C+1 [Increment counter variable.) [End of while loop] Step 7. Exit : This algorithm converts Celsius C to Fahrenheit F temperature. Read C Set F= 32+C*9/5 Write F Exit By: Muhammad Suleman MSe Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 9 Computer Science Notes For Class X =F ee Fahrenheit to Celsius temperature. Algorithm: This algorithm converts Fahrenheit F to Celsius C temperature Step I. Read F Step 2. Set C= (F-32)*5/9 Step 3. Write C Step 4, Exit Problem 16 Find even numbers in integers ranging from nl to n2. (Whe is less than n2 and 1 is an even number). : ae “eal This algorithm finds even numbers EVEN in integers tanging mn! ton2 (Where al is less than n2 and nl is an even number), Step 1. Read nl, n2 | Step2, Ser EVENsal Step 3, Repeat Steps 4 and 5 while EVENc= n2 Write EVEN 5 "ep5. Se EVEN=EVEN #2 F [End of while loop} By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 10 Computer Science Notes For Class X list L3{n]. I Sept. Read Lifa}, L2{n) x Step 2. Set I=! [Initialize counter. : Step 3. Repeat Steps 4 and 5 while I<= n 3 Step 4. Set L3QSLim+L2[1) i ; Step 6. Set I=I41 [Increment counter.] : [End of while loop) "Sep 6 Exit m 18 | te GCD of given two numbers. ithm: This algorithm calculates GCD of given two numbers m and a. 1 Read m,n | ’ | If n=0, Go to Step 5; otherwise, Proceed to Step 3 | Divide m by n and assign the value of the remainder tor 1 Assign the value of n to m and the value of r to n and go to Step2 . Write m By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahagi Peshawar Page 11 Computer Science Notes For Class X ——_—— I per or not. | Problem 19 umber is prime nui : | Determine whether a given umber NUM is iven 1 | algorithm: This algorithm determine whether a give! | prime number or not. | Step |. Read NUM | Step 2. Set i=2 [Initialize counter] | Step 3. Repeat steps 4 and 5 while i¢=NUM-1 “Step 4. IF NUM%i=0 Then Write ‘Not a prime number’ and go to Step 7 Step 5. Set i=i+! [Increment counter.] [End of while loop] Step 6. Ifi=NUM, Then Write ‘Prime number’ _ Step 7. Exit + Problem 20 pecipens ane integers ranging from nl to n2 rg algorithm determine Prime numbers between nl and n2 | Stepl. Read ni, ng Set n=n2+1 By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 12, Computer Science Notes For Class X [sep 4. Repeat Step 5 for i=2 to n-1. f Step 5. If n%i=O Then Set n=n+1 Go to Step 3 i Else - | (a)Write n @®) Set nin+1 Step 6. Exit Ans: Ans: What is Flowchart? Discuss the importance of flow chart for problem solving. Flowchart : Flowchart is a diagrammatic or symbolic representation of algorithm. Flowchart is a type of diagram representing a process using different symbols containing information about steps or a sequence of events in a problem. Importance of a flowchart for solving a problem: Flowcharts are commonly used in developing business plans, designing algorithms and determining troubleshooting steps. For solving a problem flowcharts are important for: It helps the viewer to understand a process. Showing the required input and output. Understanding of relationship among different process steps. Helping with decision making. Tracking the process flow. Highlighting important steps and eliminating the unnecessary steps. Write Flowchart requirements in detail. Requirements of flow chart are given below. Input needed: Input is anything which is required for the processing. The flowchart developer must know what exactly the input is. The input is determined from the problem statement. Processing to be completed: In flowchart, the process is, to resolve any formula or expression or initialize any value in a variable. The flowchart developer must decide what type of calculation is to be performed or which formula is to be applied to obtain the required result. Decisions to be taken: In flowchart, the decision is either taking action when the expression is true of false. For example, finding the result of a student, decision is required to be taken on passing marks. SS — a—wm—q—a—=—=—=—=—=—=—=—_—_—_—_—,—,—04S. By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 13, Computer Science Notes For Class X Output to be provided Output is the result. The flowchart must provide the required output in the end. Q6:; Write the Flowchart Symbols in detail. ‘Ans: The following are some important flowchart symbols. 1. Ovat: it Represents a Start and an End of a flowchart 2. Arrow lines: It is used to show the flow of control from one step to the other. They also indicate progress from one step to another. — . Paralletogram: It is used to represent input/output. Z__/ 4. Rectangle: It represents a process activity ar step. » 5. Diamond: It is used when there is a decision to be made.or question ta be answered, such as Yes/No or True/False. Kes aS ——_—_—_—_—— 3y: Muharnmad Suleman M.Sc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 14 . 3: To find acceleration of a moving object given mass the force applied. _,.- INPUT FORCE, MASS Eso ote Span Sg ACCELERATION=FORCE) MASS Sea OUTPUT ACCELERATION ies ry ‘Volume. By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 15 Computer Science Notes For Class X [UNIT L: PRD Hvarenrerrrn om a - ; 7 Flowchart 5: To find the area of @ triangle when the gth: height and base are giyen. Flowchart 6: To read marks (M) and print letter grade acco) to the following scheme. oe I | ee Letter Grade M280 and M100 aria F M270 and M<80 B | M260 and M<70 c M250 and M<60 D F Pit Sitti By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 16 Computer Science Notes For Class X By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 17, Computer Science Notes For Class X . Flowchart 8: Ta find the exponent (E) of a given number (N). Flowchart 9: To print odd numbers from 1 to 100. i = By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 18 Computer Science Notes For Class X ———__ from 1 to 50. To find the sum of even numbers “ine SUNN 4 SUM=SUM#K Keke2 = 7 11: To convert temperature from Fahrenheit to By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 19 Computer Science Notes For Class X Flowchart 12: To find factorial of a number. Exercise: Short Questions: Qi. Define problem analysis. Ans: Problem analysis is defined as thoroughly studying a problem with the objective to understand that why the problem has emerged and how it has reached the current state. Problem analysis points and leads the way to the roat causes of a problem. Q2: How the solution of problem is planed? Ans: After analysis the solution of the problem is planned. There can be many solutions to a problem but the proposed solution should be cost-effective, time effective, speedy and less complex. In order to Q3: Define Candid solution for a problem. By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 20 Computer Science Notes For Class X Ans: Candid is solution is the best solution to solve a problem. There should be many solutions for solving a problem, but selecting the best and most suited solution is called Candid solution. Q4: Define any three problem solving techniques. Ans: Following are the three useful problem solving methods. 1 Abstraction: solving the problem in a model of the system before applying it to the real system is called abstraction. 2. Divide and conquer: Breaking down a large and complex problem into small and solvable problem is called Divide and Conquer. Redu Transforming the problem into another problem for which solutions exist is called Reduction. Q5: List various factors for selecting the best solution of any problem. Ans: 4. Speed: In solving problems, the speed is the one of the majar factor. 2. Cost: Cost includes space and other hardware and software requirement. 2. Complexity: Complexity of the solution means the resources required by the solution such as time and memory. Note: For Long questions No 3,4 and 5 see the topic wise questions. Q6: Write an algorithm to calculate the factorial of a given number and draw the flow chart for it. Ans: This algorithm will find the factorial FACT of a number N. J sours / Step1. Read N Step2. Set FACT=1,l=1 SET 7 Step3. Repeat step4 and 5 until |<=N SET FACT=FACT?| Stepd. FACT=FACT*! = ca 4 StepS. I=1+1. [end of step 3] < Step6. Display FACT No, By: Muhammad Suleman M.Se Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 21 Computer Science Notes For Class X Q8: Write an algorithm and draw flow chart to find the average marks of eight subjects for a student Ans: This algorithm will find average marks AVGM of eight stud Step1. Read m1,m2,m3,m4,m5,m6,m7,m& se 2,8 mf Step2. Set SUM= m1+m2+m3+m4+m5+m6+m7+m8 + Step3. Set AVGM Set SUM: UT en 2. 6, Step4. Write AVGM SET AVGM=SUM/8 step5. Exit By: Muhammad Suleman M.Sc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 22 Computer Science Notes For Class X Ans: Ans: Ans: Chapter #2 Exercise Short Question: Differentiate between Program Syntax and Program Semantic. Program Syntax: Syntax refers to the rules of a programming language according to which statement of a program are to be written. It describes the way to write correct statement in a program. Syntax of a programming language is similar to the grammar of natural language. For example, in C language the output is presented using printf() statement, whose syntax is Printf("%6d", a); Proaram Semantic: Semantic describes meaning of statement of a programming language. For example, the following statement of a C program will multiply two variables x and y and store the result in variable product. Product=x*y; Differentiate between low level and high ievel languages. Low level lanquages: These languages are near to computer hardware. Computer can understand these languages easily. Writing a program in low level languages requires a deep knowledge of the internal structure of computer hardware. High tevet lanquages: High level languages are English-oriented languages. The program instruction is written using English words, e.g., print, input etc. There are different types of high level languages each having its own rules or grammar for waiting programs.The program written in high-level language must be translated to machine code before executed by the computer. Each high-level language has its own translator program. Some example of high level language is C, Java and Pascal. What is IDE (integrated Development Environments}? Integrated Development Environment (IDE) is the programming language development tool to create, compile and run programs. IDE is computer software that brings all the processes and tools required for program development into one environment. C language also uses IDE. What is OOP (Object Oriented Programming)? In object oriented programming, the program is developed by using a set of objects. An object is a modern and easy technique to design the program. Once an object for any program is designed, it can be re-used in any other program. Some popular and commonly used object oriented programming (OOP) languages are C++ andl JAVA. By: Muhammad Suleman. M.Sc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 23 Computer Science Notes For Class X Q5: Whot are the Characteristic of high Level Languages? ‘Ans: The following are same common characteristic of High level Language. Easy to Learn: The high-level languages are easier to learn than low-level languages. The statement written for the program is similar to English like statements. Easy to Understand: The program written in high-level language by one programmer can easily be understood by another programmer because the program instructions are similar to the English language. Easy to Write Program: In high-level language, a new program can easily be written in a very short time. The larger and complicated software can be developed in few days or months. Easy to Detect & Remove Errors: The errors in a program can be easily detected and removed. Mostly the errors are occurred during the compilation of new program. Built-in Library Functions: Each high-level language provides a large number of built-in functions or procedure that can be used to perform specific tasks during designing of new program. Machine independence: Program wi program wi computer. fen in high-level language is machine independent. It means that a en on one type of computer can be executed on another type of Q6: Differentiate between compiler and interpreter? Compi Compiler is systern software that translates (compiles) high level language source code into machine-language object code. It translates the whole program into machine language and then executes it. Compiler is the most suited translator for lengthy programs. Programming language like C/C++, Pascal and JAVA use compiler. Interprete: Interpreter is a high-level programming language translator that translates/ compiles and executes the program statement by statement. It converts one program statement into machine language, executes it, and then proceeds to the next statement. Examples By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 24 Computer Science Notes For Class X ES of programming language that use interpreter are Java Script, BASIC and Visual basic ete. Q7: What is Header File? Ans: Header files are collection of standard library functions to perform different tasks. There are many header files for different purpose. Each header file contains different types of predefined functions. Many header files can be included in one program. The header file must be included in the program before calling any of its functions in the program. The extension of a heard file is .h.For example # include “stdio.h” or # include Q8: Differentiate between source program and object program. Ans: The source program is the code written in any programming language. While when the source program is compiled by the compiler then it becomes an object program. The extension of source program is . or cpp while the extension of the object program is obj Q9: What are reserved words? ‘Ans: The words that are used by the language for special purpose are called reserved words. These are also called keywords. Each keyword has fixed meaning and that cannot be changed by user. For example int to declare an integer type variable. Al these words are reserved words of C. The reserved words cannot be used as variable names ina program. Examples of reserved words are int, float,for etc. Q10 Write rules for writing variables name. ‘Ans: Any variable declared in aC program should confirm to the following rules: 1. They must always begin with a letter, although some systems permit underscore as the first character. The length of a variable name depends upon the compiler of C. Blank space is not allowed. A variable should not be a Keyword. It should not contain any special characters like, #, * etc. A variable name declared for one data-type cannot be used for a different data-type. a Pw Q11 What is the purpose of const qualifier? Ans: in order to declare a constant in C program const qualifier is used. Constant declaration has the following syntax const datatype identifier= vaiue Here Const is used to declare the variables. datatype represent the type of data. By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 25 Computer Science Notes For Class X identifier will be the name of constant. Value will be the value assigned to the constant. 1.1415; For example const float pi= Ans: Qa: Ans: Long Questions What is Programming Language? Explain different type of low level languages. Programming Language: A set of words, symbols and codes used to write programs is called language. Different types of programming languages are available for writing different programs. Programming languages can be classified into two categories. {a) Low level lanquages: These languages are near to computer hardware. Computer can understand these languages easily. Writing a program in low level languages requires a deep knowledge of the internal structure of computer hardware. There are two types of low-level languages. fiJMachine language: A type of language in which instructions are written in binary form is called machine language. It is the only language that is directly understood by the computer. It is the fundamental language of the computer. Program written in machine language can be executed vary fast by the computer. Machine language is difficult to understand by humans. Writing and modifying program in machine language takes a lot of time. Machine language is also known as first generation language. {iiJAssembly Language: Assembly language is a low-level language. It is one step higher than machine language. In assembly language, symbols are used instead of binary code. Symbols are called these mnemonic. For example, sub instruction is used to subtract two numbers. What are High Level Languages? Discuss the difference between Procedural Languages and Structured languages. High level anquages: High level languages are English-oriented languages. The program instruction is written using English words, e.g., print, input etc. There are different types of high level languages each having its own rules or grammar for waiting programs. These rules are called Syntax of the language. The program written in high-level language must be By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 26 Computer Science Notes For Class X Qs: Ans: translated to machine code before executed by the computer. Each high-level language has its own translator program. Some example of high level language is C, Java and Pascal. High-level programming language is divided into the following categories. Procedural Lanquages: Procedural language is also known as third Generation Languages (3GLs). Ina procedural language, a program is designed using procedures (also called modules). A procedure is a sequence instruction having a unique name. Procedures are executed with the reference of their names. Any procedure is defined once but can be used as many times as required within the program. Some examples of procedural languages are FORTRAN, Pascal, C and BASIC. Structured lanquag: A programming language where the program may be broken down into blocks or procedures, thus allowing a top-down design approach, is called structured language. Some of the better known structured programming languages are ALGOL, Pascal, PL/I and ADA. Explain the different parts/modules of C language IDE. The following are modules of the C programming environment. Editor: Editor or text editor is a program that enables users to create and edit C-language source program having extension e.g., student is a C-language source program. Compiler: A compiler is computer software that translate C language program source program into machine code (object program) that can be understood and executed by the computer. Linker: A computer program that takes one or more object codes generated by a compiler and combines them into a single executable program is called Linker. Loader: itis a program that loads C-language program into memory and then executes them. Debugat By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 27 Computer Science Notes For Class X Q6: In computers, debugging is the process of locating and fixing bugs (errors) is computer program code. A C-language debugger is a computer program that lets users run the program, line by line and examine the values of variables or look at values passed into functions and help in finding and removing errors in the program. What are the basic structures of C program? C programs consist of three main parts. 1. Preprocessor Directives: The instructions that are given to the compiler before the beginning of the actual program are called preprocessor Directives. These are also knows as compiler Direction. The preprocessor directives consist of instructions for the compiler. The compiler adds special instructions or code from these directives into the program at the time of compilation. These preprocessor directives normally start with hash sign # and the keyword include, e.g #include, #define, etc. Syntax: #includesheader-file.h> OR #include “header-file.h” Examples: #include include “eanio.h” 2. The main (} function: The main () must be include in every C program. When aC program is executed, the control goes directly to the main () function. The statements within this function are the body of the C program. If main() function is not included, the program is not compiled and an error message is generated. The Syntax of the main {) function is: main () { Program statements. } By: Muhammad Suleman M.Sc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 28 Computer Science Notes For Class X 3. Body of main (): The statement of the program are written inside the main() function in between the braces { }. These statements are the body of the program. Each statement is C ends with a semicolon; C is a case sensitive language. The C statements are normally written in lowercase letters. Q7: What are variables and constants? Differentiate them with example. Ans: Hes Quantities whose value may change during execution of the program are called variables. A variable represents a storage or memory location in the computer memory. Types of Variables: Numeric variables: These are used to represent numeric values in computer programs. They represent integer and floating-point values. Character Variables: They represent character values in computer programs. It can represent a single character or a string of characters. Constants: Constant is a quantity that cannot be changed during program execution. A literal constant is a value that is typed directly in a program. It appears in the program wherever it is needed. For example, the following statement contains string constant: “Pakistan Zinda bad” int age= 19; Here age is an integer variable and 19 is a literal constant. Q&: Explain different data types used in C language with examples. All C compilers accept the following fundamental data types to be assigned to variables. 1) integerfint, long } Type: Integers are whole numbers with a machine dependent range of values. A good programming language is to support the programmer by giving a control on a range of numbers and storage space. C has 3 classes of integer storage namely short, int and Jong. All of these data types have signed and unsigned forms. By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 29 Computer Science Notes For Class X Generally, the number of bytes set aside by the compiler for the above type qualifiers are as given in the table below. Variable Becaraton Wa. of Bytes ona ie z ALTE ALTE Tore a Ee ABS GAB to LAT AS SAT unsigned int z 0 wessas 2) Floating Point (Float, double, long double) Types: Floating point number represents 2 real number with 7 digits precision. Floating point numbers are denoted by the keyword float. When the accuracy of the floating point number is insufficient, we can use the double and long double to define the number. Variable Declaration No. of Bytes Range float 4 3.4x10 to 3.4x10* double 8 17x10 to 17x10 long double 10 34x10" to 11x10 3) Character {char} Type: A character variable can only store on character. An example of declaration of character variables is: char ch; The C compiler sets aside on byte of memory for storing a character in a character variable. Q9: What is Type Casting? Explain with examples. Ans: The process of converting one data type into another data type during execution is known as type casting. Type casting can be performed in two ways. i Implicit Type Casting: Implicit type casting is performed automatically by the C compiler. Example: Suppose x is an integer and yis a long variable and following expression is evaluated: xty By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 30 Computer Science Notes For Class X In the above expression, data type of x is lower than data type of y, so the value of x will be converted into long during the evaluation of expression. ii. Explicit Type Casting: Explicit casting is performed by programmer. It is performed by using cast operator. The cast operator tells the computer to canvert the data type of a value. Example: Suppose x and y are two float variables. x contains 10.3 and y contains 5.2 and the following expression is evaluated. xy The above expression will generate an error because data type of x and y is float. The modulus operator cannot work with float variables. It only works with integers so the expression can be written as follows: fant) 236 (int) y The above statement converts the values of x and y into integers and evaluates the expression. The value of x will be converted to 10 and value of y will be converted to 5. So the result of the above expression will be 0. ): How Variables are Declared and initialized in C language. Give Examples Declaration of variables: Assigning the name and data type that a variable can hold is called declaration of the variable. All variable that are used in a program are declared using variable declaration statement. The Syntax to declare a variable in Cis. Data Type List of variables; Where, Data Type specifies a list of variable. For example, int,Float, etc. List of variables specifies a list of variables separated by commas. Different statements are used to declare variables of different data types. For example, to declare variables abe, xyz, d and s of integer type. The statement is written as: Int abe,xyz,d,s; To declare variables a and xy as int type, b as float type, char type and sum as variable, the statement are written as: int axy; By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 31 Computer Science Notes For Class X SS float b; char ch; double sum; fn ation of Variables: Assigning a known value to a variable at the time of its declaration is called initialization of the variable. For example, to declare variables a, b and c of integer type and assigning values 11, 20 and 60, the statement is written as; int a =11, b=20, c=60; float n=3.35; Extra Question: Qi. What is Computer Program? Ans: A set of instruction that tells a computer what to do is called program. A computer works according to the given instruction in the program. Computer programs are written in programming languages. A person who develops a program is called programmer. The programmer develops programs to instruct the computer how to process data to convert it into information. Programmer uses programming languages ‘or tools to write programs, Qz2: Discuss the Following High level language: Clanquage C was developed by Dennis M. Ritchie of Bell Laboratories in 1972. It is a procedural programming language with many low-level features, including the ability to handle memory address and bits. It is highly portable among platforms and therefore widely used in industry and among computer professional. The operating system UNIX was written in C. C++ Language: C++ was developed in early 1980s by Bjarne Stroustrup. It is an object oriented programming (OOP) language. It is an extension of C programming language. C++ includes all the elements of the c language plus it has additional features for working with object, classes, events and other object-oriented concepts. Most of the application program, such as word processers and spreadsheet programs are developed in CH+> By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 32 Computer Science Notes For Class X Ans: Visual Programming Languages: The term programming refers to creating or developed Windows based application or graphical user interface application. The visual programming languages, sometimes. called fifth-generation language, are object oriented programming languages. These languages provide visual or graphical interface facilities to develop GUI application. Some popular and widely used visual programming languages are Visual Basic (VB) and visual C++. C# Lanquage: Cif or C-sharp is an object-oriented programming language. It was developed in 2000 by Microsoft Corporation. It is based on C++ with elements from visual basic and Java. It is used to write web applications that can be used across the Internet. All types of programming including games, utilities, operating system, compilers, business applications and web based application can be developed in C#. JAVA Lanquage: Java is a high-level object oriented-programming language developed by Sun Microsystems in 1991. It is very similar to C++ but it is especially used for web page designing. How Comments are written in € language? Comments are used to give some additional explanation about the program if required. It is used to provide a brief description of the purpose and operation of a computer program/statement(s); which makes the program more understandable to the users. Comments are non-executable lines and are ignored by the compiler during the translation. There are two ways of writing comments is C. 1. In this method comments are placed within the delimiters/* and */. For example: /* this is a comment line */ 2. In this style, comment begins with // and terminates at the end of the line. This style is useful to comment in individual lines of a program. For example: // this is a. comment line. By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 33 Computer Science Notes For Class X Chapter 3 Qi: What is Output function? Explain the output functions with example. Ans: In programming output is what the computer produce after processing the data. Function that are used to receive data from the computer memory and then to send it to the output device are called output functions. Following are the output functions. printf () Function: The printf() is used to display the string, value of variables and to print the answer of arithmetic expressions. It has the following general format. Printf(“escape sequences/format specifiers”, variables/expressions); Where: Escape sequence: It refers to a combination of character beginning with a \ followed by letters or special symbol. Escape sequence are used to format the output. Format Specifier: it is the conversion specification code. It is used according to the format of output value. For example %d is used for integer. Variable/Expression: It is a list of quantities to be printed according to format specifier. Escape Sequence: \n is used for new line and \t is used for tab. 2) Puts() Function: It is an Output function used to print a string on the screen. Syntax: put(string); © The string may be a string constant or string type variable © Incase of a string constant, the string is enclosed in double quotes. © Incase of a string variable it is written without using quotes. 3)Cout() Fun In C++ the output is displayed by using cout{) function. It is used with insertion operator <<. The general syntax of this function is given below. Cout// used for cout function #include// used for getch function Output: #include// used for puts function | ‘sine # displayed by using cout function 2 . | thistine ks dsplayed by using puts function #include// used for printf function this line ks splayed by using printf function void main() { cout<<"this line is displayed by using cout function”; puts(“this line is displayed by using putst function”); printf(“this line is displayed by using printf function”) getch(); } Q2: Write a simple program using printf function to display a string of characters on the screen. Ans: #includecstdio.h> #include void main() { printf(“Welcome to C programming”); getch(); } Q3: Write a simple program using printf() function ta display 123 4. Ans: i#tinclude #include By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 35 Computer Science Notes For Class X Vaid main{) { int a=1,b=2,c=3,d=4; printf “sod\ t%d\t%d\t%d",,b,c,d); } Program to display s string of character on the screen using puts function. #includeestring.h> #include void main() { puts(“Welcome to function”); getch(); } Write a simple program using cout function that finds the sum and product of two numbers. #include #include void main() { int a=4,b=5; int sum,pro; cout<<"sum of 4 and Sis="< #include Enter your Name= All Void main() Al { char name(20]; By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 38 Computer Science Notes For Class X cleser(); printf(“\nEnter your name= gets(name); puts(name); getch(); } Q9: Write a program to get name and age in years of a person. Calculate the age in months and print the name and age in months. Ans: Hincludecstdio.h> #includesconio.h> void main() { int age,age_mon; char name(40]; clrser(); printf(“\nEnter your name=’ gets(name); printf(“\nEnter your age="); scanf(“%d", &age); age_mon=age*12; ‘Output Enter your name= Ali Enter your age= 10 Your age in manths=120 printf(“\nYour age in months=%d”, age_mon); getch(); } Q10: Write a program that convert temperature given in Fahrenheit into Celsius. The Fahrenheit temperature should be input from the keyboard at runtime. Ans: #include #include void main() Please input a value for Fahrenheit temperature:98.6 Temperature in Celsius: 37 By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 39 Computer Science Notes For Class X Qut. Ans: Qi2. Ans: Q13: Ans: float ftemp,ctemp; clrser(); cout<<"\n please input a value for Fahrenheit temperature: cin>>ftemp; ctemp=(ftemp-32)* 5/9; cout<<"\n Temperature in Celsius: "< #include void maint) { int a=4; Output float b=3.4; ant char c=’W; besa cw clrser(); printf(“a=%d",a); // %d is used for integer. Printf("\n b=%f",b); // %f is used for float. printf(“\n c=%c",c); //%c is used for character. getch(); } Q15: What is Operator? Discuss the Arithmetic Operator in detail. Ans: Operator is the symbols used to perform certain operation on data. C language provides a variety of operators. These include arithmetic operators, assignment operator, relational operators and logical operator. Arithmetic Operator: Arithmetic operator are symbol that perform mathematical operation on data. Following are the list of all arithmetic operators used in C language. Operation Symbols Description Example Addition it: Adds two values 2+3=5 Subtraction ee Subtract two numbers 6-3=3 Multiplication , Perform multiplication 3*2=6 Division / Perform division 6/6=1 Modulus % Used for reminder of division of two integer. 6%3=0 By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 41 Computer Science Notes For Class X Qué: Ans Qi7: Ans: Discuss Assignment Operator and Compound Assignment Operator with examples. Assignment operator : The assignment operator is used to assign integer, float and character data to variables. However string data cannot be assigning to variable with this operator. Assignment operator has the following general format. Variable=interger/float/character_constant/expression; Examples: int a=3; float=4: Compound assignment operator: Compound assignment operator is the combination of arithmetic and assignment operator. Compound assignment operator are used to perform the mathematically operation more easily. char gender=" Syntax: variable ap= expression; For example a#=10 is equivalent to a=at10; anda -=10is equivalent to a= 2-10 Discuss increment and Decrement Operator in detail. Increment operator: Increment operator is represented by double plus ++ sign. It is used to add 1 to the value of an integer variable. For example to add 1 to a value of variable x, it is written as x=x+1. But by using increment operator ++ it is written as x++; The increment operator has two types which are given below. a) Prefix increment operator: when an increment operator is used in prefix made in an expression, it adds 1 to the value of the variable before the value is used in the expression. b) Postfix increment operator: when an increment operator is used in postfix mode in an expression, it adds 1 to the value of the variable after the value of the variables has been used in the expression. Decrement Operator: The decrement operator is represented by double minus - - sign. It is used to subtract 1 from the value of an integer variable. For example to subtract 1 from the value of variable x, the decrement operator is written as x-- or --r The decrement operator has two types which are given below. By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 42 Computer Science Notes For Class X Ans: Qi9: y a) Prefix decrement operator: when a decrement operator is used in prefix made in an n, it subtracts 1 to the value of the variable before the value is used in the in. b) Postfix decrement operator: when a decrement operator is used in postfix mode in an expression, it subtracts 1 to the value of the variable after the value of the variables has been used in the expression. What is relational operator? Write all relational operators with their uses. Relational Operator: The relational operators are used to specify the condition in program. The relational operator compares two vales. It produces result as true or false. The relational operators are some time called conditional operator. c/C++ provide the following relation operator. Operator Description > ‘The greater than sign is used to return true if the value on left side of > is greater then the value on the right side otherwise return false. < Less than sign is used to return true if the value on the left side of < is less than the value on the right side of the < sign, otherwise return false. = Equal to operator return true if the values in both sides are equal, otherwise return false. Greater than or equal to operator returns true if value on the left side of >= is greater or equal to the value on right side, otherwise return false. < Less than or equal to operator retums true if value on the left side of <= is less or equal to the value on right side, otherwise return false. I= Not equal to operator return true if the value on the on the right side of != is not equal to the value on the right side, otherwise return false. What is logical operator? Discuss the types of logical operator in detail. Logical operator: Logical operator is used to evaluate compound condition. Following are the logical operator used in C language. AND operator &&: the symbol used for AND operator is &&. It is used to evaluate two. conditions. It produces true result if both conditions are true. It produces false result if any of the condition is false. Condition’ | Operator | CondRion® | Result False ae False False False ee Te False Tne ae False False Te ee Toe True By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 43, Computer Science Notes For Class X 2) OR Operator ff: The symbol used for OR operator is | J. It is used to evaluate two conditions. It produces true if either of the condition is true. It produces false result if both the conditions are false. Condition | Operator | Condition2 Result Fae 7 Fate Take Fake 7 Troe Troe Troe TW abe Troe Troe TW Te Troe 3) Not Operator!: The symbol used for nat operator is |. It is used to reverse the result of a condition. It produces true result if the condition is false and produces false result if the condition is true. Condition Operator Result Trae T False False r True Q20: What is the difference between assignment operator = and equaf operator==? Ans: The assignment operator is used assign a value to the variable for example x=12 etc. while the equal operator is used to compare two values of the same data type for example b==10; etc Q21: What is the difference between Unary and Binary operators? Ans: The type of operator which is used with a single operand is called unary operator. Unary operator are -, ++and - - etc. For example in case of ~a, n++ and -x, there isa single operand so these operators are Unary operator. The type of operator which is used with two operands is called Binary operator. Binary operator are -, +and * etc. For example in case of atb, n-m and x*,y there are two operand so these operators are Binary operator. Q22: What is condition Operator? Ans: Condition operator is a decision making operator. It can be used in place of simple if- else statement. It is also called ternary operator because it uses three operands. Syntax: (Condition) ?true-case statement : false-case statement; Where By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 44 Computer Science Notes For Class X Condition is specified as relational or logical expression. True-case is executed if expression evaluates to true. False-case is executed if expression evaluates to false. Q23: Write all operators used in C language and their precedence. Ans: Order of precedence of operator is the rule that specifies the order in which operations are to be performed. The following are the entire operator and their precedence. Precedence Operator Type 1 1 Logical Not 2 "2% Multiplication, division, modulus 3 + ‘Addition. Subtraction 4 Relational operator 5 Relational operator 6 a& Logical AND 7 1 Logical OR 8 = ‘Assignment operator Q24: Write aC program that illustrates the operator precedence available inC language. Ans: #include #include #include void main() { int a=20,b=10,c=: Output int 8; Value of (a+b)*c/d is: 90 clrscr(}; Value of ((a+b)*c)/d is: 90 e=(atb)*c/d; // {30*15)/5 Value of (a+b)*{c/d)jis: 90 printf(“value of (a+b)*¢/d is ; %d\n 4 Value of a+ib*c}/dis: 90 (a+b) *c)/d; //(30*15)/5 OO OOO aes By: Muhammad Suleman ‘MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 45 Computer Science Notes For Class X printf(“value of ((a+b)*c)/d is:%6d\n",e); e=(a+b)*(c/d); /(30)* (15/5) printf(“value of (a+b)*(c/d);is:%d\n”,); e=at(b*c}/d; //20+ (150/5) printf(“value of a+(b*c)/d is:%c\n",e); getch(); Exercise Short Questions: Qi. What Is the use of format specifiers? Give examples. ‘Ans: Format specifier is the conversion code. It is used with input/output functions according to the format of input/output data type. Following are example of some commonly used format specifier with their uses. Format %d or %i is used to read or print an integer and %ld is used to read and print long integer. %c is used for single character, %s is used for string etc. Q2: Why escape sequence are used? Give examples. Ans: Itis special non-printed characters used to control printing on the output device. These are the combination of characters beginning with a \ followed by letters or special symbols. It is used to format the output. Following are some escapes sequence and their uses. \n used for new line for example printf(“hello\nworld”); \t used for tab for example printf (“ hello\nworld”); Q3: What is the purpose of gets() function? Ans: The get function reads in an entire string until user presses Enter key. It has the following general format gets(Array_Name); The gets function is capable to accept a string with white space characters. This function read everything including blanks and tabs until user presses Enter kay. By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 46 Computer Science Notes For Class X Differentiate between getch() and getche() functions. Ans: The getch() function is an input function which reads a character from the keyboard without it displaying on the screen. While the getche() function is an input function which reads a character from the keyboard with displaying it on the screen. QS: Evaluate the following expressions. a) 9-5*(6+2) (b) 60/10*24+3 (c) 100%50-100%3 Sol: Sol: 9-5*(6+2) Sol: 60/10*2443 Sol: 100%50-100%3 29.58 = 6*2443 = 0-100%3 29-40 = 14443 =31 =147 Q6: Differentiate between simple and compound assignment operator. ‘Ans: The assignment operator is used assign a value to the variable for example x=12; y=a; etc. while the equal operator is used to compare two values of the same data type for 10; ete Exercise Long Questions. For question 3,4,5,6 see topic wise questions. Q?7: Write a program that reads three numbers and prints their sum, product and average. Ans: #include #include void main(} t int 0,b,¢,surn,pro; float avg; clrser(); coute<"Enter first value: ”; cin>>a; el By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 47 Computer Science Notes For Class X } cout<>b; cout<<“Enter third value. cin>>c; sum=atb+c; pro=a*b*c; cout<<"sum= “<>b; coute<"Enter the value height: ”: cin>>h; ar=0.5*(b*h); cout<<“area= "< #include void main() { } float ftemp,ctemp; clrser(); cout<"\n please input a value for Fahrenheit temperature: ”; cin>>ftemp; ctemp=(ftemp-32)* 5/9; cout<"\n Temperature in Celsius: "< ‘sinetudecconio.h> void maind); { char namef201; char address[20}; desert); print{("Enter your namne:\n"}; gets(name}; puts{name}; printf("Enter your address:\n"); gets(address); puts(address): getch(); } ES By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 49 Computer Science Notes For Class X Chapter 4 Q1: Explain the if-staternent with syntax in detail. Ans: The if-statement is the simplest decision making statement. it is used to execute or skip astatement ar set of statement by checking a condition. The condition given as a relational expression. If the condition is true the statement or set of statement after if statement is executed other not executed. Syntax. tateme: The given syntax used for single statement If (condition) Statement; In case of set of statement, these statements are written in braces { }. ‘Syntax for set of statement If (condition) { Statement 1; Statement 2; Statement n; } Q2: Write a simple program in C that prints the entered number when it is greater than 50 using if-statement. #include #include void main() { inta; clrser(); By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page $0 Computer Science Notes For Class X printf(“enter the value of 1" a); Output scanf(“ if (a>50) printi(“%d", a); Enter the value of a=60 60 getch(); } Q3: Write a program that executes a single statement if the given condition is true. Ans: #include #include Void main() { ‘Out put int a=1000; int b= 500; value of a is greater iffa>b) than the b printf{“value of ais greater than the b”}; getch(); } Q4: Write a program that asks the user to enter two values, if the vatue are equal it will print a message. Ans: #include #include void main() { inta,b; elrser(); printi(“Enter the value of a”); scanf(“%d",&a); printf(“enter the value of ”); a By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 51 Computer Science Notes For Class X SD scanf("%d” ,&b); Enter the value of a= 2 Enter the value of b=2 printf(“Both the NO are equal”); Both the numbers are equal getch(); } QS: Explain if-else statement with Syntax. Ans: if-else statement: It is a decision making statement that executes a statement or block of statement if the condition is true and another statement or block of statement if the condition is false. Syntax for if-else statement: if (condition) Statement; else Statement; Syntax for compound statement: if (condition) Statement 1; Statement 2; Statement n; else Statement 1; Statement 2; Statement n; Q6: Write a program that input ¢ number and find whether it is even or odd using if-else statement. By: Muhammad Suleman Msc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 52 Computer Science Notes For Class X Ans: #include #include void main() { ‘Output 1 int a; Enter a value a=6 printf(“Enter a number ”); Giseven scanf{"%d",&a); if(n9%2==0) printf(“s%d is even”,a); ‘Output 2 else Enter avalue=9 printi(“%d is add”,a); Sis odd getch(); } Q7: Write a program that prints the larger number from given two numbers. Ans: #include #include void main() { int a,b; elrser(); printf(“Enter the value of a”) scanf(“%d" 8a); Enter the value of a= 6 printf(“enter the value of b”); Enter the value of b=9 scanf(“%d",&b); Qis larger than 6 if(a>b) printf(“\n 9d is larger number than %d”,a,b); else printf(“\n 9d is larger number than %d”,b,a); By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 53 Computer Science Notes For Class X getch(); } Q8: Write a program that finds the smallest number of given three. Ans: fincludeestdio.h> Output #include Enter three Now void main() 6 { R int 5,x,9,25 ‘The smallest No is:6 clrser(); printf(“Enter three numbers”); scant(“%d Sod 96d %6d ” Bx, My, 962); if (ey) SEX; else s=y; if (sez) printf(“the smallest No is:%d”, s); else printf(“the smallest No is:%6d”, 2); getch(); } Q9: Explain switch statement with syntax in detail. Ans: The switch statement is used for multiple choice or selection. It is used as a subtitle of if- else statement. It is used if multiple choices are given and one is to be selected. Syntax for h statement: switch{expression) { case count-1: By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 54 Computer Science Notes For Class X statements: break; case const-2: statement: break: case cont-n: statements: break: default: statements: } In the above syntax the expression appears within the switch statement. The expression is first evaluated and then the value returned by the expression is compared with the values of constant given in each case. If the value matches with the constant value of a case then the statements of that case are executed. The const-i and const-2 are numeric constant or character constant. The break statement in each case is used to exit from switch body. It is used at the end of each case black. If break is not used, all case blocks that come after the matching case, will also be executed. The keyword default is also used in the body of switch statement. If no case is matched then the statements under the default or executed. Its use is optional. Q10: Write a program to show that an input character is vowel or not. Ans: #include Output #include Enter a character =u void main() Vowel u { char ch; elrser(); By: Muhammad Suleman Msc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 55 Computer Science Notes For Class X printf¢“Enter a character”) scanf(“%6c", Bech); switch(ch) { case printf(“vawel a”); break; case ‘e’: printf(“vawel e”); break: case ‘o': printf(“vawel 0”); break; case printf(“vawel i”); break: case ‘u’: printf(“vawel u”); break; default: printf(“not a vowel ”); } getch(); } Qi1: Discuss nested selection structures in detail. Ans: In nested selection structures one selection can be enclosed inside another selection structure. For example an “if” can be nested inside the other if structure. Synta. By: Muhammad Suleman M.Sc Computer Science + BED Certified Teacher at GCMHSS Nahagqi Peshawar Page S6 Computer Science Notes For Class X if (condition) { if(condition) { statement(s); } else { statement(s); } ? Q12: Write a program to find that a number that Is input from the keyboard is positive, negative, even, or odd? Ans: #finclude #include Void main() Enter a number which is between -10 and 10: 7 ; Tis a positive number ota) Tis anoddalso elrscr(); couts<" Enter a number which is between -10 and 10:\t”; cin>>a; if(a>0) { couté #include void main() { int abc clrser(); printi(“Enter three integers\n”); scanf(“%d %d %d”,8a,&b, 8c); By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 58 Computer Science Notes For Class X if(a>b& Base) { printf(“\n %d is largesr”,a); } else if (b>a&&b>c) { Output prinft(“\ndéd is targest”,b) Eater three integers } 3 else ‘ { 5 Sisk prinft(“\ndéed is largest”,c);| est } getch(); } Q3: Write a program in C to input a single character and print a messages “it isa vowel” or “it is consonant”. Use if-else structure. Ans: #include<"iostream.h”> #include<"conio.h”> void main() { clrser(): Output 1 char al; Enter a single character=e cout<<"enter a single character”; itis vowel cin>>al; if(als='a' | |al=="e' | |al=='i'||al=2'o"| [al=="u') Output 2 Enter a single character=n cout<<"it is is vowel” Itis consunant By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 59 Computer Science Notes For Class X cout<<"it is consonant”; getch(); } Q4: Write a program in Q3 using switch-case structure. Ans: #include #include void main() { char ch; elrser(); Output printf(“enter a character”); Enter a character =u scanf(“%c", &ch); Vowel u switch(ch) { case ‘a’: printf(“it is vowel”); break; case ‘e’: printf(“it is vowel”); break: case ‘o': printf(“it is vowel”); break; case ‘i printi(“it is vowel”); break: case ‘u’: printf(“it is vowel”); By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 60 Computer Science Notes For Class X break; default: printi(“it is consonant ”); } getch(); } Q5: Write the output of the following program. #include #include void main() { int a,b,c; a=b=10; printf(“condition is true\n”); ‘Output: a is equal to b else als not greater than ¢. { printf(“a is equal to b\n”); printf(“a is not greater than cin”); } } Q6: Find out error if any in the following program. #include #include Void main() { int a; —————— SSS a avwx—ere— By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 61 Computer Science Notes For Class X printf(“Enter any number=' scanf(“S6f", a); // 96d is required because %f is used for float value if(a>10) printf(“value is greater than 10”); else if // here is not required printf(“value is less than 10"); } By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 62 Computer Science Notes For Class X Chapter #5 Qi: What is Loop Structure? What is the purpose of Loop Structure? Ans: A type of control structures that repeats a statement or set of statement is known as looping structures. It is also known as repetitive structure. There are different types of loops available in C. Loop are used for basically two purposes. * To execute a statement or number of statements for a specified number of time. For example a user may display his name on screen for 20 times. © To execute a statement or number of statements depending upon certain condition being true or false. For example a user may display a set if natural numbers until a variable “x” becomes 100. Q2: What is for loop? Write the syntax of ‘for loop’. ‘Ans: For loop executes one or more statements for a specified number of times. It is the most frequently used loop in programming. Syntax: The general syntax for “for loop’ is given below for(initialization;condition;increment/decrement) { Body of the loop; it is an expression which specifies the starting value of counter variable. Condition: The condition is given as a relational expression. The statement within the loop is executed only if the given condition is true. If the condition is false, the statement is not executed, Increment/Decrement: this part of loop specifies the change in counter variable after each execution of the loop. Body of the loop: It is a statement are group of statements in braces { }to be repeated. Example: for(a=1,a<=5,a++) a=1is the initialization, a<=5 is the condition and a++ is the increment. By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 63 Computer Science Notes For Class X Q3: Write a program that display numbers from 1 to 10 by using for loop. Ans: #include #include void main() Output { 12345678910 int; clescr(); for(x=1jxc=10pt+) printf(“%d\t",x); getch(); } Q4: Aprogram that display numbers In reverse order from 10 to 1. Ans: Hincludecstdio.h> #include void main() Output { 9987654321 intx; clrser(); for(x=10;x>=1;--x) printf(“%d\t",x); getch(); } QS: Aprogram that input a number and displays the table of the number up to 10 using for loop. Ans: #include #finclude void main() { By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 64 Computer Science Notes For Class X intnx; clrscr(); Enter number for table:S printf(“\nEnter the number for table:”); scanf(“%d",&n); pues. for(x=2;x<=10;xt+) 5X2=10 5x3=15 printf(“"\nd%d X %d= %d”,n,x,n*x); 5x4=20 getch(); SXS=25, Q6: Write a program that calculate the sum of odd numbers from 1 to 20 and print the sum on the screen. Ans: #include #include void main() { } int n,sum; clrser(); sum=0; Output for(n=1;n<=20;n+=2) sum=20 { Sumssum#n; } printf(“\nsum=%d”,sumn); getch(}; Q7: What is While loop? Write the syntax of While loop. Ans: While Loop: While Loops can execute a block of code as long as.a specified condition is true. Synatx: While (condition) By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 65 Computer Science Notes For Class X body of the loop; } Condition: The condition is given as a relational expression. The statement within the loop is executed only if the given condition is true. If the condition is false, the statement is not executed. Body of the loop: It is a statement are group of statements in braces {} to be repeated. Q8: Write a program that displays” Pakistan’ five times using while loop. Ans: #include #include Output void main() Pakistan { Pakistan intn=t; Pakistan lrscr(); Pakistan while(n<=5) pakistan { printf(“Pakistan\n”) net; } getch(); } Q9: Write a program that display natural numbers from 1 to 20 in descending order. Ans: #include i #include ‘i void main() ? ‘ { s int n=10; 4 clrser(); 3 while(n!=0) : ooo : Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 66 Computer Science Notes For Class X { printf(“%d\n",n); ne; } getch(); } Q10: Write a program that resolves the following series and displays the result using while loop 244+4....420 Ans: #include #include void main() { int c=2,sum=0; lrser(); while(c<=20) { Output sum= sum+c; sum=110 printf(“sum= 9d”,sum); getch(); } Q11: What is do while loop? Explain with syntax. Ans; The do while loop is a variant of the while loop. This loop will execute the code block ‘once, before checking if the condition is true, than it will repeat the loop as long as the condition is true. Synt. By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahagi Peshawar Page 67 Qi2: Ans: Qi3: Ans: Computer Science Notes For Class X do{ Body of the loop: while (condition); Here Condition: is given as a relational expression. The statements of the body are executed if the given condition is true. if the condition is false, then statements of the body are executed only once because the condition comes at the end. Body of the foop: it is a statement or group of statement in braces { } to repeated Write a program that print ten integers using do-while loop. #include #include void main() { Output int n=1; 1 clrscr(); 2 do 3 { 4 Prinft(“%d\n",n); 5 net; 6 } 7 while(n<=10); & getch(); 2 } 10 What is break statement? Write a program that Inputs a number from the user using for loop. If the number is greater than O, it is displayed and the next number is input. The program exits the loop if the number is 0 or negative using breaks statement. Break Statement: The break statement terminates the execution of the loop when it is used inside the body of the loop. Syntax: By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 68 Computer Science Notes For Class X break; Example/Program: #include #include void main() { int x,num; Output elrscr(}; for(x=1;x<=5,x++) Enter a number:3 { You entered 3 prinft(“\Enter a number); Enter a number: 0 scanf("%d”", &num); OK if (num<=0) break; prinft(“\nYou entered %d\n’ num); } printf(“\n OK”); getch(); } In this program the break statement is used in for loop. The counter variable x indicates that the loop should execute for five times. But it executed only twice. In the first iteration, 3 are displayed on the screen. In the second iteration the printf() statement in the loop displays question and control moves to break statement. This statement moves the contral out of the loop. So the message appears only once. Q14: What is Continue Statement? Explain with the help of example. ‘Ans: Continue Statement: The continue statement shifts the control back to the beginning of the loop. It is used inside the body of the loop. When this statement is executed inside the body of the loop, the control shifts to the first statement of the body of the loop. Syntax: By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 69 ‘omputer Science Notes For Class X TS continue: Q15: Write a program and use the concept of continue statement using while loop. # include # include void main() { clrser(); inte; 1; while(c<=5) OUTPUT { printf(“Pakistan/n”); Pakistan ae Pakistan continue; Pakistan Pakistan printi(“Islamabad”); Pakistan printf(“Peshawar"); } getch(); } In the above program, only first three statement inside the while loop are executed S times. The two statement after continue statement are not executed because each time the continue statement returns the control back to the beginning of body of loop. Q16: Differentiate between for loop, while Loop and do while Loop. The following is the difference among for, while and do-while loops. For Joop: It is preferred to use when the programmer knows in advance how many times the body of the loop while be executed. While Loop: It is suitable to use in situations where the programmer does not know the number of times the body of the loap will be executed. In while loop, test condition comes before the body of the loop. First, the condition is tested and then the body of the loop is executed. By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 70 Computer Science Notes For Class X ES Do-while loop:\t is suitable to use in situations where the programmer wants the loop to be executed at least once. In do-while loop, the body of the loop comes before the test condition. The body of the loop is executed and then the condition is tested. In da-while loop the condition is terminated with semicolon ie., statement terminator; Q17: What is Nested Loop? Ans: Aloop within another loop is called nested loop. In nested loop in inner loop is completely enclosed inside an outer loop. The following diagram explains the use of nested loop. Outer Loop Inner Loop End of inner loop end of outer Loop Q18: A program to print the output as shown below. Using nested for loops. include output # include void main() { lrscri); By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 71 Computer Science Notes For Class X EXERCISE Note: For question 2 and 3 see the Topic vise questions. 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 # include void main() { elrser(); int n=100; long int product=1; int number=2; while(number<=1) { if(number%2==0) { product= product*number; } ++number; } rintf(“the product of even number from 1 to 100 is: %d\n” product); getch(); } Q5: Write a program ine that display alphabet from A to Z using for foop. Ans: # include # include void main() By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 72 Computer Science Notes For Class X { clrsert); OUTPUT char c; A B cC »D EE prinft(“Alphabets from A to Z:\n") ; F G6 oH ot J for(ce’A'je<='2';+-4¢) : a ‘ . a printf(“96¢",c); uovoeow x ¥ z getch(); ) Q6: Write a program to display the following output using nested for loop. a a oa ao aaa ao a@ aa a Ans: #include #inlude void main() { int ij; for(is1jie=5ji+4) { printf(“a\t’); } printf(“a\n”}; } getch(); } ——————_—_————_— Ss By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 73 Computer Science Notes For Class X Q7: Write a program in C that print the sum of odd number from 1 to 50 using the for loop. Ans: #include #inlude void main() Output { int isum=0; Sum of odd numbers from 1 to 50:625 for{i=O;i<=50;i++) { if(i%21=0) { sum=sumti; } } printf(“sum of odd number from 1 to 50 is: %d”,sum); getchi(); By: Muhammad Suleman Msc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 74 Computer Science Notes For Class X Chapter 6 Ans: How data are representing in a computer? Data the raw material. Inside the digital computer data is represented by ON and OFF electrical pulse form. It is also called binary form because ON is represented as 1 and OFF is represented as 0. In computer system 1 means pulse of electricity and 0 means no pulse of electricity. All the data entered into computer must first converting to binary system and then processed. One digit in binary system is called bit. The combination of eight bit is called byte. A byte is the basic unite in computer memory used ta represent data. One byte represents one character of data. It can be alphabetic character, numeric character or any other special symbols. For example when we enter a character A in computer it is first converted to binary code i,e 01000001. In same way all characters are converted into binary form. What are logic gates? Explain the three logic gates with diagram and truth table. Logie Gate: A Logic Gate is an electronic circuit that takes one or more inputs signals and produces a single output signals as output. It performs a particular logical function. Basic Logic Gates: There are three basic logic gates which are discuss below. AND Gate: ‘The AND gate performs logical multiplications. The AND gate has two or more input and a single output. The output of AND is 1(high) if both the input is 1 (high), and out is o(low) if both the input is O{low) or even if one of the input is (low). For example if x and y are two input, then the output F can be represented mathematically as F=x.y here dot(.) represent the AND operation. Symbolically: The AND gate is represented as x —— Truth table for 2-inputs: —| } Input | Output x |¥ F 0 fo 0 0 |i 0 1 [a 0 1 fi 1 By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 7S, Computer Science Notes For Class X 2. OR Gate: The OR gate perform logical addition. The OR gate has two or more inputs and single ‘output, The output is 1(high) if both or one of the input is 1, and the output is O(zero) if both the inputs is O{low). For example if x and y represent the input then output F can be represented mathematically as F=x4y. here + represent the OR operation. Symbolically OR gate is represented as, Table for 3.inputs on input | Output Truth Table for 2 Inputs: Input Output ia ps o o}jo}jo x |¥ F o fofala 0 fo fo o 1jo]1 0 1 1 1 [ojo|a 1 [o T a fofila 1 [2 7 a. 1jo}1 1 1jija 3. Not Gate: The NOT gate is used to reverse the input value. It has a single input and a single out. It is a gate whose output is 1(high) if the input is O{low) and output is 0 if input is 1(high). For example if x is the input then F=y’ is the output. Symbolically OR gate is represented as y— Fa By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 76 Computer Science Notes For Class X Truth table: Input | Output x x 1 0 0 T Q3: Discuss the following gates with diagram and truth table. Ans: 1. NAND Gate: NAND gate means “NOT AND gate”. The output of this gate is 0 when all the inputs are 1. NAND gate is the inverse of AND gate. If x and y are the two inputs of an NAND gate and F is the output, the block diagram and truth table is shown in following figure. Input | Output x |Y | Faq o fo fa o fa fa 1 {o [2 a a) 3. NOR Gate: NOR gate means “NOT OR gate”. The output of this gate is 1 when all the inputs are 0. This gate is the inverse of OR gate. If x and y are the two input, then the output F can be represented mathematically as F=(x+y)’. input] Output xv _| bey oO o 1 oO 1 o 1 Jo |o 1 1 oO By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 77 Computer Science Notes For Class X 3.Exclusive-OR Gate(XOR): The gate whose output is 0 when all inputs are either Os or 1sis called XOR gate. It produces 0 output for same input values, and produce 1 for different input values. Ifx and y are the two inputs of XOR gate and F is the output, then the block diagram and truth table of XOR gate is shown in figure. Tipu Output ¥ Feber pay 0 a T T 7 o i 7 7 o following 4.Exclusive-NOR Gate (ANORIJ: The gate whose output is 1 when all inputs are either Os or 1s is called XOR gate. It produces 1 output for same input values, and produce 0 for different input values. Ifx and y are the two inputs of XNOR gate and F is the output, then the block diagram and truth table of XNOR gate is shown in following figure. Truth table Input | Output x TY Fatxy)axyex’ y oO oO 1 0 {iz fo 1 o oO 1 1 oO Q4: Howcan we create NAND, NOR ,XOR, and XNOR gates using basic gates? Draw circuit diagrams for all the above mentioned gates. ‘Ans: AND, OR and NOT gates are used to create the other gates. Creating NAND qate using basic gates: NAND gate can easily create by using AND and NOT gates as shown below. By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 78 Computer Science Notes For Class X Creating NOR qate using basic gate: NOR gate can easily create by using OR and NOT gates as shown below. Lfreation of XOR Gate Using Basic Gotes: ‘The XOR gates represent the function as Fex’y + xy This function consist of two terms xy and xy’. Two AND gates are required for these terms and the output of these gates can be input into a single OR gate to create the XOR gate as shown. Two NOT gates are also required in the circuit to change the input x to x/ andy tay’. Creation of XNOR Gate Using Basic Gates: The XOR gates represent the function as F=xy+x/ y/ This function consist of two terms xy and x’ y’. The logic circuit of this gate can be created by using two AND gates for the terms xy and x’ y’, two NOT gates to change x to x/ andy to y’ and a single OR gate as shown in the figure. By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 79 Computer Science Notes For Class X Q5: Draw the logic diagram for the folfowing Boolean expression. By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 80 Computer Science Notes For Class X Exercise Note: For Q1 and 2 see the topic wise questions. Q4: Convert the following Boolean expression into logic gates. F(A,B,C)=ABC+A!/ B/ +/+ (A.B)! Q5: Simplify the following Boolean functions using K.Map method. Also draw the logic diagram of the simplified function. i Fax! Zox! 2! x x Zz 1 0 z 1 0 Fax! i Fea’ B+ BC’ +B! C! By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 81 Computer Science Notes For Class X We Fe By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 82 Computer Science Notes For Class X Qi: Ans: Chapter #7 What is World Wide Web (www)? WORLD WIDE WE! The internet is a global network connecting millions of computer. Internet is a Wide Area Network (WAN) of computer and World Wide Web is the main application of Internet for accessing and sharing information all over the world. It allows people to share knowledge, ideas and thoughts. World Wide Web (www) is an information system on the internet which allows documents to be connected to other document by hypertext links, enabling the user to search for information by moving from one document to another. Discuss the following term: Web Page: ‘A web page is a document on the Internet that can be accessed through a web browser. Every web page is identified by a unique URL (uniform Resource Locator) or web address. Web browser is used to display web pages. Web pages contain text, graphics, images, sound and video clips all in one place. Web: A website is a collection of related web pages hasted on a web server. It is accessible through an internet address known as URL. For example a website www.nts.org.pk . Web browser: A web browser is a software that enables users to retrieve information on the web. Information on the web is accessed by the URLs. Web browsers allow users to open multiple websites at the same time, either in different browser windows or in different tabs of the same window. All the browsers have graphical interface which is very easy to learn and use. Two very popular web browsers are internet Explorer from Microsoft and Google chrome from Google. Web Server: Web servers are computer that facilitate and deliver web pages from various websites they have. Every web server has an IP address and possible a domain name. For example, if user enters the URL http://www.pakistan.gov.pk/national-symbols.html in the browser, this sends a request to the web server whose domain name is pakistan gov.pk. The server then fetches the page named national-symbols.html and sends it to the user’s browser. By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 83 Computer Science Notes For Class X Any computer can be turned into a web server by installing server software and connecting the machine to the internet. Uniform Resource Locator (URL): A URL (uniform Resource Locator) Is the unique address for a file that is accessible on the Internet. A common way to get to a website is to enter the URL of its home page file in the web browser’s address line. However, any file within that website can also be specified with a URL. URLs have the following format: Protocol://hostname/other-information For example, the URL for Peshawar Education board’s home page is: http://www. om.pk/ma The http:// (hypertext transfer protocol) specifies how information from the link is transferred. The domain name, www.bisep, is the computer an which the resource is located. Links to particular files or subdirectories may b further specified after the domain name. Directory names are separated by single forward slashes. Search Engine: A search engine is a website or software system that allows people to find information on the World Wide Web. Finding exactly what the user looking for is not easy with millions of web pages on the Web. Search engine have been designed to help users find specific informaticn on the Web. Users type in one or more keywords in a search engine. The search engine looks for matching websites from all over the Web. The information shown for each website includes a title and a brief description. If the user wants to open any site, he just clicks onthe link. The popular search engines are Yahoo and Google. Home Page: Home page is the main or very first web page of a website that opens in a browser when users access it. Web Hosting: Web hosting is a service, provided by web hosting companies, to upload websites on web servers and make them available for computer users. These companies make the websites running on computers all the time that are connected to the Internet. To hast a website a web server and a permanent connection to the internet is required. It also aS By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 84 Computer Science Notes For Class X Ans: requires website administration such as managing and configuring a web server and virus protection. Computer user’s first design web pages on their computer and test it to ensure they work properly. When web pages are ready they are uploaded on a web server to make them available for others. Web Hosting companies provide 24 hour support and online control for managing the website. Write the types of website. Types of Websites: Most popular types of websites are: Web Portals: Web portals are websites that offer different types of service. These include online shopping malls, news, stock prices, e-mail and search engines, etc. Web portals function as a point of access to information on the Web. For example, a university's web portal delivers information about the university’s background, admissions, fee structure, facilities, curriculum, departments, programmers ete. News Websites: News websites provide information about current events and opinions. These sites publish news stories and let their visitors’ voice be heard. These sites provide their visitors a way to get their thoughts and views published. Very often at the end of news stories, visitors are asked to share their experience or knowledge about the topic. Therefore, link for the readers comment is provided for feedback. Some examples of news websites are www.dailymashrig.com.pk/www.paktribune.com, www.thenews.com.pk, Informational Websites: Informational websites provide information on any topic in the form of text, graphics, sound and videos. For example, www.wikipedia.org is an informational website that provides information on millions of articles. It allows users to contribute and edit articles as well. As another example, www.encyclopedia.com is another informational website that provides information on a large variety of topies including people and humanities, Animals, Business, Computer and literature, Health education etc. Educational Websites: Educational websites are created for educational purposes. These sites contain animation, slide presentations and educate people on various topic. Information is presented in a very well organized way. The purpose of any educational website is to By: Muhammad Suleman MSc Computer Science + BED Certified Teacher at GCMHSS Nahaqi Peshawar Page 8S Computer Science Notes For Class X nn SSE SSE impart knowledge to people who are looking for better understanding of a topic and purse knowledge. Some examples of educational websites are www.educationworld.com, www.ilmkidunya.com and www.knowledgepk.com, etc. Personal Websites: Personal websites are created and maintained by individuals for personal use. These websites contain information about a person’s interests, hobbies, etc. the purpose of personal sites is to share personal information with family members and friends. Personal websites are also open for public and anybody can visit and leave comments. Business Websites: Business websites provide facilities to maintain business relationships and selling information, services and commodities via internet. These sites facilitate exchange of business documents, such as orders or invoices between supplies and customers. Services provided by business. Ticket reservation, stock market transactions and even remote education. Entertainment Websites: These websites provide different types of entertainments to computer users. Entertainment websites include sports, music, radio, television, computer games, comedy, and fashion and movies websites. By: Muhammad Suleman MSc Computer Science + B.ED Certified Teacher at GCMHSS Nahaqi Peshawar Page 86

You might also like