Write this code in Python only.
Draw a 12" ruler on the screen. A ruler is basically a rectangular outline with tick marks extending from the top edge. The tick marks should be drawn at each quarter-inch mark. Below the tick marks, your ruler should show large integers at each full-inch position.
In: Computer Science
Explain "In a virtual network, service is described in a data structure, and exists entirely in a software abstraction layer, reproducing the service on any physical resource running the virtualization software.
The configuration attributes of the service can be found in software with API interfaces, thereby unlocking the full potential of networking devices."
In: Computer Science
Write a program compare.cpp that asks the user to input two dates (the beginning and the end of the interval). The program should check each day in the interval and report which basin had higher elevation on that day by printing “East” or “West”, or print “Equal” if both basins are at the same level.
Example:
$ ./compare Enter starting date: 09/13/2018 Enter ending date: 09/17/2018 09/13/2018 West 09/14/2018 West 09/15/2018 West 09/16/2018 West 09/17/2018 West
Explanation:
| Date | East (ft) | West (ft) | |
|---|---|---|---|
| 09/13/2018 | 581.94 | 582.66 | West is higher |
| 09/14/2018 | 581.8 | 582.32 | West is higher |
| 09/15/2018 | 581.62 | 581.94 | West is higher |
| 09/16/2018 | 581.42 | 581.55 | West is higher |
| 09/17/2018 | 581.16 | 581.2 | West is higher |
In: Computer Science
First, Calculate the 1/3 in binary form using 8-digits. Then convert binary form back to decimal. Why and what is the error in binary representation ?
In: Computer Science
The coding must be formatted in Python.
Write a function matrix_power(A, n) that computes the power An using Boolean arithmetic and returns the result. You may assume that A is a 2D list containing only 0s and 1s, A is square (same number of rows and columns), and n is an integer ≥ 1. You should call your previously written matrix multiply boolean function. Example: Let R = [ [0, 0, 0, 1], [0, 1, 1, 0], [0, 0, 0, 1], [0, 0, 1, 0] ] Then calling matrix power(R, 2) should return [ [0, 0, 1, 0], [0, 1, 1, 1], [0, 0, 1, 0], [0, 0, 0, 1] ]
In: Computer Science
Maze in C++
Simple Maze Program – Project Specifications:
1. Create a simple maze game that a player must traverse to win.
3. The maze must be text-based and adjustable from 5x5 to 20x20. • Player gets to choose size either as:
1) any size in the range from 5-20 by 5-20. 2) selects from 4 set size options [5x5,10x10,15x15, and 20x20] • the player can choose among different mazes. • You will need to figure out how to denote your location in the maze.
For a 5x5 maze you have 25 actual spots that are valid, if you can get to them. • You will need to figure out a way to know if you can move in a particular direction or not. You cannot move East if there is a wall to your East.
4. The maze must be displayed with a current position of the player after each move. • Display the Text-based Maze to the player - top-down view • Players sees the maze layout (walls and openings), but not what is in each maze area (e.g. Items, locked door, or mobs)
5. The maze must contain Randomized Items for the player to pick up or interact with: • At the start of the game -- Items are randomly placed in the maze • Only story specific items at the starting and ending locations, do not need to be randomized.
Some suggestion for Classes:
1. Maze -- data and functions associated with maintaining and drawing the maze
2. Items -- data and functions associated with each object in the maze
3. Player -- data and functions associated with the player
4. Backpack -- data and functions associated with stuff player picks up in maze
Some suggestion for Functions – mostly if classes not used:
1. Function to display Maze Game Introduction.
2. Function to display Game Help.
3. Function to display the maze for the player.
4. Function to get move direction from player.
5. Function to display information about current location.
6. Function to display information about a specific item.
7. Function to display current inventory
8. Function to display menu or user prompt for next command.
9. Function to display whether the player won or lost
11.The Maze Game Program needs to include:
• A game introduction displayed to the player to welcome them to the game. • Initialize all the game elements.
• Create a Play Again Loop so the player can play again.
• Create an internal Game Loop so that the player can progress through the game one command at a time.
• User Prompts to let the player know how to interact with the game and what commands are valid at this time. This prompt can either be 1 line or a menu display. • A help display on command.
• Quit must be accepted as a command to stop the game at any time. • The maze must be displayed with current position after every command is acted upon.
• You must give the player information/feedback of their current position and what is around them (like items) after each command to let them know their status.
• You must let the player know they won or lost or quit to end the play Game Loop.
• A game farewell message must be given before you end the game.
In: Computer Science
Write a MARIE assembly language program that will read an “array” of positive decimal values stored in memory and output the smallest value. Use variable addr to store the location of the first data item. Use variable length to store the number of items in your array.
Your code should be organized such that adding an additional array item would only involve adding the data line (ie. 021 dec 400) and updating the length variable (ie. length, dec 5). You can assume there will be at least one data value.
Use comments throughout your program. Save your program as h9part1.mas and upload to our course web site.
/sample data, note: addresses will vary depending on your implementation
015 addr, hex 017
016 length, dec 4
017 dec 100
018 dec 200
019 dec 50
020 dec 300
In: Computer Science
Java Programming Problem:
Define a generic method called checkOrder() that checks if four items are in ascending, neither, or descending order. The method should return -1 if the items are in ascending order, 0 if the items are unordered, and 1 if the items are in descending order.
The program reads four items from input and outputs if the items are ordered. The items can be different types, including integers, Strings, characters, or doubles.
Ex. If the input is:
bat hat mat sat 63.2 96.5 100.1 123.5
the output is:
Order: -1 Order: -1
The following is the current code for the problem:
import java.util.Scanner;
public class WhatOrder {
// TODO: Define a generic method called checkOrder() that
// takes in four variables of generic type as arguments.
// The return type of the method is integer
// Check the order of the input: return -1 for ascending,
// 0 for neither, 1 for descending
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
// Check order of four strings
System.out.println("Order: " + checkOrder(scnr.next(), scnr.next(),
scnr.next(), scnr.next()));
// Check order of four doubles
System.out.println("Order: " + checkOrder(scnr.nextDouble(),
scnr.nextDouble(), scnr.nextDouble(), scnr.nextDouble()));
}
}
In: Computer Science
Write a C++ program to score the paper-rock-scissor game. Each of two players (player1 and player2) input a character which could be either ‘P’, ‘R’, or ‘S’ (in uppercase or lowercase). For any other input character should display a message “Invalid input”. The program then announces who is the winner as well as the basis for determining the winner which could be one of the following: “Paper covers rock”, “Rock breaks scissors”, “Scissors cut paper”, or “Nobody wins”. (Use switch statement)
Please do not add up the scores just have a simple quick game and then I would have to reset the program to play again
In: Computer Science
VISUAL BASIC (VB.NET)1. Create a Sub Procedure with a
name of your choice and in the procedure, declare a
2-Dimensinal (2-D) array that can store 15 Integer numbers. Then
implement a
nested loop that will be used to store any 15 Integer numbers into
the 2-D array at
runtime (an interactive program).
The implementation will be such that the program cannot terminate
unless all the
inputs provided are integers (user input validation). If you
provide an invalid input,
you should be asked to “Try again”. Make sure also to print out all
valid inputs
respectively, after the point of insertion.
Note – The Procedure you created should be called in the Main
Procedure to run it.
In: Computer Science
Please paraphrase this c code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void sortGrades(int arr[], int size, int status, char
names[][20]);
void printer(int grades[], int size, char names[][20]);
void sortNames(char arr[][20], int size, int status, int
grades[]);
void nameSearch(int grades[], int size, char names[][20]);
void numSearch(int grades[], int size, char names[][20]);
int main()
{
int i;
int size;
int option;
do
{
printf("\n\nInput Number of Students or 0 to exit : ");
scanf("%d", &size);
if (size == 0)
{
break;
}
char names[size][20];
int grades[size];
for (i = 0; i < size; i++)
{
printf("\nEnter the Name of Student %d : ", i + 1);
scanf("%s", &names[i]);
printf("Enter the Grades of Student %d : ", i + 1);
scanf("%d", &grades[i]);
}
do
{
printf("\n\nEnter\n1 for sort by Name(A-Z)\n2 for sort by
Name(Z-A)\n3 for sort by Grades(Ascending)\n4 for sort by
Grades(Descending)\n5 for search by Name\n6 for search by Grade's
limit\n0 to re enter data\n");
scanf("%d", &option);
switch (option)
{
case 1:
sortNames(names, size, 1, grades);
printer(grades, size, names);
break;
case 2:
sortNames(names, size, 0, grades);
printer(grades, size, names);
break;
case 3:
sortGrades(grades, size, 0, names);
printer(grades, size, names);
break;
case 4:
sortGrades(grades, size, 1, names);
printer(grades, size, names);
break;
case 5:
nameSearch(grades, size, names);
break;
case 6:
numSearch(grades, size, names);
break;
default:
break;
}
} while (option != 0);
} while (size != 0);
return 0;
}
void sortGrades(int arr[], int size, int status, char
names[][20])
{
int i, j; /*counter*/
int temp;
char temp2[100];
for (j = 0; j < size - 1; j++)
/*outer for loop to repeat to repeat inner loop without the largest
number selected before*/
{
for (i = 0; i < size - 1 - j; i++) /*inner for loop to swap the
largest number to the end*/
if (status == 0)
{
if (arr[i] < arr[i + 1])
{
// swapping using temp
temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
strcpy(temp2, names[i]);
strcpy(names[i], names[i + 1]);
strcpy(names[i + 1], temp2);
}
}
else
{
if (arr[i] > arr[i + 1])
{
// swapping using temp
temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
strcpy(temp2, names[i]);
strcpy(names[i], names[i + 1]);
strcpy(names[i + 1], temp2);
}
}
}
}
void sortNames(char arr[][20], int size, int status, int
grades[])
{
int i, j; /*counter*/
char temp[100]; /*temporary value for swap*/
int temp2;
for (j = 0; j < size - 1; j++)
/*outer for loop to repeat to repeat inner loop without the largest
number selected before*/
{
for (i = 0; i < size - 1 - j; i++) /*inner for loop to swap the
largest number to the end*/
if (status == 0)
{
if (strcmp(arr[i], arr[i + 1]) < 0)
{
// swapping using temp
strcpy(temp, arr[i]);
strcpy(arr[i], arr[i + 1]);
strcpy(arr[i + 1], temp);
temp2 = grades[i];
grades[i] = grades[i + 1];
grades[i + 1] = temp2;
}
}
else
{
if (strcmp(arr[i], arr[i + 1]) > 0)
{
// swapping using temp
strcpy(temp, arr[i]);
strcpy(arr[i], arr[i + 1]);
strcpy(arr[i + 1], temp);
temp2 = grades[i];
grades[i] = grades[i + 1];
grades[i + 1] = temp2;
}
}
}
}
void nameSearch(int grades[], int size, char names[][20])
{
int i;
char key[20];
int fail = 0;
printf("\nInput a Name that you want to find : ");
scanf("%s", &key);
for (i = 0; i < size; i++)
{
if (strcmp(names[i], key) == 0)
{
printf("\nMatch Found\nName : %s\nGrade : %d\nIndex Number : %d",
names[i], grades[i], i);
fail++;
}
}
if (fail == 0)
{
printf("\nMatch NOT Found");
}
}
void numSearch(int grades[], int size, char names[][20])
{
int j; /*counter*/
int key, condition, option;
printf("Enter a grade as limit/pivot to filter data : ");
scanf("%d", &key);
printf("Enter condition:\n1 for Greater than %d\n2 for Less than
%d\n", key, key);
scanf("%d", &option);
printf(" Name");
printf(" grades\n");
for (j = 0; j < size; j++)
{
switch (option)
{
case 1:
if (grades[j] > key)
{
printf("%10s", names[j]);
printf("%10d\n", grades[j]);
}
break;
case 2:
if (grades[j] < key)
{
printf("%10s", names[j]);
printf("%10d\n", grades[j]);
}
break;
default:
break;
}
}
}
void printer(int grades[], int size, char names[][20])
{
int j; /*counter*/
printf(" Name");
printf(" grades\n");
for (j = 0; j < size; j++)
{
printf("%10s", names[j]);
printf("%10d\n", grades[j]);
} /* for loop to print all of reversed array content*/
}
In: Computer Science
A complex number is a number with two components, namely, the real part (rel) and the imaginary part (img). For example the complex number (a+bi) has a as the real part and b as the imaginary part. In developing such a class, assume that both of the real and imaginary parts to be floats. The symbol i represent . A declaration for the Complex class is presented next.
class Complex {
public:
Complex (float r = 0.0, float g= 0.0);
Complex (const Complex & c); //The copy
constructor
void print( ) const; // Print out the class data
Complex & negate ( ); // Multiplies the data members of a
complex object by a
// negative one.
Complex addComplex (const Complex & b);
// add two complex numbers, the calling
//object and b and return a new complex //one
Complex subComplex (const Complex &b);
// subtract two complex numbers, the
// calling object and b and return a new
// complex one
Complex multipComplex ( const Complex &c) const; // multiply
two complex
// numbers and return a complex one
Complex assginComplex ( const Complex & c); // assign one
complex number to
// another one and return the result in a complex object.
bool isEqual (const Complex & c) const; //compares one complex
number to
// another and returns a Boolean value
private:
float rel;
float img;
};
Implement and test the class Complex. Write a driver program to
test your Complex class. Instantiate several Complex objects. Test
that all your member functions work properly.
Hint
• Addition of two complex numbers: (a+bi) +(c+di) =
(a+c) + (b+d) i
• Subtraction: (a+bi) (c+di) = (a-c) + (b-d) i
• Multiplication: (a+bi) * (c+di) = (ac-bd) + (ad+bc)
i
A sample run is given below:
Please enter the first complex number C1(r,img) ; 1 -5
Please enter the second complex number C2(r,img) ; 2 11
Testing the copy constructor C3= C2 = 2+11i
Testing the negate function C4 = C3.negate() = -2 -11i
Testing the assign function C5 = C3.assignComplex(C4) = -2 -11i
Testing the isEqual function C4.isEqual(C5) = 1
Testing the Add Complex function C6 = C1.addComplex(C2) = 3+6i
Testing the Sub Complex function C7 = C1.subComplex(C2) = -1 -16i
Testing the multiply Complex function C8 = C1.multipComplex(C2) = 57+1i
In: Computer Science
THIS is to be done in python!
Splitting the Bill- An exercise in input validation Write a python program called splitBill.py that works as follows:
• (10 points) Allow the user to input a bill amount, a tip percent, and the number of people in their party. o Input validation: Make sure to validate the input data. Allow the user to reenter inputs until they enter values which are valid.
▪ Make it easy on the user: To leave a 20% tip, the user should just enter 20. The tip amount should be a number between 1 and 50.
▪ The bill amount should be some numeric value between 1 and 5000.
▪ The number of people should be between 1 and 20. o Your program must follow the design of the BMI program discussed in lecture.
▪ It must have (a version) of the following functions: getNumber, isInputValid, getValidNumberInput, and main as in BMI. • (5 points) Output the amount in dollars each person in the party should pay, assuming they want to split the cost evenly.
o Round the output to at most 2 decimal places. (Search for python’s round() which is not discussed in the book)
o Put a $ sign in front of the output
. o Create a new function getSplitAmount that serves as the brains of your program and returns the amount each person in the party owes. This function is the brains of this program similar to how the getBMICategory is the brains in the BMI program.
• (10 pts) Testing: Write tester functions for the isInputValid and getSplitAmount functions.
• (3 pts) Comments: Write a comment for the getSplitAmount function Here are some examples of how your program should work when all inputs are valid. The highlighted parts were typed by the user. Bill: 100 Tip percent: 20 Number of people: 6 Each person pays: $20.0 Bill: 27.50 Tip percent: 10 Number of people: 2 Each person pays: $15.12
Here are some examples of how your program should work when all inputs are valid.
The highlighted parts were typed by the user.
Bill: 100
Tip percent: 20
Number of people: 6
Each person pays: $20.0
Bill: 27.50 Tip percent: 10
Number of people: 2
Each person pays: $15.12
In: Computer Science
Write a complete java program that Define a class named sample containing:
Please enter two numbers to divide: 10 Hi
You entered wrong input. Try again.
Please enter two numbers to divide: 15 0
Division could not be completed.
Enter 5 double numbers: 2.5 3.1 5.0 9.3 10.0
Which element you want to print? (Choose a number between 0-4): 7
Wrong choice. Try again.
Which element you want to print? (Choose a number between 0-4): 3
The element in position 3 = 9.3
Thank you for using this program.
In: Computer Science
IN JAVA PLEASE
Implement a recursive approach to showing all the teams that can be created from a group (n things taken k at a time). Write the recursive showTeams()method and a main() method to prompt the user for the group size and the team size to provide arguments for showTeam(), which then displays all the possible combinations.
In: Computer Science