Questions
PYTHON COADING In this homework, we are mostly going to work with and manipulate pre-written code....

PYTHON COADING In this homework, we are mostly going to work with and manipulate pre-written code. But first, let’s practice writing a few lines of code ourselves.

(a) Create a function that raises any number to the power of 3 and fully annotate in the code itself what each line is doing. Check that your function is operating correctly (this may seem trivial now, but is good practice going forward as your programs become more complicated).

(b) Create three objects, which represent one of each of the following: a list, an array, and a tuple, each with three items.

(c) Multiply each of these three objects by three. What are the results, and why?
(d) Replace the third item in the array with the number 23. Do the same for the tuple. Show what happens. Why do you get this result?

(e) Create a range from 0 to 42 that includes every third number.

(f) Create a table with three rows and three columns, containing any kind of data (made up or real) that you like using pandas and a dictionary. Show the table, and describe the contents of the rows and columns.

In: Computer Science

How many asterisks does the following code fragment print? a = 0 while a < 100:...

  1. How many asterisks does the following code fragment print?

a = 0

while a < 100:

b = 0

while b<55:

   print('*', end='')

   b += 1

  print()

a += 1

In: Computer Science

Main Program's grading: Student's main program will be used to generate output files. These output files...

Main Program's grading:

Student's main program will be used to generate output files. These output files will be compared to the solution output files and also to output files generated through instructor code, i.e., C++ code that will call the appropriate members of the Board class with the appropriate command line arguments. Students are free to impliment their main program however they like but the output must be correct (according to the solution) and must match the output using student's Board class. Pseudocode for generating the output files from the instructor's end is shown below

#include "Cell.hpp"
#include "Board.hpp"
#include "Gary.hpp"

int main(int argc, char** argv){
        unsigned int boardSize = (from command line arguments)
        unsigned int numberSteps = (from command line arguments)
        std::string outputFilename = (from optional command line argument)
        
        Board B(boardSize);
        if (an output filename is given){
                B.setOutputFilename(outputFilename);
        }
        
        B.move_gary(numberSteps);

        return 0;
}

and student code must be capable of generating the correct output in the correct location when calling these member functions of the Board class. Please note that the only "pseudo" above is the parsing of command line arguments and the if statement - the member functions and construction of variable B of type Board is valid C++ syntax that is used during testing.

Board Class:

Note that there are no structural requirements for the Board class beyond the member functions called via the above psuedo-main program. These include:

(1) The Board class shall be constructed given an unsigned integer parameter that defines the number of rows and columns, i.e., 'N' in the N by N board. Note that N must be odd. If N is given as even, students shall display a message stating "Board dimension must be an odd number!! Got {N} and adding 1 to equal {N+1}" (note that parameters within { } must be printed as their values) and shall add 1 to N to satisfy the requirement that N must be odd. Note that this message must be printed only to the console, i.e., should not be printed to the output file. (2) Gary shall move around the board when the move_gary(steps) function is called. Each step shall be one step of Langton's ant as defined above, i.e., change Gary's orientation based on the Cell input, change the cell color, and move Gary forward one unit. The board class shall print the state of the board at every step. See the below example with a boardSize input of 5 for 10 steps:

[Gary Location] {2, 2} [Gary Orientation] up [Row 0] 0 0 0 0 0 [Row 1] 0 0 0 0 0 [Row 2] 0 0 0 0 0 [Row 3] 0 0 0 0 0 [Row 4] 0 0 0 0 0
[Gary Location] {2, 3} [Gary Orientation] right [Row 0] 0 0 0 0 0 [Row 1] 0 0 0 0 0 [Row 2] 0 0 1 0 0 [Row 3] 0 0 0 0 0 [Row 4] 0 0 0 0 0
[Gary Location] {3, 3} [Gary Orientation] down [Row 0] 0 0 0 0 0 [Row 1] 0 0 0 0 0 [Row 2] 0 0 1 1 0 [Row 3] 0 0 0 0 0 [Row 4] 0 0 0 0 0
[Gary Location] {3, 2} [Gary Orientation] left [Row 0] 0 0 0 0 0 [Row 1] 0 0 0 0 0 [Row 2] 0 0 1 1 0 [Row 3] 0 0 0 1 0 [Row 4] 0 0 0 0 0
[Gary Location] {2, 2} [Gary Orientation] up [Row 0] 0 0 0 0 0 [Row 1] 0 0 0 0 0 [Row 2] 0 0 1 1 0 [Row 3] 0 0 1 1 0 [Row 4] 0 0 0 0 0
[Gary Location] {2, 1} [Gary Orientation] left [Row 0] 0 0 0 0 0 [Row 1] 0 0 0 0 0 [Row 2] 0 0 0 1 0 [Row 3] 0 0 1 1 0 [Row 4] 0 0 0 0 0
[Gary Location] {1, 1} [Gary Orientation] up [Row 0] 0 0 0 0 0 [Row 1] 0 0 0 0 0 [Row 2] 0 1 0 1 0 [Row 3] 0 0 1 1 0 [Row 4] 0 0 0 0 0
[Gary Location] {1, 2} [Gary Orientation] right [Row 0] 0 0 0 0 0 [Row 1] 0 1 0 0 0 [Row 2] 0 1 0 1 0 [Row 3] 0 0 1 1 0 [Row 4] 0 0 0 0 0
[Gary Location] {2, 2} [Gary Orientation] down [Row 0] 0 0 0 0 0 [Row 1] 0 1 1 0 0 [Row 2] 0 1 0 1 0 [Row 3] 0 0 1 1 0 [Row 4] 0 0 0 0 0
[Gary Location] {2, 1} [Gary Orientation] left [Row 0] 0 0 0 0 0 [Row 1] 0 1 1 0 0 [Row 2] 0 1 1 1 0 [Row 3] 0 0 1 1 0 [Row 4] 0 0 0 0 0
[Gary Location] {3, 1} [Gary Orientation] down [Row 0] 0 0 0 0 0 [Row 1] 0 1 1 0 0 [Row 2] 0 0 1 1 0 [Row 3] 0 0 1 1 0 [Row 4] 0 0 0 0 0

the format is given by [Gary Location] {(row), (col)} (orientation) [Row 0] (col 0 color) (col 1 color) ... (col N-1 color) [Row 1] ... [Row (N-1)] ... (col N-1 color) where values within ( ) are to be filled in with program values. (col i color) shall be either "0" for "white" or "1" for "black". Note that students may want to call Cell::get_color_string( ) to print this value (or just Cell::get_color() as pointed out by a student in office hours!). This output will either be to standard output, i.e., std::cout, if a filename command line argument is not provided or will be printed to the filename given in the argument (students should use the ofstream object for file output. Note that C's fprintf will also be okay). The filename shall be set with the setOutputFilename member function.

Students are free to impliment the remaining functionality of the Board class as desired. The class should store a representation of the actual grid of cells which define the environment for Langon's ant, i.e., the Cell class created in Part A (Hint: I utilized a vector of vectors where each element of the outer vector stores a "row" or the grid represented by a vector of class Cell). The board class must also store a variable of type Gary that "walks" about the board. (More information on Gary is given below) At each step in the Gary::move_gary(Cell*) function the Board must pass a pointer to the Cell that Gary currently occupies so that Gary can alter his orientaiton, flip the color of that cell, i.e., call the change_color member function, and change his position, i.e., "walk" (find a tutorial for pointers to objects here).

The Gary class is subject to C++ unit testing and therefore has stricter requirements for composition. Each required member function will be denoted. (

1) Gary shall be constructed with a parameterized constructor accepting an unsigned integer input parameter representing the size of the board (denote here as BoardSize). Assume that BoardSize is odd! Gary shall initialize his position to be the middle cell of the board, e.g., if the BoardSize is given as 5 Gary would be initialized at index (2,2).

(2) Gary shall contain public member functions which return an unsigned integer type and accept no input named Gary::get_row() and Gary::get_col() which return Gary's row and column position on the board respectively.

(3) Gary shall contain a public member function which returns type void and accepts a Cell pointer called Gary::move(Cell*) which shall (a) alter Gary's orientation based on the Cell's color (b) change the Cell's color (c) move Gary one unit forward in the new orientation

(4) Gary shall contain a public member function which returns type orientation (defined as an enumeration enum orientation {up, right, down, left};) and accepts no input parameters called Gary::get_orientation()

In: Computer Science

2. In lieu of a risk assessment, what should a small company do to assess its...

2. In lieu of a risk assessment, what should a small company do to assess its security posture if a risk assessment is not financially practical?

In: Computer Science

Consider a binary classification problem where each example (observation) x has n features and class label...

Consider a binary classification problem where each example (observation) x has n features and class label y can take one of the two possible values: y = 1 (positive class label) and y = 0 (negative class label). Suppose a Logistic Regression model is trained using a training set and θ ∈ Rn is the learned parameter vector of this trained model. Show that given an unseen example x ∈ Rn having n features, the trained Logistic Regression model will predict its class label to be 1, if θ⊤x > 0 and class label to be 0 otherwise.

In: Computer Science

1. Superior Bake Shop sells a variety of baked goods online. Attributes of Baked Good include...

1. Superior Bake Shop sells a variety of baked goods online. Attributes of Baked Good include ProductID, ProductName, Product Category, Weight, and Price. Attributes of Customer include CustomerID, CustomerName, and CustomerAddress (composed of Street, City, State, and ZipCode). Customers place orders with Superior BakeShop. Attributes of order are OrderID and OrderDate. All customers have placed at least one order and customers may place many orders over time. Each order is placed by a single Customer. Orders can include one or more baked good. A baked good can be included in one or more order. Superior Bake Shop keeps track of the quantity of each baked good that is included in an order.

2. Blue Orchard Bake Shop (BOBS) offers a variety of baking workshop. BOBS keeps track of the workshops it offers as well as its teachers and students. Attributes of workshop include WorkshopID, Date, Time, and Fee. Attributes of teacher include TeacherID, TeacherName, (composed of FirstName, MiddleInitial, and LastName), PaymentPerWorkshop, and Skills. Many teachers have more than one skill. Attributes of student include StudentID, StudentName (composed of FirstName, MiddleInitial, and LastName), StudentAddress (composed of Street, City, State, and ZipCode), DateOfBirth, and Age. Students can participate in more than one workshop, but must participate in at least one workshop. Each workshop can have multiple students, but must have at least one student. All workshops are taught by a single teacher. Teachers can teach any number of workshops including zero in the case of a new teacher who has not yet offered a workshop.

3. Main Street Catering has residential, business, and school clients. Attributes of residential clients include ClientNumber, ClientName (composed of FirstName, MiddleInitial, and LastName), ClientAddress (composed of Street, City, State, and ZipCode), and NearestCrossStreets. For each residential client, the two nearest cross streets are stored. Attributes of business clients include ClientNumber, BusinessName, ClientAddress (composed of Street, City, State, and ZipCode), and AnnualCateringBudget. Attributes of school clients include ClientNumber, SchoolName, SchoolDistrictCode, and ClientAddress (composed of Street, City, State, and ZipCode). Some residential clients are also business clients, and some residential clients are also school clients. Main Street Catering has a few clients who are neither residential, nor business, nor school clients.

Draw a conceptual data model to model the scenario in each problem. Use the model constructs (e.g., the material on the E-R model and the enhanced E-R model) from chapters 2 and 3 as appropriate and follow the modeling conventions used in the example problems in the online lessons. Do not use the modeling conventions shown in Figure 2-22 of the Hoffer textbook which illustrate a data model in Visio notation. Be sure to include all appropriate completeness constraints, disjointness constraints, and subtype indicators in your conceptual data models.

In: Computer Science

Below are three methods: checkValidInput, getCoordinates and play. Looking at checkValidInput, I feel it is very...

Below are three methods: checkValidInput, getCoordinates and play. Looking at checkValidInput, I feel it is very longwinded and would like to modify by using a try/catch block for user input. How is this occomplised? Would I be able to get rid of checkValidInput method with a try/catch? Any code to help me out would be great.

public boolean checkValidInput(String input){
    ArrayList<String> numList = new ArrayList<String>();
    for (int i=0;i<10;i++){
        numList.add(""+i);
    }
    String[] coordinates = input.split(" ");
    //returns false if there are not 2 strings
    if (coordinates.length!=2){
        return false;
    }
    //returns false if first is String is not in between A and J
    if(coordinates[0].charAt(0)<'A' || coordinates[0].charAt(0)>'J')
        return false;
    //returns false if the second string is not a single digit number
    for (String str: coordinates[1]){
        if (numList.contains(str)==false){
            return false;
        }
    }
    //returns false if the coordinates have already been shot at
    int row = Integer.parseInt(coordinates[0]);
    int column = Integer.parseInt(coordinates[1]);
    if (this.availableSpot[row][column]==false){
        return false;
    }

    return true;
}
public int[] getCoordinates(String input)
{
    int[] coordinates = new int[2];
    String[] strList = input.split(" ");
    int row = (int) strList[0].charAt(0) - 65;
    int column = Integer.parseInt(strList[1]);
    coordinates[0] = row;
    coordinates[1] = column;
    return coordinates;
}
public void play()
{
    print(101);
    print(1);
    ocean.randomShipDeployment();
    boolean isGameOver = ocean.isGameOver();
    sc = new Scanner(System.in);

    //printOcean the ocean and start the game
    ocean.printOcean();
    print(3);
    while (!isGameOver)
    {
        print(2);
        String input = sc.nextLine();

        //check if input is valid
        while (!checkValidInput(input))
        {
            print(99);
            input = sc.nextLine();
        }

        //get coordinates and fire
        int[] coordinates = getCoordinates(input);
        int row = coordinates[0];
        int column = coordinates[1];
        ocean.shotFiredAtLocation(row, column);
        availableSpot[row][column] = false;
        isGameOver = ocean.isGameOver();
        ocean.printOcean();
        print(3);
        print(100);
    }
    //printOcean info saying you win
    print(4);
    print(5);
}

In: Computer Science

C++ programming,How to remove element from string without using the string::erase() function ? example: input string:"cheasggaa"...

C++ programming,How to remove element from string without using the string::erase() function ?

example:

input string:"cheasggaa"

element need to be removed:"ga"

output:"cheasga"

or:

input:"cekacssdka"

element:"ka"

output:"cecssd"

In: Computer Science

find and view several YouTube videos that discuss cloud se​curity. identify the URLs of three videos...

find and view several YouTube videos that discuss cloud se​curity. identify the URLs of three videos that you think do a good job communicating essetial issues approches for cloud security. if you could only recommend one to fellow students, which would you pick? why? summrize your recomedations and justification in a brief paper

In: Computer Science

Using the IDLE development environment, create a Python script named tryme4.py. (Note: an alternative to IDLE...

Using the IDLE development environment, create a Python script named tryme4.py. (Note: an alternative to IDLE is to use a free account on the pythonanywhere website: https://www.pythonanywhere.com/)

IDLE has both an interactive mode and a script mode. You must use the script mode to develop your script. Your script must use meaningful variable names and have comments that describe what is happening in your script. Comments may describe the assignment of a value to a variable, a computation and the assignment of the result to a variable, or the display of the result.

Write a function in this file called nine_lines that uses the function three_lines (provided below) to print a total of nine lines.

Now add a function named clear_screen that uses a combination of the functions nine_lines, three_lines, and new_line (provided below) to print a total of twenty-five lines. The last line of your program should call the function clear_screen.

The function three_lines and new_line are defined below so that you can see nested function calls. Also, to make counting “blank” lines visually easier, the print command inside new_line will print a dot at the beginning of the line:

def new_line():

print('.')

def three_lines():

new_line()

new_line()

new_line()

Submit your Python script file in the posting of your assignment. Your Python script should be either a .txt file or a .py file.

You must execute your script and paste the output produced into a document that you will submit along with your Python script.

It is very helpful if you print a placeholder between the printing of 9 lines and the printing of 25 lines. It will make your output easier to read for your peer assessors. A placeholder can be output such as “Printing nine lines” or “Calling clearScreen()”.

In: Computer Science

In the language c using the isspace() function: Write a program to count the number of...

In the language c using the isspace() function: Write a program to count the number of words, lines, and characters when user enter statements as input. A word is any sequence of non-white-space characters.

Have the program continue until end-of-file. Make sure that your program works for the case of several white space characters in a row. The character count should also include white space characters.

Example of the user input could be the statement below:

             You're traveling through

​               another dimension;

              a dimension not only

              of sight and sound,

               but of mind.

In: Computer Science

The following tables form a Library database held in an RDBMS: Borrower (card_no , last_name ,...

The following tables form a Library database held in an RDBMS:

Borrower (card_no , last_name , first_name , address , city , state , zip )
Books (ISBN, title, pub_date , pub_id , list_price, category_id, pub_id)
Categories (category_id, category_desc)
Author (author_id , last_name , first_name)
Bookauthor (ISBN, author_id)
Publisher (pub_id, name, contact, phone)
Bookloans (ISBN, branch_id, card_no , date_out, due_date)
Bookcopies (ISBN, branch_id , no_of_copies)
Branch (branch_id, branch_name, city)


Please use the standard join method, no implicit method allowed.


Write SQL statements to perform the following queries:
1. Display the title of each book and the name and phone number of the contact at the publisher’s office for reordering each book.

2. Which books were written by an author with the last name Steven? Perform the search using the author name.

3. Identify the authors of the books Leila Smith borrowed Perform the search using the borrower last name.

4. Display the most recent publication date of all books.

5. Display the list price of the least expensive book in the Computer Science category.

6. What’s the list price of the most expensive book written by Carlos Tim?

7. Display how many times each book title has been borrowed.

8. How many times has the book with ISBN “0401140733” been borrowed?

In: Computer Science

Create a html page to convert miles into kilometers, the page should have four buttons using...

Create a html page to convert miles into kilometers, the page should have four buttons using FOR loop to convert values from 1-25, 25-50, 50-75, and 75-100

Upon clicking any of the four button, output should display the range miles to kilometers in table cell.

In: Computer Science

Write a C program. Problem 1: You are given two sorted arrays, A and B, and...

Write a C program.

Problem 1: You are given two sorted arrays, A and B, and A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order without using any other array space. Implementation instruction: (1) Define one array of size 18 for A and the other array of size 5 for B. (2) Initialize A by inputting 13 integers in the ascending order, and Initialize B by inputting 5 integers in the ascending order. (Note: don’t hard code the integers of the arrays.) (3) Merge B with A in a way all values are sorted. (4) Print out the updated array A, after merging with B. For example: If your input for A is 1, 3, 11, 15, 20, 25, 34, 54, 56, 59, 66, 69, 71 and your input for B is 2, 4, 5, 22, 40 Finally, after merging A and B, A becomes 1, 2, 3, 4, 5, 11, 15, 20, 22, 25, 34, 40, 54, 56, 59, 66, 69, 71

In: Computer Science

In Java: Implement a program that directs a cashier how to give change. The program has...

In Java:

Implement a program that directs a cashier how to give change. The program has two inputs: the amount due and the amount received from the customer.

Display the dollars, quarters, dimes, nickels, and pennies that the customer should receive in return. In order to avoid roundoff errors, the program user should supply both amounts in pennies (for example 274 instead of 2.74).

In: Computer Science