Write a statement that opens the file 'final.txt' in append mode and assigns it to my_file. PYTHON
In: Computer Science
In Python 3. Design, implement, and test a network application that maintains an online phonebook. The data model for the phonebook is saved in a file on the server’s computer. Clients should be able to look up a person’s phone number or add a name and number to the phonebook. The server should handle multiple clients without delays.
In: Computer Science
python
College is an investment. Tuition can range from $3,000 to $20,000 for a full-time student per semester. It seems like every year the cost continues to increase. It has been announced that the average tuition will increase by 5 percent each year for the next 4 years. To help students manage the cost of college, write a program that allows the students to input their full-time tuition cost per semester and then using a loop displays the projected semester tuition amount for the next 4 years.
Ex.
Enter the full-time student tuition per semester:
5000
when 10000
Enter the full-time student tuition per semester: - In 1 year, the tuition will be $10500.00.
-In 2 years, the tuition will be $11025.00.
In 3 years, the tuition will be $11576.25.
here is what i got
def main():
amount=5000.0
print('Enter the full-time student tuition per semester:')
for i in range(1,5):
amount=amount+(amount*0.05)
if i is 0:
print('- In '+str(i)+' year, the tuition will be $'+str((amount))+'.')
elif i is 5:
print('- In '+str(i)+' years, the tuition will be $'+str(round(amount, 2))+'2.')
else:
print('- In '+str(i)+' years, the tuition will be $'+str(round(amount,2))+'.')
if __name__=="__main__":
main()
In: Computer Science
Java.
Write 3 methods named addArrays, subArrays, and mulArrays each.
addArrays gets two matrices(int [][] array1, int [][] array2) as parameters and add them and returns the result (matrix).
subArrays gets two matrices(int [][] array1, int [][] array2) as parameters and subtract array2 from array1 and returns the result (matrix).
mulArrays gets two matrices(int [][] array3, int [][] array4) as parameters, multiplying them and returning the result(matrix).
In: Computer Science
Define the following term:
1. Bootstrap Protocol (BOOTP)
2. Simple Mail Transfer Protocol (SMTP)
3. Post Office Protocol (POP)
4. Internet Message Access Protocol (IMAP)
5. File Transfer Protocol (FTP)
In: Computer Science
At execution time, calls to methods are resolved based on the type of the object to which the reference refers to using a process called
|
dynamic binding. |
|
|
static binding. |
|
|
symmetric binding. |
|
|
none of the above |
Classes that can be used to instantiate objects are called
|
abstract classes. |
|
|
concrete classes. |
|
|
solid classes. |
|
|
none of the above |
The keyword to use in the class declaration to indicate that it uses an interface is
|
inherits. |
|
|
implements. |
|
|
extends. |
|
|
none of the above |
The UML expresses the relationship between a class and an interface through a
|
realization relationship. |
|
|
is-a relationship. |
|
|
has-a relationship. |
|
|
none of the above |
By default, interface methods are considered
|
private and abstract. |
|
|
public and abstract. |
|
|
abstract only. |
|
|
none of the above |
In: Computer Science
7. You have a hash function that takes the binary bits of a number, divides it up into blocks of 4 bits and then XORs the blocks together. So for example, if we have 4 blocks, block X0, X1, X2 and X3, the result of the 4-bit block hash would be X0 XOR X1 XOR X2 XOR X3. For example, the hash of "011011001010" would be "0110" XOR "1100" XOR "1010". Demonstrate that this is a poor hash function by showing me a hash collision using this function and two different input strings of at least 8 bits.
In: Computer Science
In: Computer Science
What does this program output
(make sure you can explain why the output is what it
is)
#include <iostream>
using namespace std;
class A {
int i;
public:
A() {cout << "A()\n" ;}
A(int x) :i(x) {cout << "A(int)\n" ;}
A(const A& a) : i(a.i) {cout << "A(const
A&)\n" ;}
~A() {cout << "A()\n" ;}
};
class B {
A a;
public:
B() {cout << "B()\n" ;}
B(int x) :a(x) {cout << "B(int)\n" ;}
B(const B& b) : a(b.a) {cout << "B(const
B&)\n" ;}
~B() {cout << "~B()\n" ;}
};
B func(B k) {return k;}
int main() {
B b1(2), b2;
b2=func(b1);
return 0;
}
In: Computer Science
I have everything written out but it won't compile, any help?
public class Course
{
private int course id;
private int instructor id;
private int room id;
Course()
{
setCourseID (13233);
setInsID (001);
setRoomID (101);
}
Course(int courseID, int instructorID, int
roomID)
{
setCourseID
(courseID);
setInsID
(instructorID);
setRoomID
(roomID);
}
public int getCourseID()
{
return courseID;
}
public int getInsID()
{
return instructorID;
}
public int getRoomID()
{
return roomID;
}
{
System.out.println("Course ID : " +
getCourseID());
System.out.println("Instructor ID :
" + getInsID());
System.out.println("Room ID : " +
getRoomID());
}
}
In: Computer Science
Write a C++ program to perform various calculations related to the fuel economy of a vehicle where the fuel economy is modeling using a polynomial of the form y = Ax2 + Bx + C, where
y = fuel economy in miles per gallon (mpg)
x = speed in miles per hour (mph)
In particular:
Inputs: The user should be prompted to input the following information.
The values for coefficients A, B, and C used to model the fuel efficiency
The capacity of the fuel tank (in gallons).
The current amount of fuel in the tank (in gallons).
The current speed of the vehicle (in mpg)
The distance to be travelled on the current trip (in miles)
The cost per gallon for gasoline
The minimum speed, Smin, to be used in the table of Fuel Economy vs Speed
The maximum speed, Smax, to be used in the table of Fuel Economy vs Speed
The speed increment, Sinc, to be used in the table of Fuel Economy vs Speed
Functions: The program should use at least 4 user-defined functions (in addition to main) as described below.
MPG(A, B, C, Speed) – This function returns the fuel economy in mpg for a given speed in mph.
PrintTable(Smin, Smax, Sinc A, B, C) – This function will print a table of Speed (in mpg) and Fuel Economy (in mpg).
Use the range of speeds indicated with the speed increment indicated.
This function should call the function MPG above.
Fuel economy should be calculated using the coefficients A, B, and C provided.
Include a table heading with units.
Display speeds as integers and fuel economy with 2 digits after the decimal point (include trailing zeros).
MaxEconomy(Smin, Smax, Sinc A, B, C, MaxMPG, MaxMPH) – This function will return the maximum mpg and the corresponding speed value using the speed range and increment specified. This function should call the function MPG above.
Use at least one more useful (user-defined) function to calculate one or more of the program outputs.
Outputs: The program output should include the following:
Neatly summarize the input values
A table of Speed and Fuel Economy values (created by the PrintTable function above).
The maximum fuel economy (in mpg) and the corresponding speed (determined by the MaxEconomy function above).
The fuel economy (in mpg) at the current speed
The minimum fuel economy (in mph) and the corresponding speed. Note: This does not always occur at the minimum speed.
For the current speed, trip distance, number of gallons currently in the tank, and cost per gallon for fuel (show the value of each), display the following:
The fuel economy (in mpg)
Speed for the trip (in mph)
The fuel cost for the trip.
The number of gallons that will be used for the trip.
The time to reach the destination.
State how many times you will need to stop for gas. Assume that the tank must be filled when it is 10% full.
State the number of gallons of gas will be left in the tank at the end of the trip.
State the number of miles until the next time the tank must be filled (after the trip).
Repeat the above if you drive at the speed for maximum fuel economy. Also state how many gallons of gas were saved and how much money was saved by driving at the speed for maximum fuel efficiency.
Use a suitable number of digits for all numeric outputs and include units when appropriate.
Error Checks: The program should check for appropriate ranges for inputs and allow the user to re-enter any incorrect inputs, including:
Fuel tank capacity: 0 to 20 gallons
Current amount of fuel in tank: 20% - 100% of fuel tank capacity
Current speed of vehicle: 20 to 80 mph
Distance to be travelled: Must be > 0
Cost per gasoline: Must be > 0
Minimum speed for table (Smin): Integer value where 20 < Smin < 50
Maximum speed for table (Smax): Integer value where (Smin + 10) < Smax < 80
Speed increment for table (Sinc): Integer value where 0 < Sinc < (Smax – Smin)/5
Re-running the Program: Include a loop that will give the user the option of re-running the program.
In: Computer Science
Question 1
The GCD is the greatest common denominator. Euclid found that if A=Bx +R then GCD(A,B)=GCD(A,R). Prove this is true. Show working
Question 2
The approach Euclid in calculating the GCD used was novel as it was an ________process to solve a complex problem, hence formed the first _______.
Question 3
The difference between a breadth first search (BFS) and a depth first search (DFS) is that in the DFS you traverse all the first branch before proceeding to the next branch.
a) True
b) False
The first definition as graphs need axes
The second definition as more general so covers all graphs
Neither as they are too vague
Question 5
Find a c such that f(n) is O(n2) when f(n) = 1/4 n2 + 15 n + 115. Justify this answer.
Question 6
If f(n)= 10* log n then Big-O of f(n) is O(n)
a) True
b) False
In: Computer Science
Suppose we are given an arbitrary digraph G = (V, E) that may or may not be a DAG. Modify the topological ordering algorithm so that given an input G, it outputs one of the two things:
a. A topological ordering thus establishing that G is a DAG.
b. A cycle in G thus establishing that it is not a DAG.
The runtime of your algorithm should be O(m+n) where m = |E| and n = |V|
In: Computer Science
R PROGRAMMING QUESTION
- Below I have code. For each double hashtag (##) can you comment on the code below it (Describe what is happening in the code below it next to each ##)
- Run the code and compare the confidence intervals
- I have to submit the confidence intervals, comments, and the code with the ## filled out
Leaps.then.press.plot.2<-function(xmat0,yvec,xpred,ncheck=20)
{
#
#input quadratic matrix with less than 30 columns eg. the result of x.auto2a<-matrix.2ndorder.make(xmat[,-7],F)
#also, no need for plotting, just pull out best, xpred is one of the row vectors from x.auto2a, but all terms with weight are divided by 2
#
##
leaps.str<-leaps(xmat,yvec)
##
z1<-leaps.str$Cp-leaps.str$size
##
o1<-order(z1)
matwhich<-(leaps.str$which[o1,])[1:ncheck,]
MPSEvec<-NULL
##
for(i in 1:ncheck){
ls.str0<-regpluspress(xmat[,matwhich[i,]],yvec)
##
parvec<-matwhich[i,]
npar<-sum(parvec)
## (WHY npar+1)
MPSE<-ls.str0$press/(length(yvec)-(npar+1))
MPSEvec<-c(MPSEvec,MPSE)
}
##
I1<-(MPSEvec==min(MPSEvec))
##
i<-c(1:ncheck)[I1]
##
xmat.out<-xmat[,matwhich[i,]]
##
xpred.out<-xpred[matwhich[i,]]
##
list(xmatout=xmat.out,yvec=yvec,xpredout=xpred.out)
}
Bootreg<-function(xmat,yvec,xpred,nboot=10000,alpha=0.05)
{
##
lstr0<-leaps.then.press.plot2(xmat,yvec,xpred)
xmat0<-lstr0$xmat.out
yvec0<-lstr0$yvec
xpred0<-lsstr0$xpredout
##
rprd.list<-regpred(xpred0,xmat0,yvec0)
ypred0<-rprd.list$pred
sdpred0<-rprd.list$sd
df<-rprd.list$df
##
bootvec<-NULL
nobs<-length(yvec0)
for(i in 1:nboot){
##
vboot<-sample(c(1:nobs),replace=T)
xmatb<-xmat0[vboot,]
yvecb<-yvec0[vboot]
##
lstrb<-leaps.then.press.plot2(xmatb,yvecb,xpred)
##
xmatb0<-lstrb$xmat.out
yvecb0<-lstrb$yvec
xpredb0<-lsstrb$xpredout
##
rprd.list<-regpred(xpred0,xmat0,yvec0)
ypredb<-rprd.list$pred
sdpredb<-rprd.list$sd
dfb<-rprd.list$df
##
bootvec<-c(bootvec,(ypredb-ypred0)/sdpredb)
}
##
lq<-quantile(bootvec,alpha/2)
uq<-quantile(bootvec,1-alpha/2)
##
LB<-ypred0-(sdpred0)*uq
UB<-ypred0-(sdpred0)*lq
##
NLB<-ypred0-(sdpred0)*qt(1-alpha/2,df0)
NUB<-ypred0+(sdpred0)*qt(1-alpha/2,df0)
list(bootstrap.confidence.interval=c(LB,UB),normal.confidence.interval=c(NLB,NUB))
}
> regpred<-
function(xpred,xmat,y){
##
ls.str<-lsfit(xmat,y)
#calculate prediction
ypred<-ls.str$coef%*%c(1,xpred)
#use ls.diag to extract covariance matrix
ycov<-ls.diag(ls.str)$cov.unscaled
#use ls.diag to extract std deviation
std.dev<-ls.diag(ls.str)$std.dev
#variance of data around line
v1<-std.dev^2
#variance of prediction
vpred<-v1*c(1,xpred)%*%ycov%*%c(1,xpred)
df=length(y)-length(diag(ycov))
list(pred=ypred,sd=sqrt(vpred),df=df)
}
In: Computer Science