Python3 question.
Suppose I have a undirect and unweighted graph with vertex list type, here is the code of the graph.
graph = { "a" : ["c"],
"b" : ["c", "e"],
"c" : ["a", "b", "d", "e"],
"d" : ["c"],
"e" : ["c", "b"],
"f" : []
}
I want to use this to create a BFS method. How can I use queue only to finish the work?
In: Computer Science
I am building a tik tac toe board using python and the function I am using is not working to check to see if the board is full. I'll include the code for the board and the function to check if it is full. X's and O's are being inserted and the function is suppose to stop running when is_full(board) returns True. ch is either x or o
board = []
for i in range(3):
board.append([])
for j in range(3):
board[i].append(' ')
return board
def is_full(board):
""" Checking for board full """
for lst in board:
for ch in lst:
if ch == ' ':
return False
In: Computer Science
Please use python3
Create the function team_average which has the following header
def team_average(filename):
This function will return the average number of games won by the Red Sox from a text file with entries like this
2011-07-02 Red Sox @ Astros Win 7-5 2011-07-03 Red Sox @ Astros Win 2-1 2011-07-04 Red Sox vs Blue Jays Loss 7-9
This function should create a file object for the file whose
name is given by the parameter filename.
If the file cannot be opened, use a try/except statement to print
an error message and don't do any further work on the file.
The function will count the number of lines and the number of games
the Red Sox won and use these values to compute the average games
won by the team.
This average should be expressed as an integer.
Test Code
Your hw2.py file must contain the following test code at the bottom of the file
team_average('xxxxxxx')
print(team_average('red_sox.txt'))
For this test code to work, you must copy into your hw2
directory the file red_sox.txt from
/home/ghoffman/course_files/it117_files.
To do this go to your hw2 directory and run cp
/home/ghoffman/course_files/it117_files/red_sox.txt .
Suggestions
Write this program in a step-by-step fashion using the technique
of incremental development.
In other words, write a bit of code, test it, make whatever changes
you need to get it working, and go on to the next step.
Cannot open xxxxxxx None
Output
When you run the completed script, you should see
Error: Unable to open xxxxxxx 76
In: Computer Science
What are the security design principles? Explain each with an appropriate example.
In: Computer Science
for C program 10 by 10 char array. char 0-9 as rows and char a-j as collumns.
In: Computer Science
Write a java method that creates a two dimensional char array after asking the user to input a String text and String key consisting of integers only, such that
int rows=(int)Math.ceil(text.length()/key.length()); // or int rows=(int)Math.ceil(text.length()/key.length()); ?
int columns= key.length();
int remainder= text.length() % key.length(); // such that the last row avoids taking an index beyond the string text by making columns - remainder
The method fills the 2d array with letters a String entered by the use (row by row). The method then shifts the columns of the array based on key.
After changing the columns, the method returns a String of all the characters in the 2d array but written column by column.
text = Sara;
key= 312
For example, the initial 2d array is
| S | A | R |
| A |
transformed into
| R | S | A |
| A |
The final retuned string is RSAA
In: Computer Science
Using what you know about how to take inputs and make outputs to the console, create a check printing application. Your application will read in from the user an employee's name and salary, and print out a Console Check similar to the following. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > | $1,000,000 | > > > > ___Pay to the Order of___ Johnny PayCheck > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Please only use technique from chapter 1 through 3 in C++ from control structure through object 9th edition
In: Computer Science
Library Management System allows the user to borrow and return the books. The book is identified by book name, accession number, item category, due date, due time, and status. Before the user proceeds to borrow or return the books, they need to register for an account. Each user can have only one account. The user can be a staff or student. Each user is identified by ID number, name, school/department name, address. The books are arranged on a shelf. The shelf can be of two categories: open shelf or red spot. The user is allowed to reserve the book, in case, if the book is already borrowed by someone. While reserving a book, the user needs to specify the user name, ID number, book name, and accession number.
##Based on the above scenario, draw a Class Diagram. Your diagram should include attributes, methods and multiplicity.
In: Computer Science
File Compression - Student should submit a one-page paper summarizing the student’s research into compression programs associated with the filename extensions .zip, .sit, .sitx, and .exe, as well as whether those files would be self-extracting and which formats are associated with Windows and which with OS X. Also included should be a summary of at least two compression programs compatible with the computer the student uses most often, including their costs and capabilities
In: Computer Science
Write a multithreaded program that tests your solution to HW#1. You will create several threads – for example, 100 – and each thread will request a pid, sleep for a random period of time, and then release the pid. (Sleeping for a random period approximates the typical pid usage in which a pid is assigned to a new process, the process executes and terminates, and the pid is released on the process’ termination). On UNIX and Linux systems, sleeping is accomplished through the sleep() function, which is passed an integer value representing the number of seconds to sleep.
This is my HW#1 solution: public class PidManager{ private static final int MIN_PID = 300; private static final int MAX_PID = 5000; private static int[] pidArr; /* *This method is to allocate the *the array to store the pids. *@param none *@return int */ public static int allocate_map(){ pidArr = new int[MAX_PID - MIN_PID]; if (pidArr == null){ System.out.println("Not allocated."); return -1; } for (int i = 0; i < pidArr.length; i++) { pidArr[i] = 0; } System.out.println("Allocated."); return 1; } /* *This method is used to allocates and returns a pid. *@param none *@return int pidNum */ public static int allocate_pid(){ if (pidArr == null){ System.out.println("Pid manager is null "); return -1; } int pidNum = -1; for (int i = 0; i < pidArr.length; i++){ if (pidArr[i] == 0){ pidArr[i] = 1; pidNum = i + MIN_PID; break; } } if (pidNum == -1){ System.out.println("Cannot allocate Pid"); return -1; } System.out.println("Allocated Pid :" + pidNum); return pidNum; } /* *This method is used to release a pid. *@param int num *@return void */ public static void release_pid(int pidNum){ if (pidArr == null){ System.out.println("Pid manager is null. "); return; } if (pidNum < MIN_PID || pidNum > MAX_PID){ System.out.println("Pid is out of range, has to be in range from 300 to 5000"); } int newPid = pidNum - MIN_PID; if (pidArr[newPid] == 0){ System.out.println(pidNum + " is released."); return; } System.out.println("Releasing PID :" + pidNum); pidArr[newPid] = 0; } }
Thank you in advance.
In: Computer Science
Using Android Studio, create a one java android app that has 4 buttons:-
Change Color Button - When the Change Color button is clicked, it changes the current activity background to a randomly selected color
Speak Button - When the Speak button is clicked, it opens a new activity named SpeakActivity. On the SpeakActivity there are three controls: EditText, Button (Speak) and Button (Back). The Speak button uses the Text to Speech service to say the text entered in EditText. The Back button returns the user to the main/parent activity.
API Version Button - When the API Version button is clicked, display the Android API Version of the phone on a Toast in the current activity.
Serial Number Button - When the Serial Number button is clicked, send the serial number of your device to an email app as an implicit intent.
| Layout | Best practices & layout
|
Please show screenshots of your .xml and .java and the validated program.
In: Computer Science
With example, explain the different types of attack surface?
In: Computer Science
Hi I am quite confused with how to use scanner for my java project? Can someone help me with this? Thanks
In: Computer Science
Consider the various categories of ethics from the module content; Internet Ethics, Cyber Ethics, E-Commerce Ethics, Web Ethics, Business Computer Ethics, and Consumer Computer Ethics.
For this assignment, you will submit your best two scenarios from two separate categories that you devised. Be sure to reference ethical guidelines you learned from the module content and clearly identify the ethical dilemma(s) and/or violation(s).
Minimum requirements:
In: Computer Science
c++ program
Define the following classes to manage the booking of patients in a medical clinic.
a) Define a class Date that has the following integer data members: month, day and year.
b) Define a class AppointmentTime that has the following data members: day (string), hour (int) and minute (int).
c) Define a class Patient with the following data members:
• The name of the patient as a standard library string.
• The date of birth of the patient (from part a).
• Medical insurance number of the patient as a standard library string.
• Name of the doctor for the appointment.
• Day and time of the appointment (from part b). A patient may have a single doctor’s appointment each week.
c) Define a class Doctor with the following data members,
• The name of the doctor as a standard library string.
• The date of birth of the doctor (from part a).
• A two-dimensional string pointer array of 12-by-5 that shows the appointments of that doctor. The appointment durations are 30 mins and they always begin on the hour or half hour. Doctors see patients Monday to Friday during 9.00-12.00 and 14.00-17.00. This array is initialized to empty strings to indicate that at the beginning all the appointments are available. When an appointment is given a pointer to the medical insurance of the patient is stored at that location.
d) Define an AppointmentRequest class with the following data members,
• A Patient object from part (b).
• Doctor’s name.
• The day that appointment is requested as a standard library string (Monday to Friday).
e) Define a class ClinicManager with the following data members,
• An array of pointers to the Patient objects of size 200.
• An array of pointers to the Doctor objects of size 20.
• An integer variable that counts total number of patient appointments given by the clinic in a week. At least the following member functions should be provided,
- A member function that receives a patient object and inserts it to the Patient pointer array. It will check if the patient is already in the array to prevent multiple copies of the patient object in the array.
- A member function that receives a doctor object and inserts to the Doctor pointer array.
- A member function that processes appointment requests. The function will receive an AppointmentRequest object, then will check the requested doctor’s schedule to determine if the appointment can be made. If the appointment can be scheduled it will store the medical insurance of the patient in the appointment array of that doctor. It will create an AppointmentTime object from part b). Then, it will find the patient in the Patient pointer array and store the doctor’s name and AppointmentTime object in the patient object in the Patient pointer array. Finally, the member function will return the AppointmentTime object. If the doctor is already fully booked on that day this object should should return zeros for the appointment time.
- A member function that cancels an appointment, receives doctor’s name and medical insurance of the patient. Then it removes the appointment both from the doctor’s schedule and from the patient.
- A member function that receives a doctor’s name as a parameter and prints name and medical insurance number of all the patients that have booked an appointment with that doctor.
f) Write a driver program that demonstrate the functionality of your program including,
- Creates a ClinicManager object
- Creates doctor objects and calls to the doctor insert member function.
- Creates Patient and AppointmentRequest objects and calls to the member functions that processes the appointments, then outputs the time of the appointment.
Key Considerations for the assignment:
§ You must enforce encapsulation by keeping all data members private.
§ You need to make sure that your classes are well defined using the various concepts seen in the class.
§ Provide needed set/get functions for the data members.
§ Objects should be created dynamically and must be deleted when no longer needed. There should be an output statement confirming the deletion of an object from the destructor function
In: Computer Science