Java
Write a program that declares a constant named QUARTS_IN_GALLON which holds the number of quarts in a gallon (4). Also declare a variable named quartsNeeded to represent the number of quarts needed for a painting job, and assign an appropriate value. Compute and display the number of gallons and quarts needed for the job. Display explanatory text with the values—for example, A job that needs 18 quarts requires 4 gallons plus 2 quarts. When submitting the program for testing/grading, assign the value 18 to quartsNeeded.
In: Computer Science
Sorting Benchmarks
Write a program that generates and sorts an array of a
user-specified number (arraySize) of randomly generated numbers. To
keep the values to a reasonable range by using the array size as
the upper bound for the random numbers (between 1 and arraySize).
Your program should call the individual functions that implement
the five sorting algorithms discussed in class (see the lecture
slides). Each function should keep a count of the number of
comparisons/exchanges it makes. Display the pre-sorted array, the
sorted array, and the number of comparisons for each algorithm.
Note: In this assignment, you will compare all the five sorting algorithms from the lecture notes (brute force sort, bubble sort, bubble sort++, selection sort, and insertion sort) with each other using the same data for each. Start with getting one to work first. The idea is that once you have one, adding in the other algorithms is relatively simple. Hint: use the algorithms from the slides! Your program MUST include a function for each algorithm and use them appropriately. The main procedural code must first prompt the user for the arraySize = number of elements to store in the array ("How many elements in the array?"). Then, it will generate arraySize random integers between 1 and arraySize (the number they entered--yes, you will use it twice!). Since each function will sort the array, changing the values, you will need to make multiple copies of the generated array to test the same numbers against each algorithm. Each algorithm will return the number of comparisons made. This is when one element is compared to another, regardless of whether or not they get swapped. NO GLOBAL VARIABLES!
You will need to include at least these functions: void displayArray(int values[], int size); int bruteForceSort(int values[], int size); int bubbleSort(int values[], int size); int bubblePPSort(int values[], int size); int selectionSort(int values[], int size); int insertionSort(int values[], int size); The output should look something like this -- user inputs are in bold blue type: How many elements in the array? 20 BRUTE FORCE SORT Before sorting: 10 14 6 7 12 18 9 13 4 17 19 2 17 2 4 10 20 3 9 14 After sorting: 2 2 3 4 4 6 7 9 9 10 10 12 13 14 14 17 17 18 19 20 Number of comparisons: 400 BUBBLE SORT Before sorting: 10 14 6 7 12 18 9 13 4 17 19 2 17 2 4 10 20 3 9 14 After sorting: 2 2 3 4 4 6 7 9 9 10 10 12 13 14 14 17 17 18 19 20 Number of comparisons: 190 BUBBLE SORT PLUS PLUS Before sorting: 10 14 6 7 12 18 9 13 4 17 19 2 17 2 4 10 20 3 9 14 After sorting: 2 2 3 4 4 6 7 9 9 10 10 12 13 14 14 17 17 18 19 20 Number of comparisons: 184 SELECTION SORT Before sorting: 10 14 6 7 12 18 9 13 4 17 19 2 17 2 4 10 20 3 9 14 After sorting: 2 2 3 4 4 6 7 9 9 10 10 12 13 14 14 17 17 18 19 20 Number of comparisons: 206 INSERTION SORT Before sorting: 10 14 6 7 12 18 9 13 4 17 19 2 17 2 4 10 20 3 9 14 After sorting: 2 2 3 4 4 6 7 9 9 10 10 12 13 14 14 17 17 18 19 20 Number of comparisons: 186
In: Computer Science
Consider the pipelined reliable data transfer (rdt) protocols over the channel that can corrupt or lose packets.
(a) Why did we need to use sequence numbersfor these protocols?
(b) Why did we need to introduce timers in these protocols?
(c) Why did we need to introduce a sliding window in these protocols?
In: Computer Science
Assume a client uses TCP to send data to a server. The TCP header has 12 bytes of options and 99 bytes of data. [Please don't forget Ethernet Type/Len field is 2 bytes in size.]
1. Calculate the total number of bytes passed to the IP layer by the TCP layer.
2. Calculate the total number of bytes passed to the network layer by the IP layer, assuming the IP layer has no options.
3. Calculate the total number of bytes transmitted on the Ethernet cable (not including the preamble, the start frame delimiter, or the frame check sequence).
4. What is the percentage of overhead for the packet being transmitted on Ethernet (i.e. the ratio of non-user data to total protocol data)?
In: Computer Science
For C++
Write a program that opens a specified text file then displays a list of all the unique words found in the file. Hint: Store each word as an element of a set.
In: Computer Science
For each of the following problems provide: a. inputs b. outputs c. error conditions d. an algorithm using the pseudocode reference used in class e. a set of test cases. Be careful about corner cases f. the minimum number of operations executed in your algorithm g. the maximum number of operations executed in your algorithm
Q. Train Ticket for one person. Read a person’s age, then compute and display the price the person needs to pay for the train ride according to the following rules: Children younger than 7 years old ride for free. If the ticket is bought at the train station: A person over 65 years old pays $7.50. Everyone else pays $13.20. If ticket is bought inside the train, there is an extra charge of 20% compared to train station prices. Note that a persons’ age is within the range of 0 to 120 years. Other inputs are error conditions.
In: Computer Science
In each of the projects that follow, you should write a program that contains an introductory docstring. This documentation should describe what the program will do (analysis) and how it will do it (design the program in the form of a pseudocode algorithm). Include suitable prompts for all inputs, and label all outputs appropri- ately. After you have coded a program, be sure to test it with a reasonable set of legitimate inputs.
Q. Write a program that takes as input a number of kilometers and prints the corresponding number of nautical miles. Use the following approximations: - A kilometer represents 1/10,000 of the distance between the North Pole and the equator. - There are 90 degrees, containing 60 minutes of arc each, between the North Pole and the equator. - A nautical mile is 1 minute of an arc.
*please use IDLE( python 3.7)
In: Computer Science
In 6A, you created an object class encapsulating a Trivia Game which INHERITS from Game.
Now that you have successfully created Trivia objects, you will continue 6B by creating a linked list of trivia objects. Add the linked list code to the Trivia class.
Your linked list code should include the following: a TriviaNode class with the attributes:
1. trivia game - Trivia object
2. next- TriviaNode
3. write the constructor, accessor, mutator and toString methods.
A TriviaLinkedList Class which should include the following attributes:
1. head - TriviaNode
2. number of items – integer
3. write the code for the constructor, accessor and mutator, and toString methods.
4. methods to insert a triviaNode on the list - You may assume inserts always insert as the first node in the list.
5. write a method to delete a node by passing the node id of the game to delete. Take into consideration that the game may not exist in the list. Your method should let the user know that the node was successfully deleted or not.
Write a client to test all aspects - creating trivia objects, inserting the objects as nodes to the list, deleting a node by passing the id of the trivia game. Print out the list every time you make a change such as adding a node and deleting a node. You should create at least 5 objects to be inserted to your list, then delete at least 1. Also, test deleting an object that is not in the list.
6B. In this module, you will combine your knowledge of class objects, inheritance and linked lists. You will need to first create an object class encapsulating a Trivia Game which INHERITS from Game.
Game is the parent class with the following attributes:
Trivia is the subclass of Game with the additional attributes:
1. trivia game id - integer
2. ultimate prize money - double
3. number of questions that must be answered to win - integer.
4. write the accessor, mutator, constructor, and toString methods.
Write a client class to test creating 5 Trivia objects. Once you have successfully created Trivia objects, you will continue 6B by adding a linked list of trivia objects to the Trivia class.
In: Computer Science
In: Computer Science
Create a class named CollegeCourse that includes the following data fields:
All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display() method that displays the course data. For example, if dept is 'SE', id is 225, and credits is 3, the output from display() should be:
SE225 Non-lab course 3.0 credits Total fee is $360.0
Create a subclass named LabCourse that adds $50 to the course fee. Override the parent class display() method to indicate that the course is a lab course and to display all the data. For example, if dept is 'BIO', id is 201, and credits is 4, the output from display() should be:
BIO201 Lab course 4.0 credits Lab fee is $50 Total fee is $530.0
Write an application named UseCourse that prompts the user for course information. If the user enters a class in any of the following departments, create a LabCourse: BIO, CHM, CIS, or PHY. If the user enters any other department, create a CollegeCourse that does not include the lab fee. Then display the course data.
In: Computer Science
ANSWER IN JAVA
Write a simple polling program that allows users to rate five topics from 1 (least important) to 10 (most important). Pick five topics that are important to you (e.g., political issues, global environmental issues, food, video games). Use a one-dimensional array topics (of type String) to store the five issues. To summarize the survey responses, use a 5-row, 10-column two-dimensional array responses (of type int), each row corresponding to an element in the topics array. When the program runs, it should ask the user to rate each issue. Multiple people should be able to respond to the survey during a single run of the program. Once all responses have been logged, have the program display a summary of the results, including:
A tabular report with the five topics down the left side and the 10 ratings across the top, listing in each column the number of ratings received for each topic.
To the right of each row, show the average of the ratings for that issue.
Which issue received the highest point total? Display both the issue and the point total.
Which issue received the lowest point total? Display both the issue and the point to
I've gotten stuck and don't know how to progress forward. if someone could go into detail on how to finish it or make comments as you're editing that would be great. thanks
import java.util.Scanner;
public class Polling_2 {
public static void main(String[] args) {
// TODO Auto-generated method
stub
Scanner scnr = new
Scanner(System.in);
String[] topics = {"Cars",
"Politics", "Money", "Social", "Food"};
int [][] myArray = new int
[5][11];
int i;
int j;
int peoples;
int responses;
for (i = 0; i < myArray.length;
i++ ) {
for (j = 0; j
< myArray[i].length; j++) {
myArray[i][j] = scnr.nextInt();
}
}
System.out.print("Enter the amount
of people rating: ");
peoples =
scnr.nextInt();
while ( i <
peoples) {
for int j = 0; j < 5; j++ {
System.out.print(
myArray[i][j] + " " );
int x = scnr.nextInt();
int
responses[j][x] = int responses [j][x] + 1 ;
}
}
}
In: Computer Science
Python
I am creating a program that allows a user to extract data from a .csv file and print the statistics of a certain column in that file. The statistics include Count, Mean, Standard Deviation, Min, and Max. Here is the code I have so far:
import csv
import json
class POP:
""" Extract the data """
def __init__(self, line):
self.data = line
# get elements
self.id = self.data[0].strip()
self.geography = self.data[1].strip()
self.targetGeoId = self.data[2].strip()
self.targetGeoId2 = self.data[3].strip()
self.popApr1 = self.data[4].strip()
self.popJul1 = self.data[5].strip()
self.changePop = self.data[6].strip()
population = list()
with open('PopChange.csv', 'r') as p:
reader = csv.reader(p)
next(reader)
for line in reader:
population.append(POP(line))
population.append(POP(line))
obj = POP(line)
print(obj.popApr1)
As seen above, I am trying to print out the Count, Mean, Standard Deviation, Min, and Max of the column "popApr1", which is a column in the file. When I tried to print using print(obj.popApr1), it did not work. I believe that this action can be done using the .describe() method, but I am unsure of the syntax.
In: Computer Science
Write two versions of a program that reads from the user a
sequence of positive integers ending with -1, and another positive
integer num that the
user wishes to search for.
The program should then print all the line numbers in sequence
entered by the user, that
contain num, or a message saying that num does not show at all in
the sequence.
Your program should interact with the user exactly as it shows in
the following example:
Please enter a sequence of positive integers, each in a separate
line.
End you input by typing -1.
13
5
8
2
9
5
8
8
-1
Please enter a number you want to search.
5
5 shows in lines 2, 6.
a) The first version of the program, is not allowed to use the
vector data structure.
b) The second version of the program, should use the vector data
structure.
Implementation requirements (for both programs):
1. Think how to break down your implementation to functions.
2. Your programs should run in linear time. That is, if there are n
numbers in the input
sequence, your program should run in ?(?).
3. Write the two programs in two functions named main1() and
main2(). Also have
the main() test these two functions.
In: Computer Science
Introduction to Programming with C++ Third Edition. Y. Daniel Liang
Phone Key Pads:Write a program for Programming Exercise 4.15 on p.152 in the textbook.
Testing: Run the program for:
o The first three letters in your last name (all lowercase)
o The first three letters in your first name (all uppercase)
o Three invalid characters
use an old phone with 2 abc 3 def 4 ghi
In: Computer Science
1) The provided sched.cpp file is missing a few lines to read in some of the data. The comments in the code describe how there is yet another stream library that works like iostream and fstream, but for processing string’s. Fill in the necessary statements and uncomment the indicated cout statements to get the output below for the attached “sched.txt” file:
CS100
Section 1 has 17 open seats
It is held on MW from 8:00A to 9:15A in SC-S146
It is taught by C. Smith
Section 2 has 11 open seats
It is held on MW from 11:00A to 12:15P in VBT-0222
It is taught by I. Yellapragada
sched.cpp /* Lab 4 part 1. Files and stringstreams */ #include <iostream> #include <fstream> #include <sstream> // like fstream, but for string's #include <iomanip> #include <cstdlib> #include <string> using namespace std; int main() { string dept, crsInfo, secInfo, days, room, lname, finit; unsigned int crsNo, secNo, cap, avail, start_hr, start_min, end_hr, end_min; char skip, start_ampm, end_ampm; ifstream sched("sched.txt"); istringstream secStrm; // Read in Course department, number sched >> dept >> crsNo; // Note that >> does not store the space between // dept and crsNo cout << dept << crsNo << endl; getline(sched, crsInfo); sched.ignore(1); // Process each section while (sched >> secNo) { // Reads rest of line from file into string getline(sched, secInfo); // Set the stringstream to take its data // from this string secStrm.clear(); // first clear what's in the stream secStrm.str(secInfo); // now set the data to process // Now you can use the usual >> operator secStrm >> cap >> skip >> avail; // ADD CODE HERE // use the skip char variable to read in extra char's // or use ignore() cout << "Section " << secNo << " has " << avail << " open seats" << endl; // Uncomment the following to get the rest of the output // after you have extracted these values /* cout << "It is held on " << days << " from " << start_hr << ':' << setw(2) << setfill('0') << start_min << start_ampm << " to " << end_hr << ':' << setw(2) << setfill('0') << end_min << end_ampm << " in " << room << endl << "It is taught by " << finit << ' ' << lname << endl; */ // Get to start of next line in file sched.ignore(1); } sched.close(); // system("pause"); return 0; }
sched.txt
CS 100 - Programming for Everyone (3 Units) 01 45/17 MW SC-S146 08:00A-09:15A Smith C. 02 45/11 MW VBT-0222 11:00A-12:15P Yellapragada I.
In: Computer Science