Python : Write the function inAWhile that takes two integers t and d, where t is the present time on a 12-hour clock, rounded to an integer (so t is an integer in the interval [1,12]) and d is an integer increment in hours, and returns the time on a 12-hour clock in d hours. For example, in 2 hours from 3 o’clock, it will be 5 o’clock, so inAWhile (3, 2) = 5. Notice that 12 is followed by 1 on a 12-hour clock, since only computer scientists start counting at 0. The test data will clarify. Additionally, you should guarantee that the type of the parameters is int, using an assertion. For example, inAWhile (‘Hi’, ‘there’) should fail the assertion, and inAWhile (5, ‘there’) should also fail the assertion.
In: Computer Science
Write a grading program for a class with the following grading policies:
There are three quizzes, each graded on the basis of 10 points.
There is one miterm exm, graded on the basis of 100 points.
There is one finl exm, graded on the basis of 100 points.
The fnal exm counts for 40% of the grade. The miterm counts for 35% of the grade. The three quizzes together count for a total of 25% of the grade. (Do not forget to convert the quiz scores to percentages before they are averaged in.)
Any grade of 90 or more is an A, any grade of 80 or more (but less than 90) is a B, any grade of 70 or more (but less than 80) is a C, any grade of 60 or more (but less than 70) is a D, and any grade below 60 is an F. The program should read in the student’s scores and output the student’s record, which consists of three quiz scores and two exm scores, as well as the student’s overall numeric score for the entire course and final letter grade.
Define and use a class for the student record. The class should have instance variables for the quizzes, midterm, final, overall numeric score for the course, and final letter grade. The overall numeric score is a number in the range 0 to 100, which represents the weighted average of the student’s work. The class should have methods to compute the overall numeric grade and the final letter grade. These last methods should be void methods that set the appropriate instance variables. Your class should have a reasonable set of accessor and mutator methods, an equals method, and a toString method, whether or not your program uses them. You may add other methods if you wish.
JAVA!
In: Computer Science
Minimum value and its position
Create a program that:
Run the program 5 times with representative sizes
In: Computer Science
We will make some changes to our first program. If you recall we began with, A car's gas mileage or miles-per-gallon (MPG) can be calculated with the following Formula: MPG = Miles Driven / Gallons of gas used. Write a class called Mileage. The Mileage class should have two private member variables called miles and gallons of type double. The class should have four public methods: setMiles and setGallons should use void return types; getMiles and getGallons should use double return types. It should have one more method called getMPG that performs the math calculation and returns the double MPG Write a program called MPGMain that asks the user for the number of miles driven and the gallons of gas used. It should call the Mileage class to calculate the car's MPG. The class should return the MPG to the MPGMain where it was called and display the value on the screen. (Format the display and limit the miles-per-gallon to 2 decimal places) in JAVA programming language
In: Computer Science
One of the very practical uses of assembly language programming is its ability to optimize the speed and size of computer programs. While programmers do not typically write large-scale applications in assembly language, it is not uncommon to solve a performance bottle neck by replacing code written in a high level language with an assembly language procedure.
In this programming project you will be given a C++ program that generates an array of pseudorandom integers and sorts the array using the selection sort algorithm.
Your job is to write an assembly language procedure that also sorts the array of pseudorandom integers using the selection sort algorithm. The C++ program will time multiple repetitions of the sort performed by both the C++ code and your assembly language procedure. The C++ program will compare the result. If all goes as expected, your assembly language procedure should be faster than the C++ code.
Chapter 13 of your textbook contains a discussion of how to interface an assembly language procedure with a high-level programming language like C++.
The Visual Studio solution for the C++ program that you are given has been packaged and compressed into a file called “ProjectFour.zip”. Create a location on your computer for this project. Download the compressed file, “ProjectFour.zip”, and unpack it into that location in your computer.
Look in the unpacked folder for a file named “ProjectFour.sln”. The “.sln” file extension stands for solution. Double clicking on this file will start up the Visual Studio solution for ProjectFour and allow you to execute the C++ program.
Modify ProjectFour by following these steps:
Use Ctrl+F5 or click on “Debug” in the Menu Bar followed by “Start Without Debugging” to execute the program. The MASM assembler will assemble AsmSelectionSort.asm into an object file that is then linked into your project.
A “stub” assembly language procedure has been provided so that you can execute the C++ program to get a feel for how it works. Your job is to improve on the efficiency of the C++ compiled code by writing an assembly language procedure that is faster. Click on the file named “AsmSelectionSort.asm” in the Solution Explorer pane. This file is your starting point for creating an assembly language version of the selection sort routine.
As always, start small. DO NOT be the Cookie Monster and gobble up the whole project at once. Steps you might consider, but are not limited to are:
This project will provide you with the opportunity to:
In: Computer Science
Q4: Suppose you want to send a 5000 character message, using 7-bit ASCII encoding. How many TOTAL bits would need to be transmitted using an asynchronous connection? How many of those bits are overhead? How many TOTAL bits would need to be transmitted using a synchronous connection? How many of those bits are overhead? For the synchronous connection, each frame can hold 1000 characters, and has a start byte flag, a stop byte flag, a control byte, a 2 byte address field, and a 2 byte checksum. You may show your work for partial credit
In: Computer Science
Twin elements
Create a program that:
Run the program 5 times with representative sizes
In: Computer Science
Write a MIPS Assembly program that computes the sum of all the odd numbers from 1 ..99 and print out the answer.
In: Computer Science
IN JAVA LANGUAGE!!!
These questions involve choosing the right abstraction (Collection, Set, List, Queue, Deque, SortedSet, Map, or SortedMap) to efficiently accomplish the task at hand. The best way to do these is to read the question and then think about what type of Collection is best to use to solve it. There are only a few lines of code you need to write to solve each of them. Unless specified otherwise, sorted order refers to the natural sorted order on Strings, as defined by String.compareTo(s). Part 0 in the assignment is an example specification and solution.
Q1) Read the input one line at a time and output only the last 9999 lines in the order they appear. If there are fewer than 9999 lines, output them all. For full marks, your code should be fast and should never store more than 9999 lines.
Q2) ] Read the input one line at a time and output the current line if and only if you have already read at least 1000 lines greater than the current line and at least 1000 lines less than the current line. (Again, greater than and less than are with respect to the ordering defined by String.compareTo().)
CODE FORMAT:
package comp2402a1;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Part3 {
/**
* @param r the reader to read from
* @param w the writer to write to
* @throws IOException
*/
public static void doIt(BufferedReader r, PrintWriter
w) throws IOException {
// Your code goes
here
}
/**
* The driver. Open a BufferedReader and a PrintWriter,
either from System.in
* and System.out or from filenames specified on the
command line, then call doIt.
* @param args
*/
public static void main(String[] args) {
try {
BufferedReader
r;
PrintWriter
w;
if (args.length
== 0) {
r = new BufferedReader(new
InputStreamReader(System.in));
w = new PrintWriter(System.out);
} else if
(args.length == 1) {
r = new BufferedReader(new
FileReader(args[0]));
w = new PrintWriter(System.out);
} else {
r = new BufferedReader(new
FileReader(args[0]));
w = new PrintWriter(new
FileWriter(args[1]));
}
long start =
System.nanoTime();
doIt(r,
w);
w.flush();
long stop =
System.nanoTime();
System.out.println("Execution time: " + 10e-9 *
(stop-start));
} catch (IOException e) {
System.err.println(e);
System.exit(-1);
}
}
}
In: Computer Science
Write a program in C++ called RollDice.cpp that simulates rolling a pair of dice until the total on the dice comes up to be a given number. Ask the user for the number that you are rolling for.
To have your program roll two dice, use the rand() function this way:
die1 = rand() % 6 + 1; die2 = rand() % 6 + 1;
Your program then computes and prints the number of rolls it takes to get the given number. Valid numbers are 2 through 12.
If the user asked for a 2 your program should output:
It took 20 rolls to get a 2.
(your number of rolls will be different of course)
In: Computer Science
How can I use Python without Pandas to create a new.csv file with the headers "c1, c2, c3, c4, c5, c6" and the first line of data "8, 5, -9, 7, 2.1, 1.7" from the original.csv file?
In: Computer Science
Write in C programming using if and else statements only please!!!
Write a program that plays the following card game: The user starts out with a pot of $100. At each hand of the game, the dealer and the player are dealt a random number between 1 and 52. The player wins $20 if his/her number is greater than the dealer's number; otherwise they lose $20.
In: Computer Science
Reflect on your own professional interests – can you imagine yourself in the role of a Business Analyst? What aspects would you enjoy? What aspects would require some effort?
In: Computer Science
Shrink-wrap, box-top, and click-wrap agreements are inherent to e-commerce. How you feel about them often depends on whether you are the vendor or purchaser. What are the best practices to assure shrink-wrap, box-top, and click-wrap agreements are legal? What are the best ethical practices that the e-commerce industry should adopt?
In: Computer Science
use python
Although clumsy, the if statements and if-else statements can be used to achieve the same effects as if-elif-else statements. Rewrite the speed3 function:
def speed3():
kph=float(input('What is the speed in kph?'))
mph=0.621371*kph
print('The speed is',mph,'mph.')
if mph>80:
print('You are WAY over the speed limit. Your fine is $200!')
elif 65<mph<=80:
print('You are over the speed limit (65mph) . Slow down1').
elif 30<=mph<=65:
print('You are within the speed limit. Good job!')
else:
print('You are too slow. Exit highway and use local roads!')
(a) use only if statement
(b) use only if-else statement
In: Computer Science