["f. \t Ascending or descending order Smart Computer Science Book-10 g.\t Remove unnecessary record Editing Record Resize Descriptive Questions 1.\t Write very short answer of the following questions: a.\t What is viewing table? b. \t What is switching view? c.\t What is adding records d.\t What is editing records? e.\t What is deleting record? f.\t What is freezing column? g.\t What is sorting? 2.\t Write short answer of the following questions: a.\t What is resize height\/width of the row\/column? b.\t Why do you use the Datasheet View? c. \t What is hide or unhide column? d.\t Why do you use design view? Case Study and Application-based Questions* 1. \tOn the basis of given table, answer the asked questions: a. \t How do you add more records in this table? Ans: ............................................................................................................................. ..................................................................................................................................... Approved by Curriculum Development Center (CDC) 201","Entering & Editing Data b.\t What type of data is ticked? Why is it ? Give reason. Ans: ............................................................................................................................. ..................................................................................................................................... ..................................................................................................................................... c.\t Is there any modification in gender column? If it is, list out and express how you modify? Ans: ............................................................................................................................. ..................................................................................................................................... d. \t In the third column, some of the information are disappeared. How do you solve this problem? Ans: ............................................................................................................................ ..................................................................................................................................... ..................................................................................................................................... e.\t From record number 8, 'Muna' has left the office, so this record is not necessary to remain in this list. What is the solution of this problem? Ans: ............................................................................................................................. ..................................................................................................................................... ..................................................................................................................................... f.\t In the last column, if it is asked you to add two decimal places and currency symbols with the values, how do you perform this task? Ans: ............................................................................................................................. ..................................................................................................................................... ..................................................................................................................................... g.\t If you are asked to increase the row height in all the rows, how do you perform? Ans: ............................................................................................................................ ..................................................................................................................................... ..................................................................................................................................... h.\t A problem is raised in front of you that is to add one more field 'Joined_date' between column number 1 and 2. How do you solve this problem? Ans: ............................................................................................................................. ..................................................................................................................................... 202 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 ..................................................................................................................................... i.\t If you want to add more records in this table, how would you proceed? Ans: ............................................................................................................................. ..................................................................................................................................... ..................................................................................................................................... Lab Activity-1 1. \tDesign a table named 'Emp' and add records as mentioned below then perform the given tasks. a.\t Decrease the column width of the 'Gender' field. b.\t Increase the column width of the 'Department' field. c. \t Add the two decimal places and currency symbol in last field. d.\t In the record number three, the name 'Asmita' is incorrect entry. It should be 'Asmit', correct it. e. \t Uncheck the gender of record number 5 'Rasmita'. f.\t Increase the row height of all the rows. g.\t Add one more field 'Joined_date' between field 1 and 2. h.\t Arrange the data in alphabetical order on the basis of 'Ename' Field. i.\t Display the alternate name as 'Ename' to 'Employee name', 'BSal' to 'Basic Salary' and 'Sn' to 'Serial Number'. Approved by Curriculum Development Center (CDC) 203","Queries in MS-Access CHAPTER Queries in MS-Access 11 Chapter Includes \u2022\t Introduction to Query \u2022\t Types of Query \u2022\t Creating Select Query \u2022\t Running Query \u2022\t Action Query \u2022\t Insert Query \u2022\t Wildcard Characters with Query INTRODUCTION Query refers to a request to database that can ask about the data stored in a database table. Query is used to answer a simple question, to perform calculations, to extract data from different tables, or even to add, change, or delete table data. Two major types of queries supported by Ms-Access are: \t i) Select Queries\t ii) Action Queries\t \t SELECT QUERIES The query which extracts data from the table as per the user's request without making any change in the existing data is called Select Query. It is the simplest type of query that selects the data which you want from one or more tables and displays in the order as you mentioned. A select query can include criteria that tells Access to filter records and display only some of them. Creating Select Query In Ms-Access, select query can be created using two techniques: \t i) Query Design\t\t\t ii) Query Wizard Create Query using Query Design To create a query using Query Design, do the following steps: Steps to Follow: Step-1 : \tOpen the database Table. Step-2 : \tClick the 'Create' Tab. Step 3 : \tFrom the 'Queries' group, click the 'Query Design' option. You get the 'Show Table' dialog box as given. 204 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Step-4 : Select the table on which to create a query. Here, it is selected the table 'Sal'. Step-5 : After selecting a table, click the 'Add' button. Stpe-6 : Click the 'Close' button when you finish adding. Step-7 : Now, select the fields which you want to include in the query using one of the following techniques. \u2022\t Double click on the field. \u2022\t Click on the field and drag it to the required column in the grid. \u2022\t Double click the asterisk (*) to include all the columns of the table. \u2022\t Type the field name directly in the required column of the grid. Here, using the first technique, transferred the fields in the Query design grid. Step-8 : \tYou can rearrange the order of the field if you need by clicking and drag- ging the field. Approved by Curriculum Development Center (CDC) 205","Queries in MS-Access Step-9 :\t You can hide unnecessary column by clearing the check mark and unhide by clicking once on check box. Here, Department field is unchecked means it is hiding. Step-10 : You can arrange records in ascending or descending order using 'Sort' field. Choose the field to sort, Choose the 'Ascending' or 'Descending' from the corresponding Sort box by clicking the drop down arrow. In this example, it is going to arrange the Ename field in ascending order. You can extract records using the criteria field as follows: \u2022\tYou can extract records using the certain criteria. Here, it is used to extract those records whose salary is above 25000. \u2022\tYou can extract records of only females using the criteria as given below. 206 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 \u2022\tYou can extract records of only two departments, IT and Admin using the OR operator in the criteria field. \u2022\tYou can extract records using NOT operators. \u2022\t You can extract a range of records using AND operators. \u2022\t You can make calculations with a query. Here it is calculated 10% allowance of \t BSal. \u2022\tYou can extract records using wild card character \\\"*\\\" with Like operator. In this example, records are extracted whose name start with 'R' character. \u2022\tYou can extract records using wild card characters \\\"?\\\" with Like operators. Here, records are extracted whose name having 'm' character in the third position. Approved by Curriculum Development Center (CDC) 207","Queries in MS-Access Saving Query To save a query, do the following steps. Steps to follow: Step-1\t: \tClick the file tab and select the 'Save' option. -or- \t\t Click the 'Save' button on the Quick Access Tool bar. If you are saving query first time, the 'Save As' dialog box appears. Step-2 : Type the 'Query Name' and click 'Ok'. Running Query After creating the query, we should run to get its result. To run the query, do the following steps: Steps to Follow: Step-1 : Click the 'Run' button in the 'Results' group of the 'Design' tab. Action Queries The query which can change in the existing data is called Action Query. Action queries are used to change data based on some set of criteria. It can delete records, update data, append records and make new tables. Here, we discuss about update and delete queries: Update Query: The Query which updates specified values in a table for all records or for those records that match a specified criteria is called Update Query. It is an action query. For example, if you want to increase the BSal by 10% to all the employees, then you can use update query to update all the records at once. To create a update query for this example, follow these steps: Steps to Follow: Step-1\t: \t Open the table Sal. Step-2 : Click the 'Create' tab, from 'Queries' group, select the 'Query Design' button. Step-3\t :\t Select 'Sal' Table and click 'Add' button from 'Show Table' dialog box. 208 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Step-4\t:\t From the 'Query Type' group of 'Design' tab. Select the 'Update' button You get update Query window. Step-5 : Includes field names. Step-6 : Type the expression given in 'Update To' row : [BSal]*10\/100 Step-7 :\t Run the query. Stpe-8 : Conformation message box appears, click 'Yes'. You will notice, all the re- cords will be updated. Delete Query: 'Delete' query is an action query that deletes a set of records according to criteria you specify. For example, create a delete query to delete those records whose salary below is 30000. For this case, follow these steps: Steps to Follow: Step-1\t: \t Open the table 'Sal' which you have created. Step-2 : Click the 'Create' tab, from 'Queries' group, select the 'Query Design' button. Step-3\t :\t Select 'Sal' Table and click 'Add' button from 'Show Table' dialog box. Step-4\t:\t Select the 'Delete' type button from the 'Query Type' group of 'Design' tab. You get Delete Query window. Step-5 : Include field names as given in picture. Step-6 : Type the given expression in 'Criteria' row as given in the picture. Step-7 :\t Run the query. Stpe-8 :\tConformation message box appears, click 'Yes'. You will notice, all the records will be deleted. Insert Query 'Insert Query' is an append query which adds one record in every query execution. To create insert query, follow these steps: Approved by Curriculum Development Center (CDC) 209","Queries in MS-Access Steps to Follow: Step-1\t: \t Open the table BSal. Step-2 : Click the 'Create' tab, from 'Queries' group, select the 'Query Design' button. Step-3\t:\t Close the 'Show Table' dialog box. Step-4\t:\t From the 'Results' group of 'Design' tab, select the 'SQL View' button. You get a SQL view window. Step-5 : Type the INSERT INTO statement as given based on the SAL table. Step-6 : Save the Query. Step-7 :\tRun the query. While running the query, you get some conformation message, you may make a positive response. WILDCARD CHARACTERS AND OPERATORS IN QUERY A wildcard character is used to substitute one or more characters in a string. Wildcard characters can be used to extract specific records with the queries. Common wild card characters and their examples are tabulated below: Wildcard Description Examples * Represents zero or more characters bl* finds bl, black, blue, blob, etc. ? Represents a single character h?t finds hot, hat, and hit, etc. [] Represents any single character within the brackets h[oa]t finds hot and hat, but not hit ! Represents any character not in the brackets h[!oa]t finds hit, but not hot and hat - Represents a range of characters c[a-b]t finds cat and cbt 2#5 finds 205, 215, 225, 235, 245, 255, # Represents any single numeric character 265, 275, 285, and 295 An operator is a sign or symbol that specifies the type of calculation to perform within an expression. Access supports a variety of operators, including arithmetic operators such as +, -, multiply (*), and divide (\/), in addition to comparison operators for comparing values, text operators for concatenating text, and logical 210 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 operators for determining true or false values. Common operators and their examples are tabulated below: Operators Example Description Extract records having value below 25000 < <25000 Extract records backward the date 05\/15\/2020 <05\/15\/2020 or # 05\/15\/2020# Extract records having value below or equal to 25000 Extract records backward from the date 05\/15\/2020 <= <=25000 Extract records having value above 25000 <=05\/15\/2020 or # 05\/15\/2020# Extract records having value above or equal to 25000 Extract records having value 25000 > >25000 Extract records having value except \\\"Officer\\\" Extract records having value below between 10000 and >= >=25000 20000 Extract records having value either \\\"Officer\\\" or \\\"Assis- = =25000 tant\\\". Extract records having value below above or equal to <> <>\\\"Officer\\\" 25000 and below or equal to 50000. Extract records having value either \\\"BHAKTAPUR\\\" or Between \\\"KATHMANDU\\\". Between 10000 AND 20000 ..AND ... IN IN (Officer\\\" \\\"Assistant\\\") AND >=25000 AND <=50000 OR \\\"BHAKTAPUR\\\" OR \\\"KATHMANDU\\\" Points to Know \u2022\t Query refers to a request that you can ask about data stored in a database table. \u2022\t Types of queries supported by Access are: i) Select Queries ii) Action Queries \u2022\t A select query selects the data you want from one or more tables. \u2022\t Action queries can delete records, update data, append records and make new tables. \u2022\t Update Query updates specified values in a table for all records or for those records that match a specified criteria. \u2022\t A delete query is an action query in Access that deletes a set of records according to criteria you specify. \u2022\t Wildcard characters can be used to extract specific records with the queries. Terms to Know Query\t: \tA question, or requesting information. Wildcard character\t : \tSpecial characters that can stand for unknown characters in a text value. Append\t : \tAdding record at the end. Approved by Curriculum Development Center (CDC) 211","Queries in MS-Access Questions types marked by * are just for testing Worksheet higher ability but can Objective Questions enhance the knowledge 1. Match the following: for SEE. a. \tExtract or display records b. Technique to design query Append Query c. \t Update\/Delete query d.\t Insert record query Action Query Select query Query Wizard Descriptive Questions 1. Write short answer of the following questions: a.\t What is a query? b.\t Why do you use query? c.\t What is select query? d. \t What is 'wild card characters'? e.\t Why are wild card characters used? f.\t What is insert record query? g. \t What is delete query? h.\t What is update query? i.\t What is action query? j.\t What does it mean to run a query? Case Study and Application Based Questions* 1. \tOn the basis of the given picture of query design grid, what changes do you make in the grid to perform the given tasks? i) \t To display only Sn. and Ename. Ans: ............................................................................................................................ 212 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 ii) \t To display only female employees. Ans: ............................................................................................................................ iii) \t To display complete records of only 'male' employees. Ans: ............................................................................................................................ iv) \t To display records of only 'Admin' department. Ans: ............................................................................................................................ v) \t To display only those records whose gender is female and works in 'Admin'. Ans: ............................................................................................................................ vi)\t To display all the records in ascending order on the basis of e_name field. Ans: ............................................................................................................................ vii) \tTo display those records whose salary is above 20000 and below 50000. Ans: ............................................................................................................................ 2. \tOn the basis of the given picture of query design grid, what changes do you make in the grid to perform the given tasks? i) \t To increase the Bsal by 1500 of all the records. Ans: ............................................................................................................................ ii) \t To increase the Bsal by 2000 of female employees in all the records. Ans: ............................................................................................................................ iii)\t To increase the BSal by 15% of those records having BSal is below 25000. Ans: ............................................................................................................................ 3. \tOn the basis of the given picture of query design grid, what changes do you make in the grid to perform the given tasks? Approved by Curriculum Development Center (CDC) 213","Queries in MS-Access i) \t To delete those records having BSal is above 45000 and 5000. Ans: ............................................................................................................................ ii) \t To delete those records whose post is 'officer'. Ans: ............................................................................................................................ iii)\t To delete those records having gender is male and BSal is below 30000. Ans: ............................................................................................................................ Lab Activity-1 1. \tDesign a table named 'Emp_Sal' and add records as given below, and perform the mentioned tasks: i)\t Set the primary key on the 'Sn' field. ii)\t Create a query to display only Sn., Ename and BSal. iii) \t Create a query to display records of only 'male' employees. iv) \t Create a query to display of only 'female' employees. v) \t Create a query to display records of 'officers' and 'Managers'. vi) \t Create a query to display those records whose gender is 'female' and works in 'Admin' department. vii)\t Create a query to display all the records in ascending order. viii) \tCreate a query to display those records whose salary is above 20000 and below 50000. ix) \t Create a query to display records having salary is greater than or equal to 30000 and less than or equal to 40000. x) \t Create a query to display all the records whose post is except 'Manager' and 'Officer'. xi)\t Create a query to display all the records of only female 'officers'. 214 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Lab Activity-2 1. \tDesign a table named 'Emp_Sal' and add records as given below, and create queries to perform the mentioned tasks: i)\t To increase the salary by 10% in existing salary. ii) \t To change the post of 'Peon' to 'Office Helper'. iii)\t To upgrade the salary of 'Indian' and 'Chinese' by 25% of existing salary. Lab Activity-3 1. \tDesign a table named 'Emp_Sal' and add records as given below, and create queries to perform the mentioned tasks: i)\t To delete those records whose nationality is 'Chinese'. ii) \t To delete those records whose salary is between 30000 to 40000. iii)\t To delete those records who joined before the 1st Jan 2015. iv)\t To delete those records whose nationality is except 'Nepali' v)\t To delete those records whose 'Salary' is above or equal to 40000 and below 50000. vi)\t To add record query having the data set : '17-Jan-2015', 'Rahul', 'Nepali', 'Officer', '44000'. Approved by Curriculum Development Center (CDC) 215","Queries in MS-Access Lab Activity-4 1. \tConsider the following table that you have already created in previous lab activities then create queries to perform the mentioned tasks: i)\t To display those records whose name starts with 'R'. ii) \t To display those records whose name have second character is 'a' or 'u'. iii)\t To display those records having third character is 'n'. iv) \t To display females' records having second character is 'u' in the name. v) \t To display complete records of except 'marketing' and 'IT' departments. vi) \t To display records of only females who are associated with 'Admin' and 'Marketing' department. 216 Approved by Curriculum Development Center (CDC)","Creating Forms & Reports Smart Computer Science Book-10 Chapter Includes CHAPTER \u2022\t Introduction to Form \u2022\t Creating Form 12 \u2022\t Entering and Modifying Data with Form \u2022\t Introduction to Report \u2022\t Create Report using Report Wizard \u2022\t Printing Report INTRODUCTION OF FORM A form is a database object that you can use to create a user interface for the MS- Access database application. Form helps you to display live data from the table. It is mainly used to make data entry or editing task easy. It provides an easy way to enter, edit, delete and view data in a table. There are four ways to create a form in Access : i) Form Command\t ii) Form Wizard\t iii) Form Design\t iii) Blank Form We study to create a form using the form wizard in this lesson. Creating Form with Form Wizard. The Form wizard is an easy method to create a form in the Access. The Form Wizard gives you more control to perform the tasks. The wizard lets you make decisions about certain aspects of a form's design and produces a form based on your instructions. To create a form based on a single table using the Form Wizard, follow these steps. Steps to Follow: Step-1 : \tClick on the 'Create' tab in the 'Forms' group, click 'Form Wizard'. The wizard starts. Step-2 : \tFrom the 'Tables\/Queries' drop-down list, select the table or query to base the form on. The fields for the selected table loaded in the 'Available Fields 'list box as given below: Approved by Curriculum Development Center (CDC) 217","Creating Forms & Reports Step-3\t: \tMove the fields to include on the form from the Available Fields list box to the Selected Fields list box. To do so, double-click a field name to move it or select the field name and click >. To move all fields at once, click >>. Here, all the fields are moved: 218 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Step-4: Click Next >. You get Form Wizard layout dialog box as given. Step-5 :\tSelect the layout for the form. Your options are \\\"Columnar\\\", \\\"Tabular\\\", \\\"Datasheet\\\", and \\\"Justified\\\". Tip: Select each of the options to see a preview of the form layout before you make a final selection. Step-6 :\t Click Next >. You get the following dialog box. Approved by Curriculum Development Center (CDC) 219","Creating Forms & Reports Step-7 :\t Enter a title for the form. Step-8 :\t Select an option for viewing to open the form. Your options are: \u2022\t Open the form to view or enter information (opens in Form view). \u2022\t Modify the form's design (opens in Design view). Step-9 : Finally,click Finish button. The form loads in the view as you selected. First Record Previous Record Blank Record Next Record Last Record Entering and modifying data using Form In MS-Access, using 'form' you can enter new records and modify the records as you like. To do this, follow these steps: To add a new record: There are two ways to add a new record with the form: Method-1 : In the Records group on the Home tab of the Ribbon, click the New command. Method-2 \t: On the Record Navigation bar at the bot- tom of the window, click the New Record button. 220 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 To find an existing record to view or edit: There are two ways to find and view an existing record using a form, and they both use the navigation bar at the bottom of the screen: Method -1 : To look through records one at a time, click the navigation arrows. The right arrow will take you to the next record, and the left arrow will take you to the previous one. Method-2 : To search for a record, type a word you know is contained in that record in the navigation search box. To save the current record: Step-1 : Select the Home tab and locate the Records group. Step-2 : Click the Save command. The current record will be saved. To delete the current record: Step-1 : Select the Home tab and locate the Records group. Step-2 : Click the Delete command. Step-3 : A dialog box will appear. Click the 'Yes' button. Step-4 : The record will be permanently deleted. 221 Approved by Curriculum Development Center (CDC)","Creating Forms & Reports INTRODUCTION OF REPORT Report is a database object of the Ms-Access which presents the information in an attractive and organized format for printing and online display. Report offers a way to view, format, and summarize the information in your Microsoft Access database's Table\/Queries. A report consists of information that is pulled from tables or queries, as well as information that is stored with the report design, such as labels, headings, and graphics. Create Report Using Report Wizard You can also use the Report Wizard to create a report. The Report Wizard provides you with more flexibility than you get by using the Report button. The Report wizard allows you to select the tables and fields, group, sort, summarize the data, choose a layout and orientation, apply a style, and set the title in your report. Go through the following steps to create a report by using the Report Wizard: Steps to Follow: Step-1 : Open the database. Step-2 : Activate the Create tab. Stpe-3 : Click Report Wizard in the Reports group. The Report Wizard appears. Step-4 : \tClick the drop down-arrow next to the Table\/Query field and then select the table from which you want to select fields. 222 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Step-5 : \tInclude the fields. Select a field and then click the single-right arrow > to include a single field, click the double-right arrows >> to include all the fields, Select a field and then click the <single-left arrow to exclude a single field, or click the << double-left arrow to exclude all fields. Step-6 :\t Click Next. The Report Wizard moves to the next page. Step-7 :\t Click to select the field by which you want to group your data. Step-8:\tClick Next. The Report Wizard moves to the next page. Approved by Curriculum Development Center (CDC) 223","Creating Forms & Reports Step-9 :\t Click the down-arrow and then select the field you want to sort by. Step-10 : Click the button to choose ascending or descending order. Clicking the button toggles between Ascending and Descending. You can sort up to four levels. Step-11 : Click Next. The Report Wizard moves to the next page. Step-12 : Select 'Layout' and 'Orientation' as you. Step-13 : Click the 'Next' button to move to the next page of the Report Wizard. 224 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Step-14 : Type the 'Title' name. In this example, title name is typed 'Salary Sheet'. Step-15 : Click the 'Finish' button. You notice the Report of your database table as given below. PRINTING A REPORT After creating report, you may print on the paper. To do this, follow these steps. Steps to Follow: Step-1: Make sure to activate the 'Print preview' tab. If it is not active, right mouse click on the 'Report name' from the left navigation pane and click the 'Print Preview' option from the context menu. \t or \t\t Click the 'Print Preview' button on the right side of the status bar of the Report Window. Step-2 : Select the desired option and click the 'Print' button. You get the Print dialog box. Approved by Curriculum Development Center (CDC) 225","Creating Forms & Reports Step-3 :\t Select the required options and click the 'ok' button. Points to Know \u2022\t A form is a database object that you can use to create a user interface for a database application. \u2022\t The Form wizard is an easy method to create a form in the Access. \u2022\t There are four ways to create a form in Access : \t i) Form Command\t\t ii) Form Wizard\t iii) Form Design\t\t iii) Blank Form \u2022\t Report is a Database object of the MS-Access which presents the information in attractive and organized format for printing and online display. \u2022\t Report offers a way to view, format, and summarize the information through your Microsoft Access database. \u2022\t You can also use the Report Wizard to create a report. The Report Wizard provides you with more flexibility than you get by using the Report button. Terms to Know Form\t: \t An object for viewing, entering, editing and deleting data in a table. Object that presents data in an easy to read, printable and online\/offline display format. Report\t :\t A part of a program that guides you through certain steps to perform a task. Wizard\t :\t 226 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Worksheet Questions types marked by * are just for testing Objective Questions higher ability but can 1. Match the following: enhance the knowledge for SEE. a. \tProduced report on paper Form Wizard b. Method of creating report Form c. \t Presents the information on organized form Print report d.\t Method to create form Report Wizard Report e.\t Interface for database application\t\t\t Descriptive Questions 1.\t Write short answer of the following questions: a.\t Why do you generate the report? b.\t How do you create report? c.\t What is report? d. \t Why is report created? e.\t How do you enter and modify data using form? f.\t What is form? g. \t How do you create a form? h.\t Why do you create a form? Case Study and Application-based Questions* 1. \tOn the basis of the given picture, answer the asked questions: i) \t How do you get this dialog box? Ans: .............................................. ....................................................... ....................................................... ....................................................... Approved by Curriculum Development Center (CDC) 227","Creating Forms & Reports ................................. ii) \t Why do you use 'Tables\/Queries' drop down box? Ans: ............................................................................................................................ iii) \t Why do you use > button ? Ans: ............................................................................................................................ iv) \t Why do you use >> button? Ans: ............................................................................................................................ v)\t If you click 'Finish' button, what result will you get? Ans: ............................................................................................................................ vi) \t Why do you press 'Next' button? Ans: ............................................................................................................................ 2. \tOn the basis of given picture of a form, answer the asked questions: i) \t How do you get this form? Ans: ........................................... .................................................... .................................................... .................................................... .................................................... ................................................... .................................................... .................................................... ii) \t Which type of layout is used in this form? Ans: ............................................................................................................................. iii) \t Which record number is displayed in this form? How many records are there? Ans: ............................................................................................................................. iv) \t How do you move to the next following record? 228 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Ans: ............................................................................................................................. v)\t Can you shift to the last record in a single click? If yes, Mention your technique. Ans: ............................................................................................................................. ................................................................................................................................ vi) \t How do you move to the first record from the current position? Ans: ............................................................................................................................. vii)\t How do you add a new record? Ans: ............................................................................................................................. ..................................................................................................................................... viii)\tHow do you move to the specific record number? Ans: ............................................................................................................................ ix) Is it possible to change the layout? If yes, mention the technique. Ans: ............................................................................................................................ ..................................................................................................................................... ..................................................................................................................................... 3. \tOn the basis of given picture, answer the asked questions: i) \t What is the name of this dialog box? Ans: ......................................... ................................................. ii) \t How do you get this dialog box? Ans: .......................................... .................................................. .................................................. .................................................. .................................................. ........................................... iii) \t What is the purpose of this dialog box? Ans: ............................................................................................................................. Approved by Curriculum Development Center (CDC) 229","Creating Forms & Reports iv) \t What do you mean by layout? Ans: ............................................................................................................................. ..................................................................................................................................... v)\t What do you mean by orientation? Ans: ............................................................................................................................ ..................................................................................................................................... vi) \t Differentiate between 'Portrait' and 'Landscape' orientation? Ans: ............................................................................................................................ ..................................................................................................................................... ..................................................................................................................................... vii)\t What do you mean by 'Justified' layout? Ans: ............................................................................................................................. ..................................................................................................................................... viii)\tWhat is the difference between checked and unchecked radio button? Ans: ............................................................................................................................. ..................................................................................................................................... ix) What happens when you click the 'Finish' button? Ans: ............................................................................................................................. ..................................................................................................................................... x) What happens when you click 'Next' button? Ans: ............................................................................................................................. ..................................................................................................................................... xi) When do you use 'Back' button? Ans: ............................................................................................................................. ..................................................................................................................................... xii) What is the role of 'Cancel' button? Ans: ............................................................................................................................. ..................................................................................................................................... 230 Approved by Curriculum Development Center (CDC)","Lab Activity-1 Smart Computer Science Book-10 1.\t a. Create a database named \u201cStudent\u201d validation rule which allows entering the marks and create a table named \u201cMarks\u201d under between 0 to 100.\t the database \u201cStudent\u201d with the following d. \t Prepare a query named \u201cQuery1\u201d to display the structure: records of only male students.\t e. \t Prepare a query named \u201cQuery2\u201d to display all Field Name\t\t Data Type the records with calculating total and percentage marks.\t Roll No\t\t\tNumber \t Where Total = English + Nepali + Science f. \t Prepare a report on the basis of query created in Name\t\t\tText question 1(d). g. \t Prepare the query to display records of only Gender\t\t\tYes\/No females. h. \t Create a form to input more records for the above English\t\t\tNumber created table and add more two records. i. \t Create a report for the query created in the Q. (g) Nepali\t\t\tNumber Science\t\t\tNumber b. Set the primary key in the 'Roll No' field. c. Add five records in the \u2018Marks\u2019 table. Set the data Lab Activity-2 1. a. \tCreate a database named \\\"Salary\u201d and 12000.\t Create a table named \u201cTable1\u201d using the e. \t Create a report on the basis of \u201cQuery1\u201d created following structure:\t in Q(c). Field Name\t\t Data Type f. \t Create a form for the above table and enter more Empcode\t\t Number 5 records.\t\t h. \t Create an update query to increase the salary by Name\t\t\tText Rs. 2000 of existing salary. Marital Status\t\t Yes\/No i. \t Insert a new field \u2018Gender\u2019 just before the \u2018Marital Salary\t\t\tCurrency Status\u2019 and enter the respective gender. j. \t Create a report for the above created table b. \tInput at least five data.\t \u2018Table1\u2019 c. \tCreate \u201cQuery1\u201d to display all the data for those k. \t Create a form to input more records and add who are married.\t more five records. d.\tCreate \u201cQuery2\u201d to display all the data for those who are getting salary between 7500 to Approved by Curriculum Development Center (CDC) 231","Creating Forms & Reports Lab Activity-3 1. a.\tCreates a database named b.\t Create a form using the above table with the help \u201cSchool\u201d and create a table named of \u201cform wizard\u201d.\t \u201cResult\u201d using the following c.\t Input at least five data using the above created structure: form. Field Name\t\t Data Type d.\t Create \u201cQuery1\u201d to display those data where name starts with \u201cA\u201d. CodeNum\t\t Number e.\t Create \u201cQuery2\u201d to display all the data with FirstName\t\t Text Percentage. LastName\t\t Text f. \t Create a query to display whose percentage is below 50. English\t\t\tNumber g.\t Create a form using 'Form Wizard' and add more Nepali\t\t\tNumber 5 records. h.\t Create a report for the table 'Result'. Math\t\t\tNumber Lab Activity-4 1.\t a.\t Create a database named \u201cSales\u201d d.\t Create \u201cQuery1\u201d to display all the data for the and create a table named \u201cReport\u201d month of \u201cJanuary\u201d. using the following structure: e.\t Create \u201cQuery2\u201d to display all the data with commission 10% of Sales. Field Name\t\t Data Type f.\t Create an update query to edit the last name Codenum\t\t\tNumber which is entered \u2018Shrestha\u2019 which should be \u2018Maharjan\u2019. FirstName\t\t Text g.\t Create a delete query to delete those records LastName\t\t Text having last name is \u2018RAI\u2019. Month\t\t\tText h. \t Create a report for the above created table \u2018Report\u2019. Sales\t\t\tCurrency b.\t Create a form using the above table with the help of \u201cform wizard\u201d. c.\t Input at least five data using the above created form. 232 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 rogramming CHAPTER R QBASIC Peview 13Chapter Includes \u2022\t Introduction to QBASIC \u2022\t Program control structure of QBASIC \u2022\t Sequential structure \u2022\t Selection Structure \u2022\t Loop structure \u2022\t Library Function INTRODUCTION QBASIC stands for \u201cQuick Beginners All-Purpose Symbolic Instruction Code\u201d. QBASIC was developed by Microsoft Corporation in the year 1991. It is considered to be one of the most easy-to-understand programming languages for beginners. It is suitable for solving both mathematical and business problems and it has been adopted by most of the micro computers. QBASIC is a replacement of the GWBASIC (Greg Whitten \u2013 BASIC). QBASIC is only compatible with MS-DOS Environment on windows, it usually contains two files: 1.QBASIC.EXE and QBASIC.HLP. These two files help us to debug, edit and execute code in the DOS environment. QBASIC doesn\u2019t produce .exe file, the files are saved with .bas extension. PROGRAM CONTROL STRUCTURE Program control structures are just a way to specify the flow of control in programs. Any algorithm or program can be more clear and understood, if they use self-contained modules called as logic or control structure. It basically analyzes and chooses in which direction a program flow is based on certain parameters or conditions. There are three basic types of logic, or flow of control: i) Sequential structure\t\t ii) Selection Structure\t\t iii) Loop Structure Sequential Structure Sequential structure refers to the line by line execution, in which statements are executed sequentially, in the same order in which they appear in the code. They might carry out a series of read or write operations, arithmetic operations, or assignments to variables. Approved by Curriculum Development Center (CDC) 233","Review QBASIC Programming b. CLS INPUT\\\"Enter Name:\\\";N$ Examples: INPUT\\\"Enter Address:\\\";A$ a. CLS PRINT A$ PRINT B$ QP = 500 END RP = 10 TA = QP * RP D = 10 * TA \/ 100 NT = TA - D PRINT \\\"Total Amount=\\\"; TA PRINT \\\"Discount=\\\"; D PRINT \\\"Net Total=\\\", NT END Sample Programs and find their sum, product and difference. 1. \tWrite a program to ask any two CLS numbers and find their sum. INPUT \\\"Enter two numbers:\\\"; A, B REM : Example of sequential structure S=A+B CLS D=A-B INPUT \\\"Enter first number:\\\";A P=A*B INPUT \\\"Enter second number:\\\";B PRINT \\\"Sum=\\\"; S S=A+B PRINT \\\"Difference=\\\"; D PRINT \\\"Sum=\\\"; S PRINT \\\"Product=\\\"; P END END 2. \tWrite a program to ask two numbers Test Your Skill 1. \t Write a program to ask principal amount, time and rate then find the simple interest. SI= (P*T*R)\/100. 2. \t Write a program to ask a number and display its square value. 3.\t Write a program to ask length and breadth of a rectangle and find out its area. Hint-: A=L*B. 4. \t Write a program to ask quantity and rate of pen and find out total amount. 5.\t Write a program to ask three numbers and find their average and sum. 6.\t Write a program to ask your name, address and telephone number and print them. 7.\t Write a program to ask a number and divide by 2 and print quotient. 8.\t Write a program to ask Kilometer and convert into meter. 234 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Selection Control Structure : This structure depends on whether condition is true or false. The decision control structure may skip the execution of an entire block of statements or even execute one block of statements instead of another. Basically, QBASIC supports two types of selection control statements: i) IF statement\t\t ii) SELECT CASE statement Sample Programs 1. Write a program to ask your average marks and find out whether you are passed or failed. If average marks is above 50, you are passed, otherwise failed. CLS INPUT \u201cEnter Average Marks:\u201d; AV IF AV>40 THEN PRINT \u201cYou are Passed\u201d ELSE PRINT \u201cYou are Failed\u201d END or 3.\tWrite a program to ask 5 subject marks and find out whether you are CLS failed or passed. If any one subject INPUT \u201cEnter Average Marks:\u201d; AV marks is below 40, you are failed oth- IF AV>40 THEN erwise passed. PRINT \u201cYou are passed\u201d ELSE CLS PRINT \u201cYou are failed\u201d INPUT \\\"Enter 5 subject marks:\\\"; A, B, END IF C, D, E END IF A < 40 OR B < 40 OR C < 40 OR D < 40 OR E < 40 THEN 2.\t Write a program to ask any three num- \t PRINT \\\"You are failed\\\" bers and find out greatest numbers. ELSE \t PRINT \\\"You are Passed\\\" \tCLS END IF INPUT \\\"Enter first number:\\\"; A END INPUT \\\"Enter second number:\\\"; B INPUT \\\"Enter Third number:\\\"; C 4. \tWrite a program to ask your age and IF A > B AND A > C THEN find out whether you are old or not. If \t PRINT \\\"Greatest is :\\\"; A age is above 60, you are old, other- ELSEIF B > A AND B > C THEN wise you are not old. \t PRINT \\\"Greatest is :\\\"; B CLS ELSE INPUT \u201cEnter Your Age:\u201d;A \t PRINT \\\"Greatest is :\\\"; C SELECT CASE A END IF END Approved by Curriculum Development Center (CDC) 235","Review QBASIC Programming \t CASE IS>60 number\\\". \t\t PRINT \u201cYou are Old\u201d CLS \t CASE ELSE INPUT \\\"enter Lucky number:\\\"; L \t\t PRINT \\\"Not Old\\\" SELECT CASE L END SELECT \t CASE 3, 7, 11 END \t\t PRINT \\\"It is my lucky \t 5. Write a program to ask a character number.\\\" and find out whether input character \t CASE ELSE is capital, small or other character. \t\t PRINT \\\"It is not my lucky CLS number.\\\" INPUT \u201cEnter a character:\u201d;C$ END SELECT SELECT CASE C$ END \t CASE \u201cA\u201d TO \u201cZ\u201d 8. Write a program to ask principal amount and time. The program should \t\t PRINT \u201cCapital letter\u201d calculate simple interest on the basis of given rate: \t CASE \u201ca\u201d TO \u201cz\u201d \t\t PRINT \u201cSmall letter\u201d \t CASE ELSE Time(in year)\t\t\tRate(%) \t1\t\t\t\t6 PRINT \u201cOther character\u201d \t2\t\t\t\t8 \t3\t\t\t\t10 END SELECT \t>3\t\t\t\t12 END 6.\t Write a program to ask a character and find out whether vowel or constant. \t CLS CLS INPUT \\\"Enter Principal Amount:\\\", P INPUT \\\"Enter Time:\\\", T INPUT \\\"Enter a character:\\\"; C$ SELECT CASE T \t CASE 1 SELECT CASE C$ \t\t R=6 \t CASE 2 \t CASE \\\"A\\\", \\\"E\\\", \\\"I\\\", \\\"O\\\", \\\"U\\\", \\\"a\\\", \t\t R=8 \\\"e\\\", \\\"i\\\", \\\"o\\\", \\\"u\\\" \t CASE 3 \t\t R=10 \t\t PRINT \\\"it is vowels\\\" \t CASE ELSE \t\t R=12 \t CASE ELSE END SELECT SI= (P*T*R)\/100 \t\t PRINT \\\"It is not vowel\\\" PRINT \u201cSimple interest=\\\"; SI END END SELECT END 7.\t Write a program to ask a number and find out that is your lucky number or not. If input numbers are 3,7,11 then message should display \\\"It is my lucky number\\\" otherwise \\\"It is not my lucky 236 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Test Your Skill 1.\t\t Write a program to ask any two numbers and find out smaller number. 2. \t Write a program to ask three numbers and find out middle value. 3.\t Write a program to ask maths and computer marks and find out you can study computer or not. If any one subject is not below 80, you can study computer, otherwise you can not study. 4. \t Write a program to ask a number [1 to 7] and print the day of a week. 1 =SUNDAY, 2=MONDAY respectively. Using SELECT CASE. 5. Write a program to ask quantity of pen, copy and pencil and find out, gross total, discount and net total. NT=GT- discount. The discount is calculated on the basis of the following conditions. \tGT\t\t\tDiscount \t <10000\t\t no discount \t <20000\t\t 5% of GT \t <50000\t\t 8% of GT \t >=50000\t\t 10% of GT 6. Write a program to ask your obtained marks in major five subjects and find out your result. If all the subject marks above 80, you are passed otherwise failed. 7. Write a program to ask a number and find out whether it is even or odd. 8. Write a program to ask a number and find out whether it is multiple of both 5 and 3 or not. 9. Write program to ask a number and find out whether it is negative, positive or zero number. 10. Write a program to ask three sides of a triangle and find out whether the triangle is scalar or not. If all the three sides are not equal, then the triangle is scalar. Loop Control Structure: Loop control structure that allows the execution of a block of statements multiple times until a specified condition is true. QBASIC supports the following loop structures. \t a. FOR-NEXT \t\t b. WHILE-WEND\t\t c. DO - LOOP Sample Programs PRINT \\\"Sum=\\\"; S END 1.\tWrite a program to ask your name and print 10 times. 3.\t Write a program to display first 10 CLS natural numbers. INPUT \\\"Enter your name :\\\"; N$ FOR I = 1 TO 10 CLS \t PRINT N$ FOR I = 1 TO 10 NEXT I \t PRINT I END NEXT I END 2.\tWrite a program to ask 10 numbers 4.\t Write a program to display first 10 and find their sum. natural numbers in the reverse form. CLS CLS FOR I = 1 TO 10 FOR I = 10 TO 1 STEP-1 \t INPUT \\\"Enter number:\\\"; N \t PRINT I \t S=S+N NEXT I NEXT I END Approved by Curriculum Development Center (CDC) 237","Review QBASIC Programming 5.\t Write a program to ask a number and \t PRINT 5 * I; display its multiples. \t I=I+1 LOOP CLS END I=1 INPUT \\\"Enter a Number:\\\"; N 9.\t Write a program to display first 10 WHILE I <= 10 natural numbers with their cube values. PRINT N * I I=I+1 REM: Example of Post Test with WHILE condition WEND CLS END I=1 DO 6.\t Write a program to display 10 to 1 and find their sum. PRINT I ^ 3; I=I+1 CLS LOOP WHILE I <= 10 I = 10 END WHILE I >= 1 \t PRINT I 10. Write a program to display square \t S=S+I roots of first 10 natural numbers. \t I=I-1 WEND REM: Example of Post Test with UNTIL condition PRINT CLS PRINT \\\"Sum=\\\"; S I=1 END DO 7.\t Write a program to display square PRINT SQR(I) values of the first 10 natural numbers. I=I+1 LOOP UNTIL I > 10 REM: Example of Pre-Test with WHILE condition END CLS I=1 11.\tWrite a program to display the given DO WHILE I <= 10 output: \t PRINT I ^ 2; CLS \t I=I+1 LOOP FOR I = 1 TO 5 1 END \t FOR J = 1 TO I 12 \t\t PRINT J; 123 8.\t Write a program to display multiples \t NEXT J 1234 of 5. \tPRINT 12345 NEXT I REM: Example of Pre-Test with UNTIL condition CLS END I=1 DO UNTIL I > 10 238 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Test Your Skill 1. \t To print the word \\\"WELCOME\\\" 10 times. 2. \t To display only even numbers from 2 to 20. 3.\t Write a program to display 20, 18, 16, 14, 12.................2 4. \t Write a program to display 100, 81, 64................1. 5. \t Write a program to display 1, 9, 25, 49.............. up to 10th term. 6.\t Write a program to display 1, 1, 2, 3 5, 8, 13............... up to 10th term. 7. \tWrite programs to display the following patterns: a. \t1 2 3 4 5 b.\t * * * * * c.\t1 d.\t * \t 1234 \t **** \t 21 \t ** \t 123 \t *** \t 321 \t *** \t 12 \t ** \t 4321 \t **** \t1 \t* \t 54321 \t ***** LIBRARY FUNCTION The function which comes automatically with QBASIC system is called Library Function. It is also called built-in function or ready-made function. The library function can be called by programmer in any program to perform a specific task. Library functions are also of different types such as string, mathematical, date and time, Print controls, etc. String Function The function which is used to process or manipulate the string type of data is called string function. A string can be a set of alphanumeric characters or symbols. Some of the common string functions are: i) LEN()\t ii)LEFT$()\t iii) RIGHT$()\t iv)MID$()\t v) LCASE$()\t vi) ASC()\t vii) STR$()\t viii) VAL()\t ix) LTRIM$()\t x) RTRIM$()\t xi) STRING$()\t xii) SPACE$\t xiii) OCT$()\t xiv) HEX$()\t xv) INKEY$() xvi) INPUT$()\t xvii) DATE$()\t xviii) TIME$()\t xix) CHR($) Sample Programs 2. \tCLS 1. \tCLS \tA=10 \t W$ = \\\"PATAN\\\" Output \tB=20 Output \t PRINT A+B \t PRINT LEFT$(W$, 2) \t PRINT RIGHT(W$,2) \t A$=STR$(A) \t PRINT MID$(W$,2,2) \t B$=STR$(B) \t PRINT LCASE$(W$) \t PRINT A$+B$ \tEND \t PRINT VAL(X$+Y$) \tEND Approved by Curriculum Development Center (CDC) 239","Review QBASIC Programming 3. \tCLS Output 8.\tCLS Output \t PRINT CHR$(65) \t PRINT OCT$(32) \t PRINT CHR$(66) \t PRINT HEX$(44) \t PRINT ASC(\\\"A\\\") \t PRINT HEX$(47) \t PRINT ASC(\\\"B\\\") \tEND \tEND 9.\tCLS \t PRINT \\\"Press any key to continue.....\\\" 4. \tCLS Output \t DO WHILE INKEY$=\\\"\\\" \t W$(\\\" MEMORICA \\\") \tLOOP \t PRINT \\\"**WELCOME**\\\" \t PRINT LEN(W$) \tEND \t PRINT LEN(LTRIM$(W$)) Output .................................................. \t PRINT LEN(RTRIM$(W$)) 10.\tCLS \t PRINT \\\"Enter characters\\\" \tEND \t X$ = INPUT$(5) \t PRINT X$ 5.\tCLS \tEND \t PRINT STRING$(10, 35) \t W$=STRING$(10, 42) Output .................................................. \t PRINT W$ \t PRINT STRING$(10, \\\"*\\\") \tEND Output .................................................. 6.\tCLS 11.\tCLS \t PRINT INSTR(1, \\\"IT IS FUN\\\", \\\"FUN\\\") \t PRINT DATE$ \t X$=\\\"RAJA RAMAN DEVKOTA\\\" \t INPUT \\\"Enter date [mm-dd-yyyy]:\\\"; D$ \tY$=\\\"RAMAN\\\" \t DATE$ = D$ \t PRINT INSTR(X$,Y$) \t PRINT \\\"New Date\\\"; DATE$ \tEND \tEND Output .................................................. Output .................................................. 7.\tCLS Output 12.\tCLS \t FOR i = 1 TO 5 \t PRINT TIME$ \t S$ = SPACE$(i) \t INPUT \\\"Enter Time [hh:mm:ss]:\\\"; T$ \t TIME$ = T$ \t\t PRINT S$; I \t PRINT \\\"New Time\\\"; TIME$ \tNEXT \tEND \tEND Output .................................................. Note: TIME$ statement and Date$ statement may not support in MAC or Linux version of QBASIC. 240 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Test Your Skill 1. \t Write programs to display the following patterns: f. \t L \tA a. \tNEPAL b. \tN c. \tN d. \tNEPAL e. \tL \tP \tAL \tE \tNEPA \tE \tNE \tEPAL \tPAL \tN \tEPAL \tNEP \tP \tNEP \tPAL \tNEPAL \tNE \tA \tNEPA \tAL \tN \tL \tNEPAL \tL 2. Write a program to ask a word and display in reverse order. 3. Write a program to ask a word and find out whether it is a palindrome or not. 4. Write a program to ask a word and display value of each character. 5. Write a program to display the ASCII code character of each number from 0 to 255. 6. Write a program to ask a number and find out sum of digits. Using STR$(), VAL() function. 7. Write a program to ask a word and find out total vowels and consonants. MATHEMATICAL FUNCTION The function which is used to process the mathematical operation is called mathematical function. Some of the common mathematical functions are: i) SQR()\t ii) SGN()\t iii) ABS()\t iv) INT()\t v) CINT() vi) COS()\t vii) SIN()\t viii) TAN() Sample Programs 3. CLS \t FOR I = 1 TO 5 1.\tCLS Output \t READ A, B, C, D \t\t READ N \t\t SR = SQR(N) \t PRINT SQR(A) \t\t IF SR = INT(SR) THEN S = S+N \t NEXT I \t PRINT SGN(B) \t PRINT S \t DATA 10,16,9,4,6 \t PRINT SGN(C) \tEND \t PRINT ABS(D) Output .................................................. \t DATA 4, -9, 16, -25 4. CLS \t FOR I = 1 TO 5 \tEND \t\t READ N 2.\t CLS Output \t\t PRINT N, CINT(N) \tA=90 \t NEXT I \t R=A*3.1416\/180 \t DATA -10.5,-20.65,5.9,-5.3,4.5 \t PRINT COS(R) \tEND \t PRINT SIN(R) \t PRINT TAN(R) Output .................................................. \tEND Approved by Curriculum Development Center (CDC) 241","Review QBASIC Programming PRINT CONTROL FUNCTION AND STATEMENT Print control functions and statements are used to specify and control the location of the screen to print the information. The common print control function and statement. i) TAB()\t ii) SPC ()\t iii) LOCATE statement iv) PRINT USING statement Sample Programs Output 3. \tCLS \tA=5 1.\tCLS \t FOR I= 1 TO 5 \t PRINT TAB(4);\\\"RAM\\\" \t\t PRINT USING \u201c#####.##\u201d;A \t PRINT SPC(4); \\\"KRISHNA\\\" \t\t A=A*10+5 Output \t LOCATE 5, 3 \t NEXT I \t PRINT \\\"MURARI\\\" \tEND \tEND 2. CLS \tREM: Illustration of the function of PRINT USING 4. \tCLS \tA=55555 \tN=1 \t FOR I= 1 TO 5 \t\t PRINT USING \u201c########,#\u201d;A \t FOR I= 1 TO 5 \t\t A=(A-5)\/10 Output \t NEXT I \t\t PRINT USING \u201c#####\u201d;N \tEND \t\t N=N*10+1 Output \t NEXT I \tEND Test Your Skill 1. \t Write programs to display: a) \t NEPAL b) \tN c) \t N d) \t NEPAL e) \t L \tNEPA \t E \tNE \tEPAL \tAL \tNEP \t P \tNEP \tPAL \tPAL \tNE \t A \tNEPA \tAL \tEPAL \tN \t L \tNEPAL \tL \tNEPAL f ) N E PA L g ) P \t\th\t) *\t\t\t\ti) \t \t*\t \t \t *\t \t EPA \tEPA * \t *\t \t* *\t *\t * P \tNEPAL \t ** 2. Write a program to display only perfect * root numbers from* 1 to 100. * square 3. Write a program to ask 5 digits number and display with comma and 2 decimal places formatting. 242 Approved by Curriculum Development Center (CDC)","Worksheet Smart Computer Science Book-10 Descriptive Questions 1.\t Write short answer of the following questions: a.\t What is QBASIC? b.\t What is program control structure? c.\t Write short note on: \t i) Sequential structure\t ii) Selection Structure\t iii) Loop Structure d. \t What is library function? e. \t What is string function? f. \t What is mathematical function? Application Based Questions f.\t What is the purpose of this program? 1. Study the following programs and Ans: ....................................................... answer the asked questions: ii) CLS i) CLS B=10101 D=13 B$=STR$(B) WHILE D >= 1 B$=LTRIM$(B$) R = D MOD 2 FOR I = LEN(B$) TO 1 STEP -1 B$ = STR$(R) + B$ X$ = MID$(B$, I, 1) D=D\\\\2 X = VAL(X$) WEND D=D+X*2^P PRINT B$ P=P+1 NEXT END PRINT B PRINT D a. \t Write the output of this program. END Ans: ....................................................... a. Write the output of this program. b. \tIf it is written, D>0 then what does it make Ans: ....................................................... difference in the output? b.\t Why is VAL() used? Ans: ....................................................... Ans: ....................................................... c.\t How many times loop repeat? c.\t What is the length of B$ before and after using Ans: ....................................................... LTRIM$() ? e.\t If you write B$ = B$+STR$(R) in place of B$ = STR$(R) + B$, what does it make difference in the output? Ans: ....................................................... Ans: ....................................................... Approved by Curriculum Development Center (CDC) 243","Review QBASIC Programming d.\t What is the purpose of this program? PRINT S PRINT G Ans: ....................................................... DATA 50, 45, 40, 35, 55, 75, 95, 85, 70, 65 END 2. Write the output of the following programs: Ans: ........................................................ i)\tCLS ................................................................ \tN=89 \tO=N 3. \t Write a program to ask a number and find \t DO WHILE N>0 out whether it is a prime or composite. \t\t R=N MOD 10 \t\t RV=RV*10+R 4. \t Write a program to ask a number and find \t\t N=N\\\\10 out whether it is an even or odd. \tLOOP \t PRINT RV 5. \t Write a program to ask any two numbers \tEND and find out HCF. Ans: ....................................................... 6. \t Write a program to ask a number and find out whether it is a palindrome number or ii) CLS not. I=1 N=153 : S = 0 7. Write a program to ask a number and find out whether it is Armstrong or not. DO A number such that the sum of its digits R = N MOD 10 raised to the power 3 is equal to the S=S+R^3 number itself is Armstrong number. For N = N \\\\ 10 example, 33+73+13 = 371 is an Armstrong number. LOOP WHILE N >= 1 PRINT S 8. \tWrite a program to ask a character and END find out whether it is vowel or consonant. Ans: ....................................................... 9. \t Write a program to ask a word and find iii) CLS out total vowels. \t READ N \tS=N 10. Write a program to ask a word and display \tG=N in reverse order. \t FOR I= 1 TO 9 \t\t READ N\t 11. Write a program to ask a word and find \t\t IF N<S THEN S=N out whether it is palindrome or not. If word \t\t IF N>G THEN G=N can be read same from both left and right \t NEXT I sides is called palindrome word. Such as LIRIL, MAM, etc. 12. Write a program to ask 10 numbers and find out greatest number. 244 Approved by Curriculum Development Center (CDC)","Modular Programming Smart Computer Science Book-10 Chapter Includes CHAPTER \u2022\t Introduction to Modular programming 14 \u2022\t SUB procedure \u2022\t Creating and calling SUB procedure \u2022\t User defined Function procedure. \u2022\t Creating and calling User Defined Function procedure INTRODUCTION The modular programming is a programming technique which divides a large and complex program into small logical and manageable modules of the program that perform a specific task. These small manageable parts of the program are known as the modules or procedures. Each module or procedure uses the small block of functional codes which is also called structured program. Every modular program has one main module and one or more sub modules. The sub module of a program is also called as 'procedure'. Main Module Sub Module-A Sub Module-B Sub Module-C Sub Module-B1 Sub Module-B2 Advantages of modular programming The advantages of modular programming are: \u2022\t Easy to design a program. \u2022\t Coding and testing the program is very easy. \u2022\t A module can be used in multiple places, which reduces the program codes. \u2022\t Different programmers can write different modules separately. \u2022\t Debugging of the program becomes easier and faster since they are divided into different modules. Approved by Curriculum Development Center (CDC) 245","Modular Programming Main Module The main module is the control section of the entire program. It is also called main program or parent program where declaration of sub module, variable and data as well as calling sub program and end of program are mentioned. As we run the main module, the control of the program starts, then it transfers the control flow to the sub modules. It is located at the top of other modules. Sub Module Sub module is a small branch program written under a main module, which performs a specific task. It is also called procedure or child program. The sub module is defined one or more than one modules below the main module as our requirement. The sub module is totally controlled by main module. Every sub module is defined by its unique name. Types of procedure QBASIC supports two types of modular programming procedures: i) SUB procedure\t\t\t ii) FUNCTION procedure SUB Procedure A Sub procedure is a small, logical and manageable functional section or branch of a main program which performs the specified task but does not return any value. Its name does not consider the data type. It is also called child program. This section is totally controlled by main module using CALL statement. When a Sub procedure is called, the program execution control flow transfers to the Sub procedure and the execution takes place. After completion the execution process, it takes the execution flow next to the CALL statement of parent or main module. Features of SUB Procedure i) \t It is defined by unique name. ii) \t It does not return any value. iii) \tThe name of Sub procedure can not be used as a variable name. iv) \tArgument can be passed by reference or value. v) \t It is always declared in the top of its parent or main module. vi) \tA Sub program may call another Sub program. Creating Sub Procedure To create a sub procedure, you must follow the following three processes: i) Declare Procedure\t ii) Define Sub procedures\t iii) Call Sub Procedure 246 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 i) Declare Sub Procedure This is the first step of creating Sub procedure. The declaration of Sub procedure is made in the top of the main program using DECLARE statement. DECLARE SUB Statement Function\t: This statement is used to declare the SUB procedure. It is non executable statement. Syntax\t\t: DECLARE SUB <name> [(parameter list)] \u2022\tname is the procedure name. \u2022\tparameter list is the variables that receive values and are passed to the Sub procedure when it is called. Example\t: \tDECLARE SUB XYZ(A,B) \u2022\tHere, XYZ is a name of Sub Procedure and A and B are the parameters. ii) Define Sub Procedure This is the second step of creating Sub procedure. The Sub Procedure is defined by the SUB statement. The SUB statement is closed by END SUB. The body of Sub Program is written within the SUB..........END SUB. SUB...END SUB Statement Function\t: The SUB statement is used to define the Sub Procedure in the QBASIC program. Syntax\t: \tSUB <name> [(parameter list)] \t \t body of sub program \t\t.............................. \t\t.............................. \t\t END SUB \u2022\tname is the procedure name. \u2022\tparameter list are the variables that receive values sent from main module as an argument. Example : SUB PROD (A,B) \u2022\t PROD is a name of procedure. \t \t P=A*B \u2022\t Here,Aand B are the parameters \t\t\t PRINT \\\"Product=\\\"; P \t\t END SUB which are also called formal or nominal parameters. iii) Call Sub Procedure When you create a sub program, it needs to execute. So, the technique which is used to execute the sub procedure is called calling sub procedure. The CALL statement is used to call the sub procedure. When the execution flow meets the CALL statement, it controls the execution flow to the sub procedure and starts to execute the body codes of the sub procedure. After completion of execution of sub procedure, the execution flow controls to the next to the CALL statement. Approved by Curriculum Development Center (CDC) 247","Modular Programming CALL Statement Function\t: The CALL statement is used to call or execute the Sub procedure. Syntax\t\t: [CALL] <name> [(argument list)] \u2022\tname is the procedure name. \u2022\targument list is the values sent to the Sub program. Example\t: \tCALL XYZ(A,B, 20, 30, A+B, 40+50) Parameters: Parameters are the variables which receive the values sent from the parent\/main module. It may be a string or numeric variable. Arguments : Arguments are the values which are sent to the Sub or Function procedure. Arguments can be variable, constant or expression. Sample Program-1 \u2022\t Write a program to ask any two numbers and find their sum. Using SUB ...... END SUB procedure. DECLARE SUB XYZ(A,B) Declaration section Main Module INPUT \\\"Enter first number:\\\"; A INPUT \\\"Enter second number:\\\"; B CALL XYZ(A, B) Calling section END Sub Module SUB XYZ (A, B) Definition section S=A+B Body section PRINT \\\"SUM=\\\"; S END SUB Test Your Skill-1 1. \t Write a program to ask any two numbers and find their product using SUB-END SUB procedure. 2. \t Janak Lal Giri has been assigned a task to write a program to ask quantity and rate of pen then find the total amount using Sub procedure. To solve this problem, how should he write the pro- gram? 3.\t Write a program to ask principal amount, time and rate and find out simple interest. 4. \t Write a program to ask 5 subjects marks out of 100 marks each, and find out total and percent- age marks, using Sub procedure. 5.\t Write a program to ask temperature on Fahrenheit scale and convert into Celsius using Sub procedure. 248 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Calling Methods: QBASIC supports two types of calling methods: i) Call by reference and ii) Call by value. Call By Reference: The call by reference method is the passing arguments to a procedure which copies the address of an argument into the formal parameter. It is also called passed by reference method. In the procedure, the address is used to access the argument values passed in the calling section. It means the changes made to the parameter in the Sub module affects the passed argument. Sample Program DECLARE SUB XYZ(N) N=10 PRINT \\\"Value of N before calling=\\\"; N CALL XYZ(N) PRINT \\\"Value of N after calling =\\\"; N END SUB XYZ (N) \u2022\t In this example, changes made in parameters within N=N+5 the sub procedure made affect after calling the main PRINT \\\"Value of N after changing=\\\";N module. END SUB Call By Value: In this method, values of arguments are copied to procedure's formal parameters and two copies of parameters are stored in different memory locations. It is also called pass by value. So any changes made inside procedures are not reflected in actual parameters of the caller. Call by value is useful when the (SUB\/Function) procedure is not needed to modify the values of the original variables in the calling program. This is done by enclosing the argument variables in parenthesis. Sample Program DECLARE SUB XYZ(N) N=10 PRINT \\\"Value of N before calling=\\\"; N CALL XYZ((N)) PRINT \\\"Value of N after calling =\\\"; N END SUB XYZ (N) \u2022\t In this example, changes made in parameters within N=N+5 the sub procedure did not affect after calling the main PRINT \\\"Value of N after changing=\\\";N module. END SUB Approved by Curriculum Development Center (CDC) 249","Modular Programming SUB Procedure can be called without passing argument Sample Program \u2022\t Write a program to ask any two num- bers and find their sum, without pass- \u2022\t Write a program to display multiplication ing argument. table of 5. DECLARE SUB SUM() DECLARE SUB MUL() CLS CLS CALL SUM CALL MUL END END SUB SUM () SUB MUL () INPUT \\\"Enter first number:\\\";A FOR I = 1 TO 10 INPUT \\\"Enter second number:\\\";B PRINT 5 * I S=A+B NEXT I PRINT \\\"Sum=\\\"; S END SUB END SUB \u2022\t In these examples, there are not any argument and parameter. SUB Procedure can be called without CALL statement Sample Program \u2022\t Write a program to display square root \u2022\t Write a program to ask a number and of 16. display cube root number. DECLARE SUB SQU() DECLARE SUB CUBER(N) CLS CLS SQU INPUT \\\"Enter a number:\\\";N END CUBER N SUB SQU () END SR = SQR(16) SUB CUBER(X) PRINT \\\"Square Root=\\\"; SR CR=X^(1\/3) END SUB PRINT \\\"Cube Root=\\\"; CR END SUB \u2022\t In these examples, there are Test Your Skill-2 not CALL statement. 1. \t Write a program to print your name 10 times. 2. \t Write a program to display first 10 natural values. 3.\t Write a program to find the sum of first 10 natural numbers. 4. \t Write a program to display first 10 natural numbers in reverse order along with their square value. 5.\t Write a program to find the sum of only odd numbers from 1 to 10. 6.\t Write a program to ask your name and print it 10 times without passing argument. 250 Approved by Curriculum Development Center (CDC)"]
Search
Read the Text Version
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353