Fund of Software Dev 1
Fund of Software Dev 1 CSE 1001
Popular in Course
Popular in ComputerScienence
This 47 page Class Notes was uploaded by Theodora Daniel I on Monday October 12, 2015. The Class Notes belongs to CSE 1001 at Florida Institute of Technology taught by Staff in Fall. Since its upload, it has received 56 views. For similar materials see /class/221680/cse-1001-florida-institute-of-technology in ComputerScienence at Florida Institute of Technology.
Reviews for Fund of Software Dev 1
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 10/12/15
Exercise Complexity Implement the following two functions int searchSeqint array int key int searchBinaryint array int key The first function searches for key in an array of integers array using Sequential Search The second function searches for key in an array of integers array using Binary Search Both functions return the location if key is present in array and 1 otherwise The main program Use the main program on the labs webpage available alongside this document to Accept the problem size from the command line say n Fill an array say array with numbers from 1 to n Prompt the user to enter the key to search reading the same into a variable key Search key in array using Sequential Search Search key in array using Binary Search Time the search results see main program provided Varying the Problem Size 0 Execute the main program for different values of n Tabulate the search times for sequential search and binary search See sample table on next page Do you see which one is more efficient Why What is the complexity of Sequential and Binary Search in terms of O notation Sample Table of Results Problem Sequential inary Search Search Time sec Time sec 1390quot Solving a Quadratic Equation Implement the following functions double Discriminantdouble a double b double 0 Return the number b2 4ac double realPartdouble a double b Return the number b 2a double realPart2 double a double b double 0 Return the number VDiscriminanta b c 2a double imagPartdouble a double b double 0 Return the number V Discriminanua b c 2a The quadratic solver method Implement the following method to solve the quadratic equation ax2 bx c 0 a 35 0 void solveQuadratic double a double b double 0 If a is equal to zero then print Error not a quadratic equation Otherwise if Discriminanta b c is positive then Compute rootl realPartab realPart2abc Compute root2 realPartab realPart2abc Print the real roots rootl and root2 Otherwise if Discriminanta b c is equal to zero then Compute rootl realpartab Print the real root rootl Otherwise Compute realRoot realPartab Compute imagRoot imagParta b c Print the following formatted strings for the complex roots realRoot iimagRootquot and realRoot iimagRootquot The main method testing the quadratic solver Test the program by calling the method solveQuadratic in the main method as follows solveQuadratic300 1000 300 The real roots are 300 033 solveQuadratic100 8400 176400 The real root is 4200 solveQuadratic100 8500 176400 The real roots are 4900 3600 solveQuadratic100 400 900 The complex roots are 200 i224 200 i224 solveQuadratic000 400 900 Error not a quadratic equation Exercises Nested Loops Java An Introduction to Problem Solving amp Programming Walter Savitch Page 219 Problem 8 Write a program that asks the user to enter the size of a triangle to print out an integer from 1 to 50 then print the triangle by printing a series of lines consisting of asterisks The first line will have one asterisk the next two and so on with each line having one more asterisk than the previous line up to the number entered by the user On the next line print one less asterisk and continue by decreasing the number of asterisks by 1 for each successive line until only one asterisk is printed Hint Use nested for loops the outside loop controls the number of lines to print and the inside loop controls the number of asterisks to print on a line For example if the user enters 5 the output would be next page Output when the user enters 5 gtgtgtgtgtgtgtgtgt gtgtgtgtgtgtgt gtgtgtgtgt x A variation of the problem Write a Java program with the following specifications Input An integer height Output A triangle See example below Example lfthe input height is 5 then print the following XXXX gt gt gt gt 3 XXXX Exercise Use ofthe Function Split Write a Java program that reads an array of string entries parses each string read in the array and prints out the contents in a formatted manner Each string entry contains a student name major total credits earned and GPA These are separated by commas Sample Input Dialog User responses underlined Enter number of entries 5 Entry 1 Matthew Software Engineering 12 373 Entry 2 Charlotte Computer Science 9 382 Entry 3 Adam Applied Mathematics 15 400 Entry 4 Philip Aerospace Engineering 18 391 5 Entry Sarah Physics 6 364 Sample Output Dialog Name Major Earned GPA Credits Matthew Software Engineering 12 3 73 Charlotte Computer Science 9 3 82 Adam Applied Mathematics 15 400 Philip Aerospace Engineering 18 391 Sarah Physics 6 364 Exercise 1 Arrays What is the output of the following program char a new char3 char b int i I for i0 iltalength i ai b b2 System System a 139 System System XI I out out yl out out println al println a2 println al println a2 al a2 al a2 b11quot b11 b21quot b2 b11 quot b11 b2 quot b2 o I o I o I o I Exercise 2 Arrays and parameter passing What is wrong with the following method de nition that attempts to stretch an array to twice its original size public static void doubleSizeint a a new intalength 2 o I It will compile but does not work as you might hope Exercise 3 Algorithm Analysis How many lines are displayed in the execution of the following function as an expression in n n 2 O In terms of Onotation What is the asymptotic complexity of this expression public static void outputint n for int i0 iltn i for j 1 j lt n1 j Systemoutprintln2ij o I Exercise 4 Complexities of Sort and Search Algorithms Fill in the following table with Onotations of the averagecase complexities of the algorithms mentioned below Algorithm Complexity Selection sort Insertion Sort Sequential Search Threelevel nested loop Algorithm with no loops Exercise 5 Recursion What is the output of the following program public class RecursionExercise public static void mainString args SystemoutprintlnmysteryValue3 public static int mysteryValueint n if n lt 1 return 1 else return mysteryValuen 1 n Exercise 6 Recursion Complete the given method de nition Your de nition should be recursive Note that the exponent could be negative Hint 10 is 110 for negative values of n Also if n is negative then n is positive Parameter n can be any int Returns 10 to the power n 39k 39k public static double tenToTheint n Improvement to replicate Add another function replicate that prints the character 39 a specified number of times on one line The method should look Wke this public static void replicateint times I times is the number of times is printed on one line Test the method by making a call to replicate method in the main program like this replicate25 What shows up on the screen A 4x25 rectangle of stars In the main program use the replicate method in a loop to print a 4row rectangle with 25 symbols in each row An mxn rectangle of stars Modify the main function to print an mxn rectangle see dialog below Number of rows 2 Number of columns 7 Replicating any character Add a third function replicatechar symbol int times that prints a character symbol a specified number times times Modify the main function to call replicate with parametervalues 39 and 5 respectively replicate 5 What prints 0 I An mxn rectangle of characters Modify the main program to print an mxn rectangle of a specified symbol see dialog below Number of rows 2 Number of columns 7 Character to print x XXXXXXX XXXXXXX Hint mxn rectangle You cannot directly read a character from the keyboard Read in a string using keyboard next and extract the first character using the function charAt Amm 8 92 308 806398 CmSo Em mcoltm Em 3300 om lt0 932 9 m wxmo I 60686 9H t 038068 Io mco 938 m 935 I 60686 Qn i 038068 i i i Locations for Maximum and Minimum in an array Implement the following two functions that return the location of the maximum respectively minimum of an array num of double numbers int maxArrayLocdouble num int minArrayLocdouble num Do not print inside these functions Testing the two functions In the main function test the above two func ons Read numbers 135 78 34 142 67 58 10 into the array num Call method maxArrayLoc and print the return value This should print 3 Call method minArrayLoc and print the return value This should print 6 Where is this useful In the main function Prompt forthe userto enterthe number of students From the keyboard accept the number of students into a variable say nStudents Create thr double studentgrade arrays Homework Testl and Test2 each having nStudents elements Read each student s grades for Homework Test 1 and Test 2 between 0 and 100 inclusive into the three arrays Homework Testl and Test2 respectively Create a third array for the overall scores Overall having each element computed as follows Overall score 20 Homework 40 Test 1 40 Test 2 How many elements does Overall contain Student statistics Using the two functions maxArray and minArray print the following 1 2 The studentnumber starting from 1 not 0 Homework Test 1 and Test 2 scores of that student havinq the hiqhest overall score Homework Test 1 and Test 2 scores of that student havinq the least overall score Example Consider the scores of 6 students Homework scores 90 85 89 95 79 96 Test 1 scores 55 75 83 90 61 70 Test 2 scores 73 79 75 81 69 85 The program should print the following Overall Student Homework Test 1 Test 2 Number Minimum 5 790 610 690 Maximum 4 950 900 810 Introduction to BIueJ Venkatesh Ramamoorthy Venky Objectives To use BIueJ Familiarizing with the various facilities in BIueJ To type compile and execute simple JAVA programs To study Outputonly programs Inputoutput programs To understand programming errors Types of errors Difference between these types of errors Interpreting these errors in BIueJ The Hello World Program Download and study the following program in BIueJ What does the program do Students compile and execute the program Then students modify the program to display multiple lines Hello Wbrld Java is a fun programming language we enjoy this semester The Pledge Program I pIedge that every program with my name on It ts mrtttem by me and my co amthors tf amy amp that I toIIy understand the program I pIedge that every program I submit ts emttrer my own work mmIess otherwtse attrtbmteo I understand that the consequence of aoademte dtshomesty ts a grade of F for the eIass I ptedge to devote my eftorts to Iearhtmg Java by writing my own programs I shaII strive to be attentive to detatI amd wrtte programs that not ome oomptIe and execute correctty but are eastIy mmderstamdabIe by myseIt and other programmers The Example Program Download the following program textbook Answer the following questions What does the program do What are the program s inputs What are the program s outputs Students compile and execute the program Errors Three types of errors Compilation Syntax Runtime Logical Errors details Compilation errors Syntax errors Can be caught and corrected before program execution These are grammatical errors often called syntax errors Runtime errors System error during program execution Cannot be caught during compilation Logical errors Incorrect output or abnormal program execution Cannot be caught until the program executed at least once These are often caused due to human errors oversights Errors Exercise The previous program meant to add two numbers is now modified Download the following program Compile the program and execute it Analyze the different errors encountered Syntax errors Runtime errors Logical errors Correct them recompile and execute Improvement to replicate Add another function replicate that prints the character 39 a specified number of times on one line The method should look Wke this public static void replicateint times I times is the number of times is printed on one line Test the method by making a call to replicate method in the main program like this replicate25 What shows up on the screen A 4x25 rectangle of stars In the main program use the replicate method in a loop to print a 4row rectangle with 25 symbols in each row An mxn rectangle of stars Modify the main function to print an mxn rectangle see dialog below Number of rows 2 Number of columns 7 Replicating any character Add a third function replicatechar symbol int times that prints a character symbol a specified number times times Modify the main function to call replicate with parametervalues 39 and 5 respectively replicate 5 What prints 0 I An mxn rectangle of characters Modify the main program to print an mxn rectangle of a specified symbol see dialog below Number of rows 2 Number of columns 7 Character to print x XXXXXXX XXXXXXX Hint mxn rectangle You cannot directly read a character from the keyboard Read in a string using keyboard next and extract the first character using the function charAt Amm 8 92 308 806398 CmSo Em mcoltm Em 3300 om lt0 932 9 m wxmo I 60686 9H t 038068 Io mco 938 m 935 I 60686 Qn i 038068 i i i
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'