In: Computer Science
Create a table of all three of these trigonometric functions for angles from 0 to 2p, with a spacing of 0.1 radian. Your table should contain a column for the angle and then for the sine, cosine, and tangent. ((python))
In: Computer Science
I am working on a project for my Computer Science course. I am trying to create a Battleship game where a user names two coordinates on a grid and is then told whether this results in a "Hit" or a "Miss". Once the ship has been hit a certain number of times (based on the size of the ship) the ship is sunk. I have written all the code but it now fails to execute when I try to run it. Could someone please help me to get this program working properly? I will paste the code below:
battleship.h:
#ifndef BATTLESHIP_H_
#define BATTLESHIP_H_
// coordinates (location) of the ship and shots
class location {
public:
void locationreset(void); // void constructor, assigns -1 to
X
void pick(void); // picks a random location
void fire(void); // asks the user to input the
// coordinates of the next shot
void print(void) const; // prints location in format "a1"
// returns true if the two locations match
friend bool compare(location, location);
private:
static const int fieldSize = 5; // the field (ocean) is fieldSize X
fieldSize
int x; // 1 through fieldSize
char y; // 'a' through fieldSize
};
// contains ship's coordinates (location) and whether is was
sunk
class ship {
public:
ship(void); // void constructor, sets sunk=false
bool match(location) const; // returns true if this location
matches
// the ship's location
bool isSunk(void) const { return(sunk); }; // checks to see if the
ship is sunk
void sink(void); // sets "sunk" member variable of the ship to
true
void setLocation(location); // deploys the ship at the specified
location
void printShip(void) const; // prints location and status of the
ship
private:
location loc;
bool sunk;
};
// contains the fleet of the deployed ships
class fleet {
public:
void deployFleet(void); // deploys the ships in random
locations
// of the ocean
bool operational(void) const; // returns true if at least
// one ship in the fleet is not sunk
bool isHitNSink(location); // returns true if there was a
deployed
// ship at this location (hit) and sinks it
// otherwise returns false (miss)
void printFleet(void) const; // prints out locations of ships in
fleet
private:
static const int fleetSize = 5; // number of battleships
bool check(location); // returns true if one of the ship's
locations
// matches the ship, returns false
// if none-match
ship ships[fleetSize]; // battleships of the fleet
};
#endif /* BATTLESHIP_H_ */
//////////////////////////////////////////////////////////////////////////////////////////////////////////
battleship.cpp:
#include <iostream>
#include <ctime>
#include <cstdlib>
#include "battleship.h"
using namespace std;
void location::locationreset(void) {
x = -1;
y = 'x';
}
void location::pick(void) {
x = rand() % fieldSize + 1;
y = rand() % fieldSize;
switch (y) {
case 0: y = 'a'; break;
case 1: y = 'b'; break;
case 2: y = 'c'; break;
case 3: y = 'd'; break;
case 4: y = 'e'; break;
}
}
void location::fire(void) {
cout << "input the coordinates of the next shot
"; cin >> y >> x;
}
void location::print() const {
cout << y << x;
}
bool compare(location loc1, location loc2) {
return (loc1.x == loc2.x && loc1.y ==
loc2.y);
}
ship::ship(void) {
sunk = false;
}
bool ship::match(location shiploc) const {
return compare(loc, shiploc);
}
void ship::sink(void) {
sunk = true;
}
void ship::setLocation(location shiploc) { //
deploys the ship at the specified location
loc = shiploc;
}
void ship::printShip(void) const { // prints location and status
of the ship
loc.print();
if (sunk == true)
cout << "sunk";
else if (sunk == false)
cout << "not sunk" <<
endl;
}
void fleet::deployFleet(void) { // deploys the ships in random
locations of the ocean
location loc; loc.locationreset();
for (int i = 0; i < fleetSize; i++) {
loc.pick();
ships[i].setLocation(loc);
}
}
bool fleet::operational() const { // returns true if at least
one ship in the fleet is not sunk
for (int i = 0; i < fleetSize; ++i)
if (ships[i].isSunk() ==
false)
return
true;
return false;
}
bool fleet::isHitNSink(location shiploc) { //
returns true if there was a deployed
for (int i = 0; i < fleetSize; ++i) {
if (ships[i].match(shiploc) == true
&& ships[i].isSunk() == false)
{
ships[i].sink();
return
true;
}
else
return
false;
}
}
void fleet::printFleet(void) const { // prints out locations of
ships in fleet
for (int i = 0; i < fleetSize; ++i)
ships[i].printShip();
}
bool fleet::check(location shiploc) {
for (int i = 0; i < fleetSize; ++i)
if (ships[i].match(shiploc))
{
return
true;
}
else
{
return
false;
}
}
////////////////////////////////////////////////////////////////////////////
main.cpp:
#include "battleship.h"
#include <iostream>
using namespace std;
int main() {
srand(time(NULL));
char answer;
fleet myFleet; //computer's ships
myFleet.deployFleet(); // fleet is deployed at random
locations
cout << "Do ships' positions and status need to
be printed? (y for yes)" << endl;
cin >> answer;
if (answer == 'y')
myFleet.printFleet();
while (myFleet.operational() == true) {
cout << "there are still
ships up";
location userShot;
userShot.locationreset();
cout << "Input location(a-e
1-5): ";
userShot.fire();
if (myFleet.isHitNSink(userShot) ==
true)
cout <<
"hit";
else
cout <<
"miss";
cout << "Do ships' positions
and status need to be printed? (y for yes, q to quit)";
cin >> answer;
if (answer == 'y')
myFleet.printFleet();
else if (answer == 'q')
break;
}
}
In: Computer Science
given an array A = {a1, a2, ... ,
an}
find the number of the continuous subarrays of gcd one
continuous subarrays of gcd one means gcd(ai,
ai+1, ... , aj) = 1
for example {2, 4, 6, 3} or {1} are continuous subarrays of gcd
one
In: Computer Science
Need this in C++:
Suppose that you are given a set of words; and two words from the set: word 1 and word 2.
Write a program which will transform word 1 into word 2 by changing a single letter in word 1 at a time.
Every transition that word 1 takes will have to be in the set of words.
You must output the smallest sequence of transitions possible to convert word 1 into word 2.
You may assume that all the words in the dictionary are the same length.
The first line will be word 1 and word 2 separated by a comma, followed by the set of words. The set of words will be terminated by a ‘-1’.
Input:
DOG,GOD
DOG
BOG
GOG
ABH
GOD
THU
IOP
-1
Output:
DOG -> GOG -> GOD
Input:
HOUSE,JOUKS
MOUSE
HIUKE
HIUKS
HOUSH
LOUSE
HOZKS
SOUSE
HOUKS
HOUSE
HOUKE
JOUKZ
JOUKS
HOIKE
-1
Output:
HOUSE -> HOUKE -> HOUKS -> JOUKS
In: Computer Science
In Ruby
A dentist appointment schedule validation software
Implement a superclass Appointment and sub classes OneTime, Day and Month. An appointment has a description (for example, "Root Canal"), and dates information (you can use Date object or int Year, Int Month, Int Day). Fill an array of Appointment objects with a mixture of appointments.
Write a method OccursOn inside each of the sub classes that checks whether the appointment occurs on that date (OneTime), day (Day) or month (Month). Ask the user to enter a date to check (for example, 2006 10 5), and ask to user if they want to check against OneTime, Day or Month appointment. Based on what the user selected, OccursOn inside each of the sub class should run and display any matching appointment and associated descriptions.
Hint: For OneTime subclass, OccursOn need three inputs (Year, Month and Day) to validate, for Day subclass, OccursOn needs one input (Day) to validate, and for Month subclass, OccursOn need one input (Month) to validate. OccursOn is different for different subclasses.
In: Computer Science
Calculator Class Instructions
Create a calculator class that will add, subtract, multiply, and divide two numbers. It will have a method that will accept three arguments consisting of a string and two numbers example ("+", 4, 5) where the string is the operator and the numbers are what will be used in the calculation.
The class must check for a correct operator (+,*,-,/), and a number (integer) for the second and third argument entered. The calculator cannot divide by zero that will be an error.
Separate error messages will be displayed for all errors. Also, separate success messages will be displayed with each successful answer. This script will run using a browser. The output of the script will display after the web address is entered into the browser navigation window. There will be a separate file that will require the class. That file will be used to instantiate the class and call the appropriate method, while the class will do the heavy lifting.
You will have two files
One will be the file that is your class.
The other will be a file that requires your class and call the
appropriate method. This is the file you will provide the web
address for.
For example:
If you have a file with a class named $Calculator. You will have another class that uses the calculator class and displays the information. That file will have the code shown below.
NOTE: You are to use the code shown below as your test code.
NOTE: For this assignment you can write the following code within a PHP block within the HTML body element. You do not need to write the comments I did that to show you what needs to be outputted depending on what is sent as arguments.
<?php
require_once "Calculator.php";
$Calculator = new Calculator();
echo $Calculator->calc("/", 10, 0); //will output Cannot divide
by zero
echo $Calculator->calc("*", 10, 2); //will output The product of
the numbers is 20
echo $Calculator->calc("/", 10, 2); //will output The division
of the numbers is 5
echo $Calculator->calc("-", 10, 2); //will output The difference
of the numbers is 8 echo $Calculator->calc("+", 10, 2); //will
output The sum of the numbers is 12
echo $Calculator->calc("*", 10); //will output You must enter a
string and two numbers echo $Calculator->calc(10); //will output
You must enter a string and two numbers
?>
The browser will output (based upon the above methods):
Cannot divide by zero
The product of the numbers is 20
The division of the numbers is 5
The difference of the numbers is 8
The sum of the numbers is 12
You must enter a string and two numbers You must enter a string and
two numbers
in PHP/HTML
In: Computer Science
How would you call a username in a different function when coding in C?
I have a function that logs a user in, and I would like to say if (username == 'abc'){do function} but everytime I use the 'username' variable in a different function, it says it is an undeclared identifier.
In: Computer Science
User Python to solve; show all code:
Write a program that will prompt the user for the player data described above. The user does not know how many players are on the team so allow the user to enter the word end when he/she has finished entering data.
Validate that the player is not entered more than once.
After entering the data, compute the following:
In: Computer Science
Java Special Methods:
A) Write a method that finds the maximum of two numbers. You should not use if-else or any other comparison operator.
B) Write methods to implement the multiply, subtract and divide operations for integers. The results of all of these are integers. Use only the add operator.
In: Computer Science
Given the strings s1 and s2 that are of the same length, create a new string s3 consisting of the last character of s1 followed by the last character of s2, followed by the second to last character of s1, followed by the second to last character of s2, and so on
In: Computer Science
2. Convert the following decimal fractions to binary with a
maximum of six places to the right of the binary point: [12]
a. 25.84375 b. 57.55 c. 80.90625 d. 84.874023
In: Computer Science
In Java
In mathematics, factorial of a non-negative integer n, denoted by n! , is the product of all positive integers less than or equal to n. For example,
5! = 5 * 4 * 3 * 2* 1 = 120
3! = 3 * 2 * 1 = 6
2! = 2 * 1 = 2
The value of 0! is 1.
Write a program that asks user to enter an integer > 0; if a valid value is entered, it should calculate and display factorial of the number entered. If the user enters an integer <=0, display a message "Invalid entry - valid entry is an integer > 0" and have them re-enter the information.
In: Computer Science
Use Python to solve, show all code
Write a program that sums a sequence of integers from a starting integer to and ending integer. The sequence is generated by skipping a value (e.g. 1,3,5,… or 2,6,10,14…). Prompt the user for a) a starting value greater than 0. Validate the value is greater than 0.
b) the ending value.
c) the value to skip
Print out the sum of the numbers for the sequence. If the starting value is 2, the ending value is 10 and the value to skip is 2, the sequence would be 2,4,6,8,10
Sample Interaction:
Enter the starting value: -1
Error – invalid number
Enter the starting value: 2
Enter the ending value: 10
Enter the value to skip: 2
The sum of the integers from 2 to 10 skipping 2 is 30
In: Computer Science
For this Discussion, you will analyze mobile security threats and evaluate countermeasures.
Briefly describe your mobile device and another device currently on the market that uses a different OS. Explain the security vulnerabilities associated with each device. Explain the security solutions that would address the vulnerabilities. Finally, state which OS has more robust security and explain your reasoning.
In: Computer Science