hw01
.pdf
keyboard_arrow_up
School
Palomar College *
*We aren’t endorsed by this school
Course
128
Subject
Computer Science
Date
May 17, 2024
Type
Pages
10
Uploaded by ConstableSteel14439 on coursehero.com
hw01
May 16, 2024
[3]:
# Initialize Otter
import
otter
grader
=
otter
.
Notebook(
"hw01.ipynb"
)
1
Homework 1: Causality and Expressions
Please complete this notebook by filling in the cells provided. Before you begin, run the previous
cell to load the provided tests.
Recommended Readings:
•
What is Data Science?
•
Causality and Experiments
•
Programming in Python
For all problems that you must write explanations and sentences for, you
must
provide your answer
in the designated space. Moreover, throughout this homework and all future ones, please be sure
to not re-assign variables throughout the notebook! For example, if you use
max_temperature
in
your answer to one question, do not reassign it later on.
Otherwise, you will fail tests that you
thought you were passing previously!
Note: This homework has hidden tests on it. That means even though tests may say
100% passed, it doesn’t mean your final grade will be 100%. We will be running more
hidden tests for correctness once everyone turns in the homework.
Directly sharing answers is not okay, but discussing problems with the course staff or with other
students is encouraged.
You should start early so that you have time to get help if you’re stuck.
1.1
1. Scary Arithmetic
An ad for ADT Security Systems says,
“When you go on vacation, burglars go to work […] According to FBI statistics, over
25% of home burglaries occur between Memorial Day to Labor Day.”
Do the data in the ad support the claim that burglars are more likely to go to work during the
time between Memorial Day to Labor Day? Please explain your answer.
(6 Points)
Note:
You can assume that “over 25%” means only slightly over.
Had it been much over, say
closer to 30%, then the marketers would have said so.
1
Note:
Memorial Day is observed on the last Monday of May and Labor Day is observed on the
first Monday of September.
Burglars are not more likely to go to work during the time between Memorial Day to Labor Day.
The duration of time between Memorial Day and Labor Day is about 25% of the year, which
accounts for 25% of home burglaries.
That means the other 75% of the year sees 75% of home
burglaries, which is the same ratio as the previous statistic. I can conclude that home burglaries
occur pretty evenly throughout the year.
1.2
2. Characters in Little Women
In lecture, we counted the number of times that the literary characters were named in each chapter
of the classic book,
Little Women
. In computer science, the word “character” also refers to a letter,
digit, space, or punctuation mark; any single element of a text.
The following code generates a
scatter plot in which each dot corresponds to a chapter of
Little Women
. The horizontal position
of a dot measures the number of periods in the chapter. The vertical position measures the total
number of characters.
[2]:
# Just run this cell.
# This cell contains code that hasn't yet been covered in the course,
# but you should be able to interpret the scatter plot it generates.
from
datascience
import
*
from
urllib.request
import
urlopen
import
numpy
as
np
import
d8error
%
matplotlib
inline
little_women_url
=
'https://www.inferentialthinking.com/data/little_women.txt'
chapters
=
urlopen(little_women_url)
.
read()
.
decode()
.
split(
'CHAPTER '
)[
1
:]
text
=
Table()
.
with_column(
'Chapters'
, chapters)
Table()
.
with_columns(
'Periods'
,
np
.
char
.
count(chapters,
'.'
),
'Characters'
, text
.
apply(
len
,
0
)
)
.
scatter(
0
)
2
Question 1.
Around how many periods are there in the chapter with the most characters? Assign
either 1, 2, 3, 4, or 5 to the name
characters_q1
below.
(4 Points)
1. 250
2. 390
3. 440
4. 32,000
5. 40,000
Note:
If you run into a
NameError: name 'grader' is not defined
error in the autograder cell
below (and in any assignment), please re-run the first cell at the very top of this notebook!
[3]:
characters_q1
= 2
[4]:
grader
.
check(
"q2_1"
)
[4]:
q2_1 results: All test cases passed!
The test above checks that your answers are in the correct format.
This test does not check that
you answered correctly
, only that you assigned a number successfully in each multiple-choice
answer cell.
3
Question 2.
Which of the following chapters has the most characters per period? Assign either
1, 2, or 3 to the name
characters_q2
below.
(4 Points)
1. The chapter with about 60 periods
2. The chapter with about 350 periods
3. The chapter with about 440 periods
[5]:
characters_q2
= 1
[6]:
grader
.
check(
"q2_2"
)
[6]:
q2_2 results: All test cases passed!
Again, the test above checks that your answers are in the correct format, but not that you have
answered correctly.
To discover more interesting facts from this plot, check out
Section 1.3.2
in the textbook.
1.3
3. Names and Assignment Statements
Question 1.
When you run the following cell, Python produces a cryptic error message.
[7]:
4 = 2 + 2
Cell
In[7], line 1
4 = 2 + 2
^
SyntaxError:
cannot assign to literal here. Maybe you meant '==' instead of '='?
Choose the best explanation of what’s wrong with the code, and then assign 1, 2, 3, or 4 to
names_q1
below to indicate your answer.
(4 Points)
1. Python is smart and already knows
4 = 2 + 2
.
2. In Python, it’s a rule that the
=
sign must have a variable name to its left, and
4
isn’t a
variable name.
3. It should be
2 + 2 = 4
.
4. I don’t get an error message. This is a trick question.
[8]:
names_q1
= 2
[9]:
grader
.
check(
"q3_1"
)
[9]:
q3_1 results: All test cases passed!
Question 2.
When you run the following cell, Python will produce another cryptic error message.
4
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
Use C language only.
Create a program that will ask for
Enter number of students: (for this example 2)
Enter student 1's name:
Enter student 1's age:
Enter student 2's name: E
nter student 2's age:
At the end, the program shall display two class lists: one with arranged name (ascending order) and the other one arranged according to their age (ascending order).
The two lists should contain the complete details of the students as follows: Sorted by name:
1. name, age
2. name, age
Sorted by age:
1. name, age
2. name, age
If the number of students is less than one, the program will display "no students to display."
The letter case (uppercase or lowercase) shall have no bearing in the arrangement of names. Please use the "fgets()" in getting the name.
arrow_forward
Write JAVA code
General Problem Description:
It is desired to develop a directory application based on the use of a double-linked list data structure, in which students are kept in order according to their student number. In this context, write the Java codes that will meet the requirements given in detail below.
Requirements:
Create a class named Student to represent students. In the Student class; student number, name and surname and phone numbers for communication are kept. Student's multiple phones
number (multiple mobile phones, home phones, etc.) so phone numbers information will be stored in an “ArrayList”. In the Student class; parameterless, taking all parameters and
It is sufficient to have 3 constructor methods, including a copy constructor, get/set methods and toString.
arrow_forward
Python question
Analysis: Computational Complexity (Q14-15)
In this section, you are asked to analyse the worst-case computational time complexity of Python functions. Always identify the order of growth in the tightest and simplest possible form using big-O notation, e.g., write O(n) instead of O(2n+n/2).
Question 14 (Complexity 1)
State the overall worst-case time complexity of the below function and provide a short explanation of your answer. The function accepts an integer n as input.
def mystery(n): num = 1 count = 0 while num < n: num = num*2 count += 1 return count
Question 15 (Complexity 2)
State the overall worst-case time complexity of the below function and provide a short explanation of your answer. The function is supposed to return a list, res, containing the duplicated elements in the given list , lst, of size n. Analyse the function in terms of the length of the list, n.
def duplicate_values(lst): res = [] for i in range(len(lst)):…
arrow_forward
please code in python
Forbidden concepts: recursion, custom classes
Create a program for a used car dealership that buys and sells cars. The dealership currently has an S14, 240z, R33, and a 350z. The program must keep track of inventory. There must be options to add, remove, or print the list of cars, along with a killswitch.
arrow_forward
Art.java
In this part you will create a program Art.java that produces a recursive drawing of the design attached in the picture.
Requirements
Art.java must take one (1) integer command-line argument n that controls the depth of recursion.
Your drawing must stay within the drawing window when n is between 1 and 7. (The autograder will not test values of n outside of this range.)
You may not change the size of the drawing window (but you may change the scale). Do not add sound.
Your drawing can be a geometric pattern, a random construction, or anything else that takes advantage of recursive functions.
Optionally, you may use the Transform2D library you implemented in Part 1. You may also define additional geometric transforms in Art.java, such as sheer, reflect across the x- or y- axis, or rotate about an arbitrary point (as opposed to the origin).
Your program must be organized into at least three separate functions, including main(). All functions except main() must be private.
call…
arrow_forward
Write Java Program Mr. Patrick is fond of reading books he is looking for a computerized way to keep record of his book collection, you have been given the responsibility to meet up his following requirements. (Use appropriate data structure to accomplish your task), develop following methods: 1. Add(): adds a new book to the list ( A book contains name of the book, author name) NOTE: every new book will have access to its neighboring books (previous and next) 2. Remove():in case any book is removed from the pile update your list 3. countBooks(): displays the total number of books 4. search(): returns true if the given book is present in the list else returns false 5. display(): shows the book collection
arrow_forward
Python Answer Required:
A Rajesh teaches a cooking class. The course is attended by NN students, numbered 11 to NN.
The cook must participate in the presence before each class, i.e. call out the names of the
students one by one and indicate which students are present. Each student has a first and last
name. To save time, Rajesh only wants to call up students' first names. However, if there are
multiple students with the same first name, the Rajesh must call out the full names (first and last
names) of all those students. For any student who does not share a first name with any other
student, the cook can still only call that student's first name.
Help the Rajesh decide for each student whether to call that student's full name or just their first
name.
Input
1
1
hasan jaddouh
Output
hasan
arrow_forward
CSCI 2436:01L Data Structures Lab
Lab 1 - Chapter 4 The Efficiency of Algorithms
In this lab, you will practice how to measure the running time f a section of code in Java. One
approach is to use System.nano Time() where the current time is stored as a long integer equals to
the number of nanoseconds. By subtracting the starting time in nanoseconds from the ending time in
nanoseconds, you get the run time-in nanoseconds of a section of code.
public static void main(String[] args) {
int n1 = 10, n2 = 100, n3 = 1000, n4 = 10000;
long n1Time, n2Time, n3Time, n4Time;
n1Time AlgorithmA (nl);
For example, suppose that AlgorithmA is the name of a method you wish to time. The following
statements will compute the number of nanoseconds that AlgorithmA requires to execute:
}
public static long AlgorithmA (int n) {
long startTime, endTime, elapsedTime;
startTime = System.nanoTime ();
int sum = 0;
for (int i = 1; i 0
1
2. By midnight, Tuesday, Jan 24th, submit your Java source file and a…
arrow_forward
Q/ Write a program in C# that lets the user to define the number of rows and columns. Then, the
program reads the matrix and finds the index of the even and odd numbers and display them with their
corresponding indices. Use adequate messages during the program execution.
arrow_forward
Part III - Create Your Own Art
Art.java
In this part you will create a program Art.java that produces a recursive drawing of your own design. This part is meant to be fun, but here are some guidelines in case you're not so artistic.
Requirements
Art.java must take one (1) integer command-line argument n that controls the depth of recursion.
Your drawing must stay within the drawing window when n is between 1 and 7. (The autograder will not test values of n outside of this range.)
You may not change the size of the drawing window (but you may change the scale). Do not add sound.
Your drawing can be a geometric pattern, a random construction, or anything else that takes advantage of recursive functions.
Your program must be organized into at least three separate functions, including main(). All functions except main() must be private.
For full credit, Art.java must not be something that could be easily rewritten to use loops in place of recursion, and some aspects of the recursive…
arrow_forward
Write VBA CODE FOR THE FOLLOWING PROBLEM
Problem:
The Worksheet named Grades contains a place for students to record the grades they have received in their classes. Students put the number of each letter grade received in the B column. (For example, the worksheet currently shows that the student has taken 9 classes and made five As, one B, one C, one D, and one F as grades. You need to write a program that reads the grades from the worksheet and uses a function to calculate the student’s GPA. For this problem you can assume that all classes are worth the same number of credit hours. The function should send back the GPA to the calling procedure. The procedure will then put up a message box that gives the student their GPA and a message about their GPA, all in one message box. The message should be “You qualify for an internship” if the student has a GPA of at least 3.0. It should be “You’re in the danger zone” if the GPA is between 2.0 and 3.0. And it should be “You are on…
arrow_forward
### Q5: Reduce No Change Python
def reduce_no_change(fn, lst, base):
"""Same as Q4. However, preserve the lst in this problem.
Object can be any python type which the input
Not Allowed To Import Libraries
Args:
fn (function): Combination function which takes in two arguments and return
an value with the same type as the second argument
lst (List): A list of any type
base (Object): A value of custom type which fn can handle.
Returns:
Object: A value after applying fn on lst.
>>> reducer = lambda x, y: x + y
>>> lst = [1, 2, 3]
>>> a = reduce_lst(reducer, lst, 0)
>>> a # a = reducer(reducer(reducer(base, lst[0]), lst[1]), lst[2])
6
>>> lst
>>> [1, 2, 3] # we preserve the list
"""
### Modify your code here
### Modify your code here
arrow_forward
Objectives
Java refresher (including file I/O)
Use recursion
Description
For this project, you get to write a maze solver. A maze is a two dimensional array of chars. Walls are represented as '#'s and ' ' are empty squares. The maze entrance is always in the first row, second column (and will always be an empty square). There will be zero or more exits along the outside perimeter. To be considered an exit, it must be reachable from the entrance. The entrance is not an exit.Here are some example mazes:mazeA
7 9
# # #####
# # # #
# # # ###
# # #
# ##### #
# #
#########
mazeB
7 12
# ##########
# # # #
# # # #### #
# # # #
# ##### ## #
# # #
############
mazeC
3 5
# # #
## ##
Requirements
Write a MazeSolver class in Java. This program needs to prompt the user for a maze filename and then explore the maze. Display how many exits were found and the positions (not indices) of the valid exits. Your program can display the…
arrow_forward
CodeWorkout
Gym
Course
Search exercises...
Q Search
kola shreya@colum
X459: Review-
Fibonacci
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, characterized by the fact that
every number after the first two is the sum of the two preceding ones:
e, 1, 1, 2, 3, 5, 8, 13,
Write a recursive function that the returns the nth fibonacci number.
Examples:
fibonacci(0) -> 0
fibonacci(1) -> 1
fibonacci(7) -> 13
Your Answer:
1 public int fibonacci(int n) {
2
3}
4
CodeWorkout © Virginia Tech
About
License
Privacy
Contact
arrow_forward
Common Time Zones
Function Name: commonTimeZones()
Parameters: code1( str ) , code2( str )
Returns: list of common time zones ( list )
Description: You and your friend live in different countries, but you figure there's a chance that
both of you might be in the same time zone. Thus, you want to find out the list of possible time
zones that you and your friend could both be in. Given two country codes, write a function that returns a list of the time zones the two countries have in common. Be sure not to include any duplicate time zones. If the two country codes do not have any common time zones, return the string 'No Common Time Zones' instead.
Note: You can assume that the codes will always be valid.
example test cases:
>>> commonTimeZones('can', 'usa')
['UTC-08:00', 'UTC-07:00', 'UTC-06:00', 'UTC-05:00', 'UTC-04:00']
>>> commonTimeZones('rus', 'chn')
['UTC+08:00']
For this assignment, use the REST countries API…
arrow_forward
Please code in python
Forbidden concepts: recursion, custom classes
A grocery store needs to track whether their specific apple types are in stock. Create a program the takes in all the types of apples in stock in the morning and when the user searches for a specific apple, it tells them whether it’s in stock or not.
arrow_forward
Common Time Zones
Function Name: commonTimeZones()
Parameters: code1( str ), code2( str)
Returns: list of common time zones ( list )
Description: You and your friend live in different countries, but you figure there's a chance that
both of you might be in the same time zone. Thus, you want to find out the list of possible time
zones that you and your friend could both be in. Given two country codes, write a function that
returns a list of the time zones the two countries have in common. Be sure not to include any
duplicate time zones. If the two country codes do not have any common time zones, return the
string 'No Common Time Zones' instead.
Note: You can assume that the codes will always be valid.
example test cases:
>>> commonTimeZones('can', 'usa')
[UTC-08:00', 'UTC-07:00', 'UTC-06:00', 'UTC-05:00', 'UTC-04:00]
>>> commonTimeZones('rus', 'chn')
[UTC+08:00]
For this assignment, use the REST countries API
(https://restcountries.com/#api-endpoints-v2).
For all of your requests, make…
arrow_forward
CODING LANGUAGE: R (similar to python)
R is a programming language for statistical computing and graphics supported by the R Core Team and the R Foundation for Statistical Computing.
The Behdel TestThe Bechdel test asks whether a work of fiction features at least two women who talk to each otherabout something other than a man, and there must be two women named characters.In this mini analysis we work with the data used in the FiveThirtyEight story titled:"The Dollar-And-Cents Case Against Hollywood's Exclusion of Women"https://fivethirtyeight.com/features/the-dollar-and-cents-case-against-hollywoods-exclusion-of-women/Start with loading the packages: fivethirtyeight, tidyverse1. What information does this dataset contain? What commands did you use to see this?For our purposes of analysis we will focus our analysis on movies released between 1990 and 2013.bechdel90_13 <- bechdel %>%filter(between(year, 1990, 2013))2. How many movies are in our filtered data set?The…
arrow_forward
Data Structures
the hasBalancedParentheses () method. Note: this can be done both iteratively or recursively,
but I believe most people will find the iterative version much easier.
C++: We consider the empty string to have balanced parentheses, as there is no imbalance. Your
program should accept as input a single string containing only the characters ) and (, and output a
single line stating true or false. The functionality for reading and printing answers is written in the
file parentheses.checker.cpp; your task is to complete the has balanced.parentheses ()
function.
**Hint: There's a pattern for how to determine if parentheses are balanced. Try to see if you can find
that pattern first before coding this method up.
arrow_forward
C++ PROGRAMMINGTopic: HashTable - PolyHash Quadratic
Explain the c++ code below.: SEE ATTACHED PHOTO FOR THE PROBLEM INSTRUCTIONS It doesn't have to be long, as long as you explain what the important parts of the code do. (The code is already implemented and correct, only the explanation needed). You can also explain line by line for an upvote, thanks.
EXPLAIN THE CODE BELOW:
#include <cstdlib>
#include <math.h>
#include <cstring>
#include <iostream>
using namespace std;
class HashTable {
string* table;
int N;
int count;
// TODO: Polynomial Hash Code using a=7
int hash_code(string key) {
int code;
int hash = 0;
for (int i = 0; i < key.size(); i++) {
char ch = key[i];
code += ((ch - 96) * pow(7, key.size() - (i + 1)));
}
return code;
}
// TODO: This hash table uses a MAD compression function
// where a = 11, b = 461, p = 919
int compress(int code) {
return (((11*code)+461) % 919) % N;
}…
arrow_forward
Write a program in Java, Python and Lisp
When the program first launches, there is a menu which allows the user to select one of the following five options:
1.) Add a guest
2.) Add a room
3.) Add a booking
4.) View bookings
5.) Quit
The functionality of these options is as follows:
1.) When users add a guest they provide a name which is stored in some manner of array or list. Guests are assigned a unique ID value where the first guest added is assigned the ID value 1, the second guest added is assigned the ID value 2 and so on.
2.) When users add a room they provide a room number and a room capacity (i.e. how many people can stay in the room at any one time) which is stored in some manner of array or list. Rooms have a property which indicates if they are booked or not for any given date – please see the Room Booking Dates section below for some guidance on the easiest way to implement this.
3.) When users add a booking they provide a guest ID, room number, the number…
arrow_forward
Topical Information
Use C++. This lab is designed to give you practice with labeled data in files. Again, classes can help ease your design woes.
Program Information
Write a program that transfers the contents of one file to a second file. The first file will contain an arbitrary (unknown) number of data groups. A data group will normally consist of a person's name (a string containing spaces), the person's student ID (a large integer), the person's GPA (a floating point number), and the person's gender (a character).
The data in each group should be in a labeled data format. Be sure to use some kind of string library to help you with the label/value processing (as we discussed in class). (The library provided here is good but not everything you'll need. You still need functions to convert strings into integers and into floating point numbers. string to bool, string to string, and string to character conversions should be fairly easy.)
You can choose the actual values to use for the…
arrow_forward
PYTHON:Please help me fix my code. It was supposed to ask the user to input an inorder traversal and let them choose whether to enter postorder or preorder, then identify the order of the missing traversal, just like the image below. However, my code can only identify the POSTORDER traversal but not the PREORDER. There is something wrong with my def function on def PreOrderT(). Please help me fix it. Thank you.
# Main programinorder_list = []preorder_list = []postorder_list = []n = int(input("How many nodes want to enter? "))
# Methodsdef searchR(arr, x, n): # CHANGED THE NAME OF FUNCTION AS THERE ARE TWO FUNCTION WITH SAME NAME for i in range(n): if (arr[i] == x): return i
return -1
def PostOrderT(Ino, preo, n): root = searchR(Ino, preo[0], n) if (root != 0): PostOrderT(Ino, preo[1:n], root) if (root != n - 1): PostOrderT(Ino[root + 1:n], preo[root + 1:n], n - root - 1) print(preo[0], end=" ")
# Make new nodeclass…
arrow_forward
C++ Progrmaing
Instructions
Redo Programming Exercise 6 of Chapter 8 using dynamic arrays. The instructions have been posted for your convenience.
The history teacher at your school needs help in grading a True/False test. The students’ IDs and test answers are stored in a file. The first entry in the file contains answers to the test in the form:
TFFTFFTTTTFFTFTFTFTT
Every other entry in the file is the student ID, followed by a blank, followed by the student’s responses. For example, the entry:
ABC54301 TFTFTFTT TFTFTFFTTFT
indicates that the student ID is ABC54301 and the answer to question 1 is True, the answer to question 2 is False, and so on. This student did not answer question 9 (note the empty space). The exam has 20 questions, and the class has more than 150 students. Each correct answer is awarded two points, each wrong answer gets one point deducted, and no answer gets zero points. Write a program that processes the test data. The output should be the student’s ID,…
arrow_forward
Ocelot/PuTTY(C Language)
Through this programming assignment, the students will learn to do the following:
Learn to work with command line options and arguments
Gain more experience with Makefiles
Gain more experience with Unix
Learn to use some of the available math funtions available with C
Usage: mortgagepmt [-s] -r rate [-d downpayment] price
In this assignment, you are asked to do a mortgage payment calculation. All information needed for this will be passed to the program on the command line. There will be no user input during the execution of the program.
You will need a few pieces of information. The price of the home and the amount of the down payment. You will also need to know the interest rate and the term of the mortgage. To figure your mortgage payment, start by converting your annual interest rate to a monthly interest rate by dividing by 12. Next, add 1 to the monthly rate. Third, multiply the number of years in the term of the mortgage by 12 to calculate the number…
arrow_forward
please code in python
Forbidden concepts: arrays/lists (data structures), recursion, custom classes
Watch this video on the Fibonacci sequence. The first two numbers of the sequence are 1 and 1. The subsequent numbers are the sum of the previous two numbers. Create a loop that calculates the Fibonacci sequence of the first 25 numbers and prints each one.Lastly, state the 25th and 24th sequence in a sentence, and explain how the golden ratio is conducted from it, including what it is.Note: you don’t know what the 24th and 25th numbers are, get the program to find out and calculate itself what the ratio is.
arrow_forward
c++
Redo Programming Exercise 6 of Chapter 8 using dynamic arrays. The instructions have been posted for your convenience.
The history teacher at your school needs help in grading a True/False test. The students’ IDs and test answers are stored in a file. The first entry in the file contains answers to the test in the form:
TFFTFFTTTTFFTFTFTFTT
Every other entry in the file is the student ID, followed by a blank, followed by the student’s responses. For example, the entry:
ABC54301 TFTFTFTT TFTFTFFTTFT
indicates that the student ID is ABC54301 and the answer to question 1 is True, the answer to question 2 is False, and so on. This student did not answer question 9 (note the empty space). The exam has 20 questions, and the class has more than 150 students. Each correct answer is awarded two points, each wrong answer gets one point deducted, and no answer gets zero points. Write a program that processes the test data. The output should be the student’s ID, followed by the answers,…
arrow_forward
Programming: C#(C sharp)
without using (array, while and furthermore advance loop)
Someone i know posted this here already but he got the wrong answer. I was hoping i can get the right one.
arrow_forward
In C
In this problem, you will recreate one of the truly great moments in history, namely the classic race of the tortoise and the hare. You will use random number generation to develop a simulation of this memorable event and use pointers to store / track the position of the two race contestants.
Our contenders begin the race at “square 1” of 70 squares. Each square represents a possible position along the race course. The finish line is at square 70. The first contender to reach or pass square 70 is rewarded with a pail of fresh carrots and lettuce. The course weaves its way up the side of a slippery mountain, so occasionally the contenders lose ground.
There is a clock that ticks once per second. With each tick of the clock, your program should adjust the position of the animals according to the rules shown in the table below.
Implement the “race course” as an integer array containing the numbers from 1 to 70.
Implement the positions of the tortoise and the hare as pointers,…
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Related Questions
- Use C language only. Create a program that will ask for Enter number of students: (for this example 2) Enter student 1's name: Enter student 1's age: Enter student 2's name: E nter student 2's age: At the end, the program shall display two class lists: one with arranged name (ascending order) and the other one arranged according to their age (ascending order). The two lists should contain the complete details of the students as follows: Sorted by name: 1. name, age 2. name, age Sorted by age: 1. name, age 2. name, age If the number of students is less than one, the program will display "no students to display." The letter case (uppercase or lowercase) shall have no bearing in the arrangement of names. Please use the "fgets()" in getting the name.arrow_forwardWrite JAVA code General Problem Description: It is desired to develop a directory application based on the use of a double-linked list data structure, in which students are kept in order according to their student number. In this context, write the Java codes that will meet the requirements given in detail below. Requirements: Create a class named Student to represent students. In the Student class; student number, name and surname and phone numbers for communication are kept. Student's multiple phones number (multiple mobile phones, home phones, etc.) so phone numbers information will be stored in an “ArrayList”. In the Student class; parameterless, taking all parameters and It is sufficient to have 3 constructor methods, including a copy constructor, get/set methods and toString.arrow_forwardPython question Analysis: Computational Complexity (Q14-15) In this section, you are asked to analyse the worst-case computational time complexity of Python functions. Always identify the order of growth in the tightest and simplest possible form using big-O notation, e.g., write O(n) instead of O(2n+n/2). Question 14 (Complexity 1) State the overall worst-case time complexity of the below function and provide a short explanation of your answer. The function accepts an integer n as input. def mystery(n): num = 1 count = 0 while num < n: num = num*2 count += 1 return count Question 15 (Complexity 2) State the overall worst-case time complexity of the below function and provide a short explanation of your answer. The function is supposed to return a list, res, containing the duplicated elements in the given list , lst, of size n. Analyse the function in terms of the length of the list, n. def duplicate_values(lst): res = [] for i in range(len(lst)):…arrow_forward
- please code in python Forbidden concepts: recursion, custom classes Create a program for a used car dealership that buys and sells cars. The dealership currently has an S14, 240z, R33, and a 350z. The program must keep track of inventory. There must be options to add, remove, or print the list of cars, along with a killswitch.arrow_forwardArt.java In this part you will create a program Art.java that produces a recursive drawing of the design attached in the picture. Requirements Art.java must take one (1) integer command-line argument n that controls the depth of recursion. Your drawing must stay within the drawing window when n is between 1 and 7. (The autograder will not test values of n outside of this range.) You may not change the size of the drawing window (but you may change the scale). Do not add sound. Your drawing can be a geometric pattern, a random construction, or anything else that takes advantage of recursive functions. Optionally, you may use the Transform2D library you implemented in Part 1. You may also define additional geometric transforms in Art.java, such as sheer, reflect across the x- or y- axis, or rotate about an arbitrary point (as opposed to the origin). Your program must be organized into at least three separate functions, including main(). All functions except main() must be private. call…arrow_forwardWrite Java Program Mr. Patrick is fond of reading books he is looking for a computerized way to keep record of his book collection, you have been given the responsibility to meet up his following requirements. (Use appropriate data structure to accomplish your task), develop following methods: 1. Add(): adds a new book to the list ( A book contains name of the book, author name) NOTE: every new book will have access to its neighboring books (previous and next) 2. Remove():in case any book is removed from the pile update your list 3. countBooks(): displays the total number of books 4. search(): returns true if the given book is present in the list else returns false 5. display(): shows the book collectionarrow_forward
- Python Answer Required: A Rajesh teaches a cooking class. The course is attended by NN students, numbered 11 to NN. The cook must participate in the presence before each class, i.e. call out the names of the students one by one and indicate which students are present. Each student has a first and last name. To save time, Rajesh only wants to call up students' first names. However, if there are multiple students with the same first name, the Rajesh must call out the full names (first and last names) of all those students. For any student who does not share a first name with any other student, the cook can still only call that student's first name. Help the Rajesh decide for each student whether to call that student's full name or just their first name. Input 1 1 hasan jaddouh Output hasanarrow_forwardCSCI 2436:01L Data Structures Lab Lab 1 - Chapter 4 The Efficiency of Algorithms In this lab, you will practice how to measure the running time f a section of code in Java. One approach is to use System.nano Time() where the current time is stored as a long integer equals to the number of nanoseconds. By subtracting the starting time in nanoseconds from the ending time in nanoseconds, you get the run time-in nanoseconds of a section of code. public static void main(String[] args) { int n1 = 10, n2 = 100, n3 = 1000, n4 = 10000; long n1Time, n2Time, n3Time, n4Time; n1Time AlgorithmA (nl); For example, suppose that AlgorithmA is the name of a method you wish to time. The following statements will compute the number of nanoseconds that AlgorithmA requires to execute: } public static long AlgorithmA (int n) { long startTime, endTime, elapsedTime; startTime = System.nanoTime (); int sum = 0; for (int i = 1; i 0 1 2. By midnight, Tuesday, Jan 24th, submit your Java source file and a…arrow_forwardQ/ Write a program in C# that lets the user to define the number of rows and columns. Then, the program reads the matrix and finds the index of the even and odd numbers and display them with their corresponding indices. Use adequate messages during the program execution.arrow_forward
- Part III - Create Your Own Art Art.java In this part you will create a program Art.java that produces a recursive drawing of your own design. This part is meant to be fun, but here are some guidelines in case you're not so artistic. Requirements Art.java must take one (1) integer command-line argument n that controls the depth of recursion. Your drawing must stay within the drawing window when n is between 1 and 7. (The autograder will not test values of n outside of this range.) You may not change the size of the drawing window (but you may change the scale). Do not add sound. Your drawing can be a geometric pattern, a random construction, or anything else that takes advantage of recursive functions. Your program must be organized into at least three separate functions, including main(). All functions except main() must be private. For full credit, Art.java must not be something that could be easily rewritten to use loops in place of recursion, and some aspects of the recursive…arrow_forwardWrite VBA CODE FOR THE FOLLOWING PROBLEM Problem: The Worksheet named Grades contains a place for students to record the grades they have received in their classes. Students put the number of each letter grade received in the B column. (For example, the worksheet currently shows that the student has taken 9 classes and made five As, one B, one C, one D, and one F as grades. You need to write a program that reads the grades from the worksheet and uses a function to calculate the student’s GPA. For this problem you can assume that all classes are worth the same number of credit hours. The function should send back the GPA to the calling procedure. The procedure will then put up a message box that gives the student their GPA and a message about their GPA, all in one message box. The message should be “You qualify for an internship” if the student has a GPA of at least 3.0. It should be “You’re in the danger zone” if the GPA is between 2.0 and 3.0. And it should be “You are on…arrow_forward### Q5: Reduce No Change Python def reduce_no_change(fn, lst, base): """Same as Q4. However, preserve the lst in this problem. Object can be any python type which the input Not Allowed To Import Libraries Args: fn (function): Combination function which takes in two arguments and return an value with the same type as the second argument lst (List): A list of any type base (Object): A value of custom type which fn can handle. Returns: Object: A value after applying fn on lst. >>> reducer = lambda x, y: x + y >>> lst = [1, 2, 3] >>> a = reduce_lst(reducer, lst, 0) >>> a # a = reducer(reducer(reducer(base, lst[0]), lst[1]), lst[2]) 6 >>> lst >>> [1, 2, 3] # we preserve the list """ ### Modify your code here ### Modify your code herearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education