3 Pages

c17s99f

Course: CSE 17, Spring 2008
School: Lehigh
Rating:
 
 
 
 
 

Word Count: 951

Document Preview

17 CSc Final Examination Wednesday 12 May 1999 4 PM Page 1 !!!!!!!!!!!!!!!SUGGESTED ANSWERS!!!!!!!!!!!!!!!!! 1. (10 pts) Assume class Staque implements an ADT which has the properties of both a stack and a queue. Further assume that Staque has the member functions push(int), enqueue(int), int pop(), int dequeue(), bool full(), and empty(), where the functions push and enqueue have exactly the same effect. For the...

Register Now

Unformatted Document Excerpt

Coursehero >> Pennsylvania >> Lehigh >> CSE 17

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
17 CSc Final Examination Wednesday 12 May 1999 4 PM Page 1 !!!!!!!!!!!!!!!SUGGESTED ANSWERS!!!!!!!!!!!!!!!!! 1. (10 pts) Assume class Staque implements an ADT which has the properties of both a stack and a queue. Further assume that Staque has the member functions push(int), enqueue(int), int pop(), int dequeue(), bool full(), and empty(), where the functions push and enqueue have exactly the same effect. For the code below, list the contents of aStaque after each push, pop, enqueue, or dequeue is called. List the entries from left to right, with the latest entry on the right. Staque aStaque(100); //create a Staque with capacity for 100 entries for(int j=5;j<7;j++){ aStaque.push(j); 5 aStaque.push(j+10); 5 15 aStaque.enqueue(aStaque.dequeue()); 15 5 } 15 5 6 while(!aStaque.empty()){ 15 5 6 16 aStaque.pop(); 5 6 16 15 aStaque.dequeue(); 5 6 16 } 6 16 6 <empty> 2. (25 pts) Assume we have the following data structure for building a binary tree: class TNode{ public: int data; TNode *child[2]; }; class Tree{ private: TNode *root; //possibly other stuff... public: //other stuff.... }; Write a member function for Tree called recPrintRange such that the call recPrintRange(root,low,high) displays on the screen all entries in the tree that are greater than the int low and less than the int high. void Tree::recPrintRange(TNode *rt,int low, int high){ if(rt!=NULL){ if(rt->data>low && rt->data<high) cout<<rt->data<<endl; recPrintRange(rt->child[0],low,high); recPrintRange(rt->child[1],low,high); } } 3. (20 pts) For class Tree in question 2, I wrote the following member function which assumes a Tree constructed in ascending order, but I forgot to provide documentation. Provide it. //Purpose: To return the largest entry in the tree. If the tree is // emtpy, return 0. //Pre-condition(s): The TNodes actually form a binary tree; each value // of data is valid; each root and each child are defined; There is only // one way to go from the root to any child. //Post-condition(s): The tree is unchanged. The largest value (or 0 if // the tree is empty) has been returned. int Tree::Puzzling(){ TNode *temp; if(root!=NULL){ temp=root; while(temp->child[1]!=NULL) temp=temp->child[1]; return temp->data; } else return 0; } 4. (20 pts) For the class TNode in question 2 overload the << operator so that for the declaration TNode t, the statement "cout<<t" displays t.data on the screen. Write both the prototype and the definition. friend ostream & operator <<(ostream &out,const TNode &t); ostream & operator <<(ostream &out,const TNode &t){ out<<t.data; return out; } 5. (20 pts) For the class TNode in question 2 write the function "output" so that for the declaration TNode t, the statement "t.output(cout)" displays t.data on the screen. Write both the prototype and the definition. void output(ostream &out); TNode::output(ostream&out){ void out<<data; } 6. (30 pts) Suppose we have the declaration: int x[100], first, last. Suppose the call sum(x,first,last) returns the sum of x[first], x[first+1], ..., x[last]. Write a version of sum that uses the following recursvie algorithm: To sum the numbers between first and last, inclusive, take the entry in the middle and add it to the sum of the entries to the left of the entry in the middle and the sum of the entries to the right of the entry in the middle. int sum(int x[],int first, int last){ if(first>last) return 0; if(first==last) return x[first]; int middle=(first+last)/2; return(sum(x,first,middle-1)+x[middle]+sum(x,middle+1,last)); } 7. (10 pts) Write one, and only one, definition of the function swap so that the following code compiles (even though the code may not make much sense). Swap is supposed to interchange the values of its two arguments. int a,b; TNode c,d; //TNode is defined in question 2 swap(a,b); swap(c,d); template <class T> void swap(T &u,T&v){ T temp; temp=u; u=v; v=temp; } 8. (5 pts) What is the output of the following code? char line[]="One fine day", *p; p=line; cout<<line[4]<<p[5]<<endl; fi cout<<p<<endl; One fine day cout<<(p+1)[4]<<endl; i cout<<(p+1)<<endl; ne fine day line[3]='\0'; cout<<line<<endl; One 9. (5 pts) Write a prototype for the function junk so that the following code will compile: int x[5], y[5][2], z[2][4][2], w[5][4][2]; junk(x,z,z[3]); junk(y[2],w,y); junk(w[3][3],w,y); void junk(int x[],int[][4][2],int [][2]); 10. (30 pts) Write a function "charCount" which counts the number of times a given character appears as the first character on a line in a file. In particular, suppose we have the declaration: istream in; The call charCount(in,'a') should return the number of times the character 'a' appears as the first character of a line in the file "in". If the file contained the lines of this paragraph, right justified, then the call charCount(in,'c') would return 4 (c appears on lines 6 thorugh 9), and the call charCount(in,'T') would return 1 (T appears on line 4). Your function can assume the file is opened and at the beginning. int charCount(istream &in,char target){ char ch; int count; count=0; in.get(ch); while(!in.eof()){ if(ch==target) count++; while(ch!='\n' && !in.eof()) in.get(ch); if(!in.eof()) in.get(ch); } return count; } 11. (25 pts) Write a function "sort" which sorts an array of doubles into ascending order. In particular, if x is an array of doubles, and n is an int which counts the number of entries in x, after the call sort(x,n) the first n entries in x should be in ascending order. void sort(double x[],int last){ bool sorted; do{ sorted=true; for(int j=1;j<last;j++) if(x[j-1]>x[j]){ swap(x[j-1],x[j]); //use the swap of question 7 sorted=false; } }while(!sorted); }
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Lehigh - CSE - 17
CSc 17 Test 1 1.Wednesday 8 October 1997ANSWERS(15 pts) This is a true-false question. After each expression state whether the expression evaluates to true or to false. ( 3/2 = (2/3+1) TRUE ('a'&gt;'b') | ( ('b'-'a')&gt;0 ) ) TRUE ('a'+int(true)&gt;'a')
Lehigh - CSE - 318
CSc 318 Test 3 Wednesday 1 December 1999.TEST 3 SUGGESTED ANSWERS1. (10 pts) Prove that the grammar below is ambiguous. S A B AA | BAB aa | Sa a | abSThe trees for the following two derivations of aaaa differ. S S SS /\/|\ AABAB /\|\|/\| aaaaaaa
Lehigh - CSE - 17
CSc 17 Test 1 1.Thursday 10 June 1999#ANSWERS# (10 pts)Given the function definitions below, state what output is generated by the code below the dashed line. void b(int &amp; x, int &amp;y) {y+; x+=y; cout &lt;x&lt;&quot; &quot;&lt;y&lt;&quot; &quot;; } void a(int &amp; x, int&amp; y,int z) {
Lehigh - CSE - 318
CSc 318 Test #1 Wednesday, 27 September 2000 &gt;SUGGESTED ANSWERS&lt; 1. Prove A B A A B B. A B 1-1, onto f:A B. Define 1-1, onto g: A A B B by g(x,y) = (f(x), f(y). g is 1-1, because g(x,y)=g(u,v) (f(x),f(y)=(f(u),f(v) f(x)=f(u) and f(y)=f(v) x=u and y=v
Lehigh - CSE - 17
CSc 17Test 2Friday27 March 1998Page 1&gt;ANSWERS&lt; 1. (10 pts) In writing the function below, I forgot to provide the documention. Provide it by stating the pre- and post-conditions. void x (int y[], int m, int n) /Pre-Condition: 0&lt;=m&lt;=n /Post-
Lehigh - CSE - 17
CSc 17 Test 2 24 June 1999 Page 1 &gt;ANSWERS&lt; 1. (15 pts) (a) Using the standard algorithm for building a binary tree for storing numbers in order: (1) show the state of the tree after the numbers 15, 12, 14, 6, and 9 have been added to an empty tree i
Lehigh - CSE - 17
CSc 17 Test 1 Friday 2 October 1998 Page 1 &gt;ANSWERS&lt; 1. Assume that we have #include&lt;math.h&gt;. Explain why the segment of code in (a) causes a run-time error (i.e., crashes) and why the segment of code in (b) executes without a run-time error (i.e., d
Lehigh - CSE - 17
CSc 17 Final ExaminationMonday 15 December 1997 4 PM&gt;ANSWERS&lt; CLOSED BOOK, CLOSED NOTES. ANSWERS AVAILABLE AFTER THE TEST ON MY WEB PAGE AND ON THE BULLETIN BOARD CSCKAY 1. (20 pts) Suppose we have a class called Stack whose instances implement a
Lehigh - CSE - 17
CSc 17 Test 1 Monday 18 October 1999 Page 1 &gt;SUGGEST ANSWERS&lt; 1. (15 pts) Given that the function 'truth' is defined as char truth(bool t){ if(t) return 'T'; return 'F';} what is the output of the following lines of code? cout&lt;(2+3%4*5/6%7)&lt;endl; cou
Lehigh - CSE - 17
CSc 17 Page 1Final ExaminationMonday14 December 19981. ( pts) Assume the declarations of class biNode and of rt below. Write a function &quot;zero&quot; such that the call &quot;zero(rt)&quot; stores a 0 in each leaf of the tree whose root is rt. The function as
Lehigh - CSE - 17
CSc 17 Final ExaminationFriday 2 July 1999Page 1&gt;ANSWERS&gt;. 1. (25 pts) Call an array of ints with one entry &quot;balanced&quot; if the entry is 9. Call an array of ints with two entries &quot;balanced&quot; if the sum of the two entries is 9. Call an array of int
Lehigh - CSE - 17
CSc 17 Final Saturday 18 December 1999 &gt;SUGGESTED ANSWERS&lt;, 1. (25 pts) a. Provide the missing documentation for the function below. b. Determine the complexity of the algorithm used in the function and state the complexity in terms of the O() notati
Lehigh - CSE - 17
CSc 17 Test 1 Monday 22 November 1999 &gt;SUGGESTED ANSWERS&lt; 1. (25 pts) Write a private recursive member function for the class Tree which visits every node in a binary tree and increments the number in each node by 1. Assume the function is named INC
Lehigh - CSE - 17
CSc 17 Test 1 Wednesday 17 October 2001 =SUGGESTED ANSWERS MARKED WITH &quot;&lt;&quot; = 1. (16 pts) Assume you have the function v() below (which I forgot to format): char v(int x, int y) {char ch; ch='C'; if(x&lt;y) if(x&gt;0) if(x&lt;5) ch='D'; else {if(x&gt;77) ch='A';}
Lehigh - CSC - 262
CSc 262 Final Examination Saturday, 12 December 1998 4-7 PM Suggested answers will be posted on CSCKAY shortly after 7.Page 1Name_ 1. (25 pts) In this question I ask you to provide the details of the activation records for the Pascal program belo
Lehigh - CSE - 17
CSE 17 Test 1 Tuesday 18 October 2005 &lt;SUGGESTED ANSWERS&gt; 1. Write a program that prompts the user to enter four strings from the console and then displays the lexicographically (as they would appear in a case-sensitive dictionary) smallest and large
Lehigh - CSE - 17
CSc 17 Test 1 6 June 2002 &gt;SUGGESTED ANSWERS&lt; 1. (20 pts) Given some function &quot;statement()&quot; and the code for(int j=0;j&lt;n;j+=3) statement(j); a) Write a while loop which has the same effect as the above for loop b) Write a do-while loop which has the
Lehigh - CSE - 17
CSc 17 Final Examination Tuesday 18 December 2001 &gt;SUGGESTED ANSWERS&lt; 1. (25 pts) The code below will compile but not link, because the function f() is not defined. Add code for a single function f() to the code below so that the code compiles and ru
Lehigh - CSE - 17
CSc 17 Test 2 20 July 2002 *SUGGESTED ANSWERS* 1. (10 pts) What is the output of the following program? void a(int *p,int *&amp;q) {p[1]=5; q=p; p=new int(14); } int main() { int *x,*y,v[]={1,2,3,4},z[]={6,7,8,9}; x=v; x[1]=0; for(int j=0;j&lt;2;j+) cout&lt;v[
Lehigh - CSE - 17
CSE 17 FINAL TUESDAY 20 DECEMBER 2005 &lt;SUGGESTED ANSWERS&gt; 1. For the following scenarios, what would be the best data structure to use as the primary data structure in a Java implementation? Justify your choice. Choose from the following data structu
Lehigh - CSE - 17
CSE 17 Test 2 Tuesday 15 November 2005 &gt;SUGGESTED ANSWERS&lt; 1. Design a class called Dictionary that is a subclass of the Book class. Create the methods in Dictionary so that word.main() produces the following output. Number of pages: 1500 Number of d
Lehigh - CSE - 17
CSE 17 Final Examination Wednesday 20 December 2006 &lt;SUGGESTED ANSWERS&gt; 1. For each of the questions below, assume the following data are processed in the given order: 11, 26, 64, 63, 76, 50. (a) Assume the data are entered into a binary tree, where
Lehigh - CSC - 262
CSc 262 1.Test 2Suggested Answers(20 pts) Suppose that Algol allowed parameters to be passed in three ways, by value, by reference, and by name. What would be the output of the following program if, in procedure M, x is passed by value, y by re
Lehigh - CSE - 17
CSc 17 Final Examination Tuesday 19 December 2000 &gt;SUGGESTED ANSWERS&lt; 1. Write the declaration for a class FlipFlop and then write the definition of its member functions and operators. Instances of class FlipFlop store either the value of 0 or 1. If
Lehigh - CSC - 262
CSc 262 Final Examination Thursday 11 December 1997 8 AM &gt;SUGGESTED ANSWERS&lt;, 1. (20 pts) Write a recursive LISP function entryn such that evaluating the expression (entryn n alist) returns the nth entry in the list alist, if it has at least n entrie
Lehigh - CSC - 262
CSc 262Test 3Wednesday12 November 1997 Suggested answers available after test.Closed book, closed notes.1. (40 pts) Below is a Pascal program to list the moves in solving the Towers of Hanoi problem. Certain statements in the program have c
Lehigh - CSE - 17
CSE 17 Test 1 Friday 6 October 2006 &gt;SUGGESTED ANSWERS&lt; 1. Write a class P, whose main program forces the user to enter three integers and then tells the user whether the sum of the squares of the first two is equal to the square of the third (Pythag
Lehigh - CSE - 17
CSE 17 Test 1 Friday 17 November 2006 &lt;SUGGESTED ANSWERS&gt; 1. Assume the following class: public class Node{ public int j; public Node next; } Write a method list() for listing the contents of a linked list of Nodes in the file &quot;test2.out&quot;. Given Node
Lehigh - CSE - 17
CSc 17 Test 2 Wednesday 28 November 2001 &gt;SUGGESTED ANSWERS&lt; 1. (10 pts) Using the algorithms discussed in class for building a balanced binary tree for sorting integers, draw a picture of the tree after each of the numbers listed in (a) are added to
Lehigh - CSE - 17
CSc 17 Test 2 20 November 2000 &gt;SUGGESTED ANSWERS&lt;, 1. (20 pts) Assume the class LinkList below. Write a member function of LinkList called same() which returns true if and only if two linked lists have the same data in the same order. Given the decl
Lehigh - CSE - 17
CSc 17 Final Examination28 July 20021. (25 pts) Write a function numberLines() which reads text from a file and faithfully echoes it to the screen, except that it appends the line number at the end of each line in the form [xx]. For example, if t
Lehigh - CSC - 262
Possible answers to the test are below the test. CSc 262 Test 1 Friday, 19 September 1997Each question worth 20 points. 1. You are designing a pseudo-code for a machine with 512 words of data memory, 512 words of a separate program memory, where ea
Lehigh - CSC - 262
CSc Test 1 Friday 25 September 1988 ANSWERS 1. (15 pts) Given the assignment x=2-3*4-5, for each of a), b), and c) below, find a set of precedence and hierarchy rules for the operatores &quot;-&quot; and &quot;*&quot; such that a) x=-15 b) x=-9 c) x=5 a) Higher preceden
Lehigh - CSC - 262
CSc 262Test 1Friday23 October 1998&gt;ANSWERS&lt; 1. (15 pts) Suppose we have the program ONE below, which is written in some programming language, say ELBONIAN. PROGRAM ONE; INTEGER GLOBAL; INTEGER ARRAY LIST[1.3]; PROCEDURE SUB(PARAM1:INTEGER; PA
Lehigh - CSC - 262
CSc 262 Test 3 20 November 1998 &gt;SUGGESTED ANSWERS&lt; 1. (40 pts) In this question I ask you to provide the details of the activation records for the Pascal program below. Beside each statement in the program is the (hypothetical) decimal address for t
Lehigh - CSE - 17
CSc 17 Test 1 Wednesday 18 October 2000 &gt;SUGGESTED ANSWERS&lt; 1. (12 pts) Assume the statement if(x&lt;y) if(x&lt;5) cout&lt;'D'; else if(x&gt;77) cout&lt;'A'; else cout&lt;'B'; is preceded by one of the four pairs of statements below. State the output that occurs for e
Tulane - FINC - 725
I. Debt and val ueWe examine two important stories for the benefit and cost tradeoffs from using debt. Later we will examine more stories A. Tax shields and bankruptcy cost B. Agency costs of debt and equity C. Sum up1Income StatementSales t CO
Lehigh - BIOS - 95
Cardiovascular disease, studies at the cellular and molecular levelLinda LoweKrentz Bioscience in the 21st Century November 14Risk Factors High blood pressure (above 120/80 mm Hg) Serum cholesterol [aim for below 100 mg/dL LDL cholesterol and
Lehigh - CALC - 1,2,3
6.5 Average Value of a FunctionIf f is continuous on [a, b], then the average value of f on this interval is given by1 b ab af ( x)dxMean Value Theorem for IntegralsIf f is continuous on [a, b], then there exists a number c in [a, b] such t
Lehigh - BIOS - 95
Professor Robin S. Dillon Department of Philosophy Lehigh UniversityA Framework for Moral Reasoning and Decision-Making in Bioethics 1I. Morality Morality is a universally valid and applicable, impartial, rationally justified system for making dec
Lehigh - BIOS - 95
Genomes: What we know . and what we don't knowComplete draft sequence 2001October 15, 2007Dr. Stefan Maas, BioS Lehigh U. SMaas 2007What we knowRaw genome data SMaas 2007The range of genome sizes in the animal &amp; plant kingdoms! No cor
Lehigh - BIOS - 95
Principles and Ethics of Clinical ResearchJohn Glod, M.D., Ph.D. Departments of Pediatrics and Pharmacology Robert Wood Johnson Medical School The Cancer Institute of New JerseyGoals of clinical research New therapies Improving outcomes Reducin
Lehigh - BIOS - 95
Fluorescence Bioimaging in Translational ResearchKim Wicklund, PhDResearch Imaging Product Manager Scientific Equipment GroupOutline What is fluorescence? How can we put it in a biological system? How can we see it?LightElectromagnetic ener
Lehigh - CALC - 1,2,3
11.10 Taylor and Maclaurin Series Find the Taylor series (or Maclaurin Series) of a function Calculate the coefficients directly by using Theorem 5. Theorem 5 If f has a power series representation (expansion) at a, that is, iff (x) =n=0cn (x
Tulane - FINC - 725
Optimal Risky PortfoliosBKM Chapter 7Mean standard deviation diagrams Mean variance analysis: 2 risky assets Mean variance analysis: 3 or more risky assets Many risky assets and the risk-free asset Two Risky Assets; No risk-free asset (This mate
Tulane - FINC - 725
IV. DDM and FCFF Growth ModelWe examine some growth valuation models; A. B. C. D. E. F. The DDM- dividend discount model FCFF growth model Super-to-normal FCFF growth model Finding DDM from FCFF model Spreadsheet versus model approach Application to
Tulane - FINC - 725
FINC 727: Valuation and financing enterprises, GW II 3111Professor Robert S. HansenOVERVIEW Professor 865-5624 rob.hansen@tulane.edu Hours: M-144 GW II, Wed. 4-6 pm, and by appointment Faculty Assistant Ethel Matshiya 865-5666 Ethel is at the Mez
Lehigh - BIOS - 95
Contagious Others: The Egyptian Ophthalmia in Mary Shelley's FrankensteinElizabeth A. Dolanbdolan@lehigh.eduFrom Seeing Suffering in Women's Literature of the Romantic Period, Ashgate Press (2008)Plot summaryEmbedded narration Robert Walton (se
Lehigh - CALC - 1,2,3
7.4 Integration of Rational Functions by Partial FractionsThis section examines a procedure for decomposing a rational function into simpler rational functions to which we can apply the basic integration formulas.A. Partial Fraction Decomposition
Lehigh - CALC - 1,2,3
Lehigh - CALC - 1,2,3
Tulane - FINC - 725
Political Capital Politics &amp; Policy Let Capital Markets, Not Financial Firms, Govern Fate of IPOs By Alan Murray 897 words 10 September 2002 The Wall Street Journal A4 English (Copyright (c) 2002, Dow Jones &amp; Company, Inc.) IT HAS BEEN 13 YEARS since
Lehigh - CALC - 1,2,3
A Quick Introduction to Factor Analysis From Data Analysis: A Statistical Primer for Psychology Students by Edward L. Wike: . . . [T]here are elaborate extensions of r to multivariate data . . . another case is k variables (factor analysis). Fortunat
Lehigh - CALC - 1,2,3
February 11, 2005Announcements Review L'Hospital Rule Today 7.7 Approximate Integration What can you do when you are asked to estimate1 1e dx0x2or0cos(x3 ) dx?1Let f be a continuous function on [a, b]. Divide [a, b] into n subinterv
Lehigh - CALC - 1,2,3
February 14, 2005Announcements Reading for this Week: 7.8, 8.1 and 8.3. Midterm # 2 is next week! Thursday, February 24th (Covers 7.1 - 8.1) Start doing practice Midterms. Modification to Week 8 homework: Problems 1, 5, 7, 11, 12 and 15 in 8.3 a
Tulane - FINC - 725
FINC 727: Corporate transactions and business valuationProfessor Robert HansenAssignment 1. CAPM and WACC in valuationBLAZER TELECOM s has perpetual earnings before interest and taxes of $400, the corporate tax rate is 40%. BLAZER uses a debt-t
Lehigh - CALC - 1,2,3
11.12 Applications of Taylor Polynomials Taylor's Inequality Alternating Series Estimation Theorem Tn (x), Rn (x)1
Lehigh - CALC - 1,2,3
Formulas for Final Polar coordinates: x = r cos , y = r sin , r2 = x2 + y 2 , tan = y/x Identity satisfied by angle between two vectors: a b = |a|b| cos Vector projection of b onto a: proja (b) =ba |a| a |a| ba |a|The component of b in the dire
Lehigh - CALC - 1,2,3
February 28, 2005Announcements: Reading from the book: 9.1, 9.3 and 9.4. The last 2 homeworks will not be collected. Last quiz of the quarter, Tuesday March 1, 2005 Problems 1, 5, 7, 11, 12, and 15 from section 8.3 are not part of this week's as
Tulane - FINC - 725
III. DCF MethodsWe take up five DCF methods to value the firm with perpetual cash flow, a constant debt ratio, and risk-free debt. A.NPV B.IRR C.APV D.FTE E.CCF1Present value1 2 t t+1 t+2+-+-+-/ /-+-+-+-/ d1 d2 dt dt+1 dt+2 In classic form the
Lehigh - CALC - 1,2,3
Calculus 2: Some Results on Limits of SequencesWith limits of sequences, one very important situation is determining when a sequence has limit zero, which is necessary for the sum of the sequence to converge, though not enough to guarantee convergen