Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / CIT 120 – Computational Thinking Spring 2021 INSTRUCTIONS: The following project will test most, if not all, concepts we have studied throughout the semester

CIT 120 – Computational Thinking Spring 2021 INSTRUCTIONS: The following project will test most, if not all, concepts we have studied throughout the semester

Sociology

CIT 120 – Computational Thinking Spring 2021 INSTRUCTIONS: The following project will test most, if not all, concepts we have studied throughout the semester. You should go about answering the questions just as you did when completing the homework assignments. You should use pseudocode syntax to write your source code. Proper indention and formatting guidelines, as used throughout the semester must be used. You can find source code that uses proper formatting in the homework solutions that are posted in the Course Notebook. Failure to use the pseudocode and formatting used for the class will result in a question, or part of question, not being graded. You MUST use the pseudocode and formatting used in the class. Failure to use the correct syntax and formatting will result in deductions in the score for that question. You should record your solutions using the answer sheet provided. Good luck. 1. Max weighs 175 pounds using the English System of measurement. If we convert his weight to the Metric System, he will weigh 79.45 kilograms. If Paula weighs 145 pounds using the English System, what is her weight using the Metric System. To convert pounds from the English System to kilograms using the Metric System you multiply the number of pounds by .454 to get the number of kilograms. Write a program that will prompt the user for a weight, measured in pounds, and convert the weight to kilograms. There is no need for a loop in this problem. Your program only needs to convert on weight and then terminate. Problem Statement 2. Input Statement Output Example Write a program that asks the user for an employee’s annual salary before taxes. Print the employee’s salary and taxes. The taxes are 25% of the salary if the employee made less than $45,000, 33% if the employee made between $45,000 and $100,000, and 40% if the employee earned more than $100,000. You must use nested IF=THEN-ELSE statements and do not use the AND/OR statements. “Please input your annual salary before taxes: “ “Your salary after taxes is: “ a. Use a FOR-NEXT loop to print the odd numbers from -5 to 31 3. b. Use a WHILE loop to print numbers starting at 12 and ending with -30 in order (inclusive). c. Use a DO-UNTIL loop to print every fifth number starting at 75 and ending with 50. CIT 120 – Computational Thinking Final Exam (Spring 2021) Page 1 of 3 4. Bill would like to compute the average of his tips over a given number of days. You may ask Bill over how many days he would like to compute the average over and then ask for input for that many days. Write a program that will prompt Bill for the number of days that will be included in his calculation. The program should then prompt him for the total of his tips for each day. Once Bill has entered the total amount of tips for each day, your program should compute the average of the tips over the given amount of time. It should then tell Bill the average of his tips. Do not use an array to solve this problem. Gail would like to compute the average of the daily high temperature over some number of days. Write a program that will allow Gail to enter some number of temperatures and find the average of the temperature over the given number of days. Your program may not ask Gail how many temperatures she will be entering. To indicate that she is finished entering temperatures, she will enter a negative number. Your program should compute the average of the temperatures and output the average daily high and how many days the average was computed for. You should also indicate the high temperature of the set and the low temperature of the set. 5. An example would be if Gail entered 12 temperatures that resulted in an average daily high of 82 degrees. Your output statement would be “Hello user, the average daily high temperature was 82 degrees over 12 days” “The high temperature during the interim was 86 degrees” “The lowest temperature during the interim was 36 degrees” a. Declare an array named NewArray that is of type STRING that will hold ArraySize items. b. Write a program that will initialize an array of type STRING named BigArray of the size given by the user and stored in a variable named ArraySize. The initial value of the elements in the array should be set to “a”. 6. c. Write a loop that will copy an array named Array1 into a second array named Array2. The size of the arrays is held in a variable named ArraySize. d. Write a program that will take user input to fill an array of type numeric named TheArray that is of size TheSize. e. Write a program that will print the contents of an array of string type named PracticeArray whose size is held in a variable named ArraySize. 7. You have an array named BigArray that has been declared populated with STRINGS. The size of the array is held in a NUMERIC variable named TheSize. The items in the array are unique (no duplicates). Write a program that will prompt the user for the input of a STRING and store it in a STRING variable named SearchString. The program will then search through the array for a match to the input given by the user. If the program finds the match, it should stop searching and print the index of the array where the match was found. If the match is not found, it should print a “-1”. You should use the most efficient way of searching for the target item. CIT 120 – Computational Thinking Final Exam (Spring 2021) Page 2 of 3 a. What is a parameter list and where does one appear? b. What is an argument list and where is it used? 8. c. What is meant by the term “pass by value” and when is the term used? d. What is meant by the term “pass by reference” and when is the term used? e. What is meant when a method is said to be “VOID”? a. Write the header for a method named FindNum that returns a number and accepts 2 numbers and a string to do its job. 9. b. Write the header for a method named CopyTheArray. This method will accept two arrays of type numeric, and one number representing the number of items in the arrays. It will return nothing to the user. c. Write the header for a method named GetUserInput. This method will accept nothing through the parameter list and will return a string to the calling method. d. Write the header for a method named DoNothing that accepts nothing in the parameter list and returns nothing. CIT 120 – Computational Thinking Final Exam (Spring 2021) Page 3 of 3 Formatting Pseudocode For this course we will use a combination of pseudocode and BASIC (Beginner’s All-purpose Symbolic Instruction Code) to write programs. This document will define several commands used in pseudocode and it will also discuss formatting the pseudocode. You should consult your textbook for good practices for naming variables. Definition Pseudocode - A notation resembling a programming language but not intended for actual compilation. It usually combines some of the structure of a programming language with an informal natural-language description of the computations to be carried out. Common Commands NUMERIC – Used during declaration of a variable to determine it to be of numeric type Format NUMERIC variable name Example NUMERIC num1 This example declares a variable named num1 to be of type numeric. STRING – Used during declaration of a variable to determine it to be of string type Format STRING variable name Example STRING str1 This example declares a variable named str1 to be of type string. PRINT – In the simplest form, it is used to send output to “standard output” which we will consider to be the monitor. Format PRINT variable name PRINT some string of literals Example PRINT var1 Given that var1 is a variable, the line would sends the contents of the variable var1 to the monitor. PRINT “Hello World” The character string “Hello World”, not including the quotes, would be sent to the monitor PRINT “The contents of you variable are “; var1 We can print a string of literals in combination with the contents of a variable or even multiple variables by separating them with a semi-colon. CIT 120 Formatting Pseudocode Page 1 of 6 INPUT – In the simplest form, it is used to take input from “standard input” which we will consider to be the keyboard. Format Example INPUT variable name INPUT var1 INPUT “character string”; variable name Given that var1 is a variable, the line would take input from the keyboard buffer up to the end of line marker. INPUT “Please enter a number”; var1 The character string “Please enter a number” would be printed on the monitor and the cursor would wait at the end of that line. Input is given at the keyboard and then the buffer is taken as input up to the end of line marker. IF-THEN-ELSE – Used to implement a decision structure. Format IF condition 1 is true THEN statements ELSE statements ENDIF Indention is called for here to distinguish the body of pseudocode contained in the IF section of the structure. For our course we will use 5 spaces for indention levels. Do not use a TAB. CIT 120 Example IF var1 = 10 THEN PRINT “Today is a good day” ELSE PRINT “Today is not a good day” ENDIF If the variable var1 is equal to 10 then the character string “Today is a good day” is printed on the monitor. If var1 is not equal to 10 then the character string “Today is not a good day” is printed on the monitor. Formatting Pseudocode Page 2 of 6 Example Problem: Write the pseudocode for an application that allows a user to enter the number of minutes used on a cell phone and displays the phone bill. The calls cost 10 cents per minute plus 6% tax. Solution 1 START When a varialble is declared, memory is allocated in RAM that is the appropriate size NUMERIC minutes to hold the data type. The amount needed to minutes = 0 store different types of data may be NUMERIC billSubtotal different. billSubtotal = 0 NUMERIC totalBill totalBill = 0 Once the memory is allocated, we set the NUMERIC COST_PER_MINUTE = 0.10 variable to an initial value. This can be done to NUMERIC TAX_RATE = 0.06 provide a meaningful initial value or can be an PRINT “Enter the number of minutes used >> ” arbitrary value. Either way, when this is done, INPUT minutes the allocated memory location is purged and the billSubtotal = minutes * COST_PER_MINUTE new value is stored. totalBill = billSubtotal + billSubtotal * TAX_RATE PRINT “The total bill for ”; minutes; “ minutes used is ”; totalBill STOP Solution 2 START NUMERIC minutes = 0 NUMERIC billSubtotal = 0 NUMERIC totalBill = 0 NUMERIC COST_PER_MINUTE = 0.10 NUMERIC TAX_RATE = 0.06 INPUT “Enter the number of minutes used >> ”; minutes billSubtotal = minutes * COST_PER_MINUTE totalBill = billSubtotal + billSubtotal * TAX_RATE PRINT “The total bill for ”; minutes; “ minutes used is ”; totalBill STOP CIT 120 Formatting Pseudocode The steps of declaration and initialization can be combined into one line of pseudocode. We can combine the PRINT and INPUT statements by using the alternative form of the INPUT instruction. Page 3 of 6 FOR-NEXT Loop – used for accomplishing a definite number of repetitive tasks Format FOR loop counter variable = start value for loop counter TO ending value for loop counter STEP increment value body of the FOR-NEXT loop NEXT loop counter variable NOTE: If the loop increment value is 1, explicitly stating the STEP value is optional Example Example FOR i=0 TO 9 PRINT “Hello World” NEXT i FOR i=0 TO 10 STEP 2 PRINT “Hello World” NEXT i In this example the counter variable i starts at 0 and the last value it holds is 9. Each time the loop executes “Hello World” is printed on the monitor 10 times. The STEP value is 1 so it is optional to explicitly state it. The name chosen for the loop counter variable does not matter as long as it adheres to the rules of variable names. In this example the counter variable i starts at 0 and the last value it holds is 10. Each time the loop executes “Hello World” is printed on the monitor 6 times. The STEP value is 2 so it must be explicitly stated. The starting and ending values for these example is arbitrarily chosen and may differ in actual use. Example Example FOR i=17 TO 5 STEP -1 PRINT “Hello World” NEXT i In this example the counter variable i starts at 17 and the last value it holds is 5. Each time the loop executes “Hello World” is printed on the monitor 13 times. The STEP value is -1 so the loop counter actually decrements by 1. Since the STEP value is something other than positive 1 it must be explicitly listed. CIT 120 NUMERIC firstNum = 0 NUMERIC secondNum = 0 NUMERIC aValue = 0 the values for firstNum, secondNum, and aValue are set within the program FOR i=firstNum TO secondNum STEP aValue PRINT “Hello World” NEXT i In this example the counter variable i starts at the value held in the variable firstNum and goes to the value held in the variable secondNum in increments of the number held in the variable aValue. Of course in this case certain care would need to be taken so that the values of these variables are restricted to values that would actually work with the given FOR-NEXT loop. Formatting Pseudocode Page 4 of 6 WHILE Loop – used when performing a repetitive task an indefinite number of times Format WHILE (condition 1) body of WHILE loop ENDWHILE NOTE: The WHILE loop will continue to execute as long as the stated condition is true. Care must be taken that there is the possibility within the loop that the condition could become false in order for the WHILE loop to terminate execution. Failing to do so will result in an infinite loop. The WHILE loop is known as a pre-condition loop which means the condition for the loop is checked before the loop is executed. If the condition is true, the loop will execute. If the condition is not true then the loop will not execute. Example Example NUMERIC firstNum = 1 NUMERIC secondNum = 10 WHILE (firstNum < secondNum) PRINT “BCTC Rules” firstNum = firstNum + 1 ENDWHILE STRING aPhrase = “” WHILE (aPhrase “quit”) INPUT “Input the phrase ‘quit’ to stop”; aPhrase ENDWHILE This loop starts by checking the condition that firstNum is less than secondNum. In this example it is so the loop executes. The literal string “BCTC Rules” is printed on the monitor. Next the value of firstNum is increased by one. The loop reaches the ENDWHILE line and returns to the beginning of the loop and checks the condition to see if it is true. As long as the condition continues to be true, the loop will continue to execute. Once the condition fails then the execution of the program will go to the line of code appearing just after the ENDWHILE statement. If the statement “firstNum=firstNum + 1” was missing from the loop, the loop would never terminate making it an infinite loop. CIT 120 This loop starts by checking the condition that the variable aPhrase is not equal to “quit”. As the pseudocode is written here, it will not be. The condition is checked and is true so the loop executes. Notice, within the loop the user is given the opportunity to enter “quit”. The input from the user is taken and then the program flow returns to the WHILE statement and checks the condition. If the user entered “quit” the program flow will go to the line appearing after ENDWHILE. If the user entered anything other than “quit” the loop will execute again. The string the user enters must match exactly to the sentinel value which is the value that will halt the execution of the loop. In this example the sentinel value is “quit”. Formatting Pseudocode Page 5 of 6 Example STRING aPhrase = “” NUMERIC loopcounter = 0 WHILE (aPhrase “quit”) loopcounter = loopcounter + 1 INPUT “Input the phrase ‘quit’ to stop”; aPhrase ENDWHILE Taking the previous example, we can modify it slightly to show how a loop counter can be used to count the number of executions of the loop. We declare and initialize a variable that will act as our loop counter. The variable name is not important and the only requirement is that it observe the rules in place for creating variable names. The loop works the same way as in the previous example. The condition is checked and if it is true then the loop executes. The first time it executes the loop counter is increase by a value of 1 from 0 to the new value of 1. The user is prompted for input next and then the program flow returns to the beginning of the loop. Since the loop counter variable was initially set to 0, if the value of the variable aPhrase had been changed within a larger program before this loop was executed and the loop condition was evaluated to false then the loop would not be executed. The value of the loop counter would remain at 0 which would be correct since the loop never executed. DO-UNTIL Loop – used as a post-condition loop to perform repetitive tasks. Format DO body of DO-UNTIL loop UNTIL (condition 1) NOTE: The DO-UNTIL loop will continue to run as long as condition 1 is false. In other words, the loop will execute until condition 1 is true and then execution stops and program flow goes to the line of code appearing after the UNTIL statement. The body of the DO-UNTIL loop will execute one time before the condition is checked. For this reason, it is known as a post-condition loop. Example Example NUMERIC firstNum = 1 NUMERIC secondNum = 10 DO PRINT “BCTC Rules” firstNum = firstNum + 1 UNTIL (firstNum = secondNum) STRING aPhrase = “” DO INPUT “Input the phrase ‘quit’ to stop”; aPhrase UNTIL (aPhrase = “quit” This loop will perform like a similar example for a WHILE loop except this loop will execute at least one time since the condition is not checked until after the loop has executed. Notice how the condition is stated differently to work with the DOUNTIL loop. This loop will continue to execute until the value of the variable firstNum is equal to the value of secondNum. CIT 120 This loop is written to perform like the WHILE loop example given above with the same exception, the loop will run at least one time.

Option 1

Low Cost Option
Download this past answer in few clicks

19.89 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE