Introduction to Computers -Final exam- 授課教授:李錫智. Q1 Write a function named Reverse that takes a string as input and returns a copy of that string in reverse.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

1 COMM 1213 H1 COMP 4923 X1 JavaScript 1 (Readings: Ch. 10, 11 Knuckles)
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 8 Strings.
Introduction to computers Exam 2 授課教授:李錫智. Question_1 For the following program: Suppose the user enters 43 、 57 in the text boxes numberBox1 and numberBox2,
Loops (Part 1) Computer Science Erwin High School Fall 2014.
An Introduction to Python – Part II Dr. Nancy Warter-Perez.
授課教授:李錫智 Data Structures -3 rd exam-. 1.[5] Refer to the two trees in Fig. 1. Let’s define the balance factor BF of a node to be the absolute value of.
Introduction to Computers -1 st exam- 授課教授:李錫智. 1. Given 12 bits, (a).How many different distinct combinations can we get from these bits? Ans: 2 12 =
Spreadsheets in Finance and Forecasting Presentation 8 Buttons, Boxes and Bars.
1 9/15/06CS150 Introduction to Computer Science 1 Combined Assignments, Relational Operators, and the If Statement.
1 CS 105 Lecture 8 Strings; Input Failure Mon, Mar 7, 2011, 3:39 pm.
To remind us We finished the last day by introducing If statements Their structure was:::::::::
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
Introduction to Computers -3rd exam- 授課教授:李錫智. Q1 What will the web page look like if the user type 100 、 20 in the numberbox1 、 numberbox2 respectively?
JavaScript Lecture 6 Rachel A Ober
Introduction to Computers 第三次考試 授課教授 : 李錫智. 第一題 [15] Suppose random(x,y) returns an integer randomly between x and y inclusively. Consider the following.
String Class in Java java.lang Class String java.lang.Object java.lang.String java.lang.Object We do not have to import the String class since it comes.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 3.
Strings CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Data Structures -1 st test- March 30, 2015 授課教授:李錫智.
Using Client-Side Scripts to Enhance Web Applications 1.
Decision II. CSCE 1062 Outline  Boolean expressions  switch statement (section 4.8)
Friends = ['Tom', 'Sue', 'Danny', 'Joe', 'Mary'] Index positions >>>Friends[2] Danny >>>Friends[2:4] Danny, Joe >>>Friends[-4] Sue Use your PYTHON.
A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University ©2011 Pearson Prentice Hall ISBN Chapter 15 JavaScript.
Coding Design Tools Rachel Gauci. Task: Counting On Create a program that will print out a sequence of numbers from "1" to a "number entered”. Decision’s.
Combination of logic gates  Logic gates can be combined to produce more complex functions.  They can also be combined to substitute one type of gate.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
Arrays Character Arrays and Strings Alina Solovyova-Vincent Department of Computer Science & Engineering University of Nevada, Reno Fall 2005.
1 CSC 221: Introduction to Programming Fall 2011 Lists  lists as sequences  list operations +, *, len, indexing, slicing, for-in, in  example: dice.
C++ String Class nalhareqi©2012. string u The string is any sequence of characters u To use strings, you need to include the header u The string is one.
Introduction to computers 103 學年度 上學期 Solution of Homework_ch12 授課教授:李錫智.
Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Validation final steps Stopping gaps being entered in an input.
1 CSC 221: Introduction to Programming Fall 2012 Lists  lists as sequences  list operations +, *, len, indexing, slicing, for-in, in  example: dice.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Basic Conditions. Challenge: ● Ask the user his/her name ● If it’s “Wally,” jeer him ● Pause video and try on your own.
Data Structures -2 nd exam- 授課教師 : 李錫智 教授 1. 1.[10] Please answer the following questions about stack: What is the response of the statement “(new stack()).isEmpty()”?
31/01/ Selection If selection construct.
110 F-1 Decisions and Conditions Chapter 4: We can design a form We can calculate To make our programs more powerful, we need to be able to make choices.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Using a Database Access97 Please use speaker notes for additional information!
Arrays What is an array… –A data structure that holds a set of homogenous elements (of the same type) –Associate a set of numbers with a single variable.
The Scripting Programming Language
OVERVIEW OF CLIENT-SIDE SCRIPTING
Building Blocks CS 1308 Computer Literacy and the Internet.
Introduction to Computers - 4 th exam- 授課教授:李錫智. Hints: ADD [DR] [SR1] [SR2] DR SR1 SR2 SUB [DR] [SR1] [SR2] DR.
Strings … operators Up to now, strings were limited to input and output and rarely used as a variable. A string is a sequence of characters or a sequence.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Strings. Using strings as abstract value A string is a sequence of characters e.g. “Hello, World!” Early version of C++ followed the older C language.
© 2016 AQA. Created by Teachit for AQA Boolean logic Lesson 3.
C++ Memory Management – Homework Exercises
Logic Gates.
Introduction to Scripting
3rd prep. – 2nd Term MOE Book Questions.
3.4 Computer systems Boolean logic Lesson 2.
Chapter (3) - Looping Questions.
T. Jumana Abu Shmais – AOU - Riyadh
Introduction to TouchDevelop
Logical Operations In Matlab.
Selection Statements.
GCSE Computer Science – Logic Gates & Boolean Expressions
Binary Logic.
Chapter 3: Selection Structures: Making Decisions
Programming Concepts and Database
Chapter 3: Selection Structures: Making Decisions
JavaScript: Introduction to Scripting
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Presentation transcript:

Introduction to Computers -Final exam- 授課教授:李錫智

Q1 Write a function named Reverse that takes a string as input and returns a copy of that string in reverse order. For example, the function call Reverse("apple") should return the string "elppa".

Solution of Q1 Ans: function Reverse(str) { var len,restr; len=str.length; restr=""; i=len-1; while(i!=-1) { restr=restr+str.charAt(i); i=i-1; }

Q2 Consider the following program : function string(string){ str = string; i = str.search(/[aeiou]/); while(i != -1){ str = str.substring(0,i) + '*' + str.substring(i+1,str.length); i = str.search(/[aeiou]/); } return str; } What will be returned for the function call string('Hello world')?

Solution of Q2 Ans: H*ll* w*rld

Q3 Write a function named Maximum that takes an array of numbers as input and return the biggest value in the array. For example, the call Maximum([2, 28, 33, 12, 5, 17, 8]) should return 33.

Solution of Q3

Q4 Suppose you are given the following segment of program: Phrase = “George Bush, USA\n”+ “Leonardo da Vinci, Italy\n”+ “William Shakespeare, England\n”; Spilt_1 = Phrase.split(“, “); Spilt_2 = Phrase.split(/[,\n]+/); [5] What is the value of Split_1? [5] What is the value of Split_2?

Solution of Q4 Ans: Split_1 = ["George Bush", "USA\nLeonardo da Vinci", "Italy\nWilliam Shakespeare", "England\n"] ; Split_2 = ["George Bush", "USA", "Leonardo da Vinci", "Italy", "William Shakespeare", "England"];

Q5 Please using the NOT, AND, and OR gates, draw a circuit that will output 0 while both inputs are 0 or 1. That is, suppose A and B are the two inputs and C is the output, then C=0 if and only if (A=0 and B=0) or (A=1 and B=1).

Solution of Q4 ABC

Q6 Consider the following program: What will be returned for the function call Cipher('Bronze')? function Cipher(str) { var coded, ch, index, key, i; alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; coded = ' '; key = 4; str = str.toUpperCase(); i = 0; while(i < str.length) { ch = str.charAt(i); index = alphabet.search(ch); if (index != -1) { if ( (index+key) < alphabet.length) { coded = coded + alphabet.charAt(index+key); }else{ coded = coded + alphabet.charAt(index+key-alphabet.length); } }else{ coded = coded + ch; } i = i + 1; } return coded; }

Solution of Q6 Ans: FVSRDI Offset 4 characters.

Q7 Suppose you are given an array of numbers, A. (a) [10] Please write a function taking A and returning an array B which records the number of times each element appearing in A. For example, suppose A=[15,25,35,45,35,35,25]. Then B=[1,2,3,1,3,3,2]. (b) [10] Please write a function taking A and returning the element in A which appears most frequently in A. For example, for the above example, 35 will be returned.

Solution of Q7

Q8 Please design a Web page that asks the user to enter his/her name and age in a phrase separated by a colon, e.g., John :36. When the user clicks a button, the webpage will show the name and say the user is an adult or a child, e.g., John is an adult. Note that a person is an adult if his/her age is equal to or greater than 20.

Solution of Q8

Q9 Consider the following circuit. A, B, and C are inputs. P and Q are outputs. Please list the input- output relationship in a truth table.

Solution of Q9 ABCQP

Q10 Please write a function to check whether a given string is a mirror-string. A string A is a mirror-string if and only if A satisfies one of the following conditions: A is a concatenation of B and C, i.e., A=BC, where B and C are strings and C is the reverse of B. For example, “abccba” is a mirror-string. A is a concatenation of B, t, and C, i.e., A=BtC, where B and C are strings, t is a character, and C is the reverse of B. For example, “abcycba” is a mirror-string.

Solution of Q10 Ans : function IsP(string) { var stripped, front, back; stripped = string; front = 0; back = stripped.length - 1; while (front < back) { if (stripped.charAt(front) != stripped.charAt(back)) { return false; } front = front + 1; back = back - 1; } return true; }

The end of the final Exam