In a file called ThreeOperations.java, write a program that:
For example: if the user enters numbers 11 and 7, your program output should look EXACTLY like this:
Please enter real number N1: 11 Please enter real number N2: 7 11.000000 * 7.000000 = 77.00 11.000000 / 7.000000 = 1.57 11.000000 raised to the power of 7.000000 = 19487171.00
As another example: if the user enters numbers 3.25 and 10.3, your program output should look EXACTLY like this:
Please enter real number N1: 3.25 Please enter real number N2: 10.3 3.250000 * 10.300000 = 33.48 3.250000 / 10.300000 = 0.32 3.250000 raised to the power of 10.300000 = 187239.99
In: Computer Science
import java.io.*; import java.util.*; /** * * * * * Lab Project 9: Rock, Paper, Scissors * * @authors *** Replace with your names here *** */ public class lab { // global named constant for random number generator static Random gen = new Random(); // global named constants for game choices static final int ROCK = 1; static final int PAPER = 2; static final int SCISSORS = 3; // global names constants for game outcomes static final int PLAYER1_WINS = 11; static final int PLAYER2_WINS = 12; static final int DRAW = 3; // global named constant for error condition static final int ERROR = -1; /** * 1. Get human player's choice * 2. Get computer player's (random) choice * 3. Check human player's choice * 4. Check computer player's choice * 5. Announce winner */ public static void main(String[] args) { Scanner scan = new Scanner(System.in); PrintStream output = System.out; int player1, player2; // get player 1 input as 1 (rock), 2 (paper or 3 (scissors) output.print("Choose 1 (rock), 2 (paper), or 3 (scissors): "); player1 = scan.nextInt(); /* Lab 9.1 * * *** Add code here to validate that player1 has entered * an integer between 1 and 3 * otherwise, ABORT the program */ // echo human player's choice System.out.print(" You chose "); if (player1 == ROCK) { System.out.println("rock"); } else if (player1 == PAPER) { System.out.println("paper"); } else { System.out.println("scissors"); } // now computer picks one randomly output.println("Now I choose one ..."); /* Lab 9.2 *** Add code to and un-comment the following line so that player2 is set to a random integer between 1 and 3, using the gen Random object, ALREADY DECLARED AS A GLOBAL VARIABLE: */ // player2 = ...; System.out.print(" I choose "); /* Lab 9.3 * * *** Add code here to output the computer's choice * as "rock", "paper" or "scissors" */ /* Lab 9.4 * * *** Add code below to compare player input against * computer's choice and output results: * * if human player chose ROCK: * call rockChoice method with computer choice * output the game's outcome (returned from rockChoice) * otherwise, if human player chose PAPER: * call paperChoice method with computer choice * output the game's outcome (returned from paperChoice) * otherwise, if human player chose SCISSORS: * call scissorcChoice method with computer choice * output the game's outcome (returned from scissorcChoice) */ } // end main /** * Lab 9.5 * * rockChoice(int) -> int * * method consumes the computer player's choice (ROCK, PAPER or SCISSORS), * assuming the human player has chosen ROCK * method produces game outcome (PLAYER1_WINS, PLAYER2_WINS, or DRAW) * * ex1: rockChoice(ROCK) -> DRAW * ex2: rockChoice(PAPER) -> PLAYER2_WINS * ex3: rockChoice(SCISSORS) -> PLAYER1_WINS * ex4: rockChoice(0) -> ERROR * ex5: rockChoice(-1) -> ERROR * ex6: rockChoice(4) -> ERROR * * *** ADD METHOD CODE HERE *** */ /** * Lab 9.6 * * paperChoice(int) -> int * * method consumes the computer player's choice (ROCK, PAPER or SCISSORS), * assuming the human player has chosen PAPER * method produces game outcome (PLAYER1_WINS, PLAYER2_WINS, or DRAW) * * ex1: paperChoice(ROCK) -> PLAYER1_WINS * ex2: paperChoice(PAPER) -> DRAW * ex3: paperChoice(SCISSORS) -> PLAYER2_WINS * ex4: paperChoice(0) -> ERROR * ex5: paperChoice(-1) -> ERROR * ex6: paperChoice(4) -> ERROR * * *** ADD METHOD CODE HERE *** */ /** * Lab 9.7 * * scissorsChoice(int) -> int * * method consumes the computer player's choice (ROCK, PAPER or SCISSORS), * assuming the human player has chosen SCISSORS * method produces game outcome (PLAYER1_WINS, PLAYER2_WINS, or DRAW) * * ex1: scissorsChoice(ROCK) -> PLAYER2_WINS * ex2: scissorsChoice(PAPER) -> PLAYER1_WINS * ex3: scissorsChoice(SCISSORS) -> DRAW * ex4: scissorsChoice(0) -> ERROR * ex5: scissorsChoice(-1) -> ERROR * ex6: scissorsChoice(4) -> ERROR * * *** ADD METHOD CODE HERE *** */ } // end class lab
In: Computer Science
Write a 3 to 5 paragraph response to the question "Why do big companies need an Application Lifecycle Management tool?"
You should focus on the benefits of security-focused configuration management and implementation of access control / controlled disclosure of information about software requirements, designs, source code, executables, etc.
In: Computer Science
Instruction
This task is about using the Java Collections Framework to accomplish some basic textprocessing tasks. These questions involve choosing the right abstraction (Collection, Set, List, Queue, Deque, SortedSet, Map, or SortedMap) to efficiently accomplish the task at hand. The best way to do these is to read the question and then think about what type of Collection is best to use to solve it. There are only a few lines of code you need to write to solve each of them. Unless specified otherwise, sorted order refers to the natural sorted order on Strings, as defined by String.compareTo(s). Part 0 in the assignment is an example specification and solution.
Part0
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class Part0 {
/**
* Read lines one at a time from r. After reading all
lines, output
* all lines to w, outputting duplicate lines only
once. Note: the order
* of the output is unspecified and may have nothing to
do with the order
* that lines appear in r.
* @param r the reader to read from
* @param w the writer to write to
* @throws IOException
*/
public static void doIt(BufferedReader r, PrintWriter
w) throws IOException {
Set<String> s = new HashSet<>();
for (String line = r.readLine(); line != null; line =
r.readLine()) {
s.add(line);
}
for (String text : s) {
w.println(text);
}
}
/**
* The driver. Open a BufferedReader and a PrintWriter,
either from System.in
* and System.out or from filenames specified on the
command line, then call doIt.
* @param args
*/
public static void main(String[] args) {
try {
BufferedReader
r;
PrintWriter
w;
if (args.length
== 0) {
r = new BufferedReader(new
InputStreamReader(System.in));
w = new PrintWriter(System.out);
} else if
(args.length == 1) {
r = new BufferedReader(new
FileReader(args[0]));
w = new PrintWriter(System.out);
} else {
r = new BufferedReader(new
FileReader(args[0]));
w = new PrintWriter(new
FileWriter(args[1]));
}
long start =
System.nanoTime();
doIt(r,
w);
w.flush();
long stop =
System.nanoTime();
System.out.println("Execution time: " + 10e-9 *
(stop-start));
} catch (IOException e) {
System.err.println(e);
System.exit(-1);
}
}
}
Question 6
[5 marks] Read the input one line at a time and output the current line if and only if it is not a suffix of some previous line. For example, if the some line is "0xdeadbeef" and some subsequent line is "beef", then the subsequent line should not be output.
Template code
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Part6 {
/**
* Your code goes here - see Part0 for an example
* @param r the reader to read from
* @param w the writer to write to
* @throws IOException
*/
public static void doIt(BufferedReader r, PrintWriter
w) throws IOException {
// Your code goes here - see Part0
for an example
}
/**
* The driver. Open a BufferedReader and a PrintWriter,
either from System.in
* and System.out or from filenames specified on the
command line, then call doIt.
* @param args
*/
public static void main(String[] args) {
try {
BufferedReader
r;
PrintWriter
w;
if (args.length
== 0) {
r = new BufferedReader(new
InputStreamReader(System.in));
w = new PrintWriter(System.out);
} else if
(args.length == 1) {
r = new BufferedReader(new
FileReader(args[0]));
w = new PrintWriter(System.out);
} else {
r = new BufferedReader(new
FileReader(args[0]));
w = new PrintWriter(new
FileWriter(args[1]));
}
long start =
System.nanoTime();
doIt(r,
w);
w.flush();
long stop =
System.nanoTime();
System.out.println("Execution time: " + 10e-9 *
(stop-start));
} catch (IOException e) {
System.err.println(e);
System.exit(-1);
}
}
}
In: Computer Science
Im asked to edit the C++ code given to me so that the user can enter as many courses as they would like.
I've already built the array to house the courses, but Im a tiny bit stuck on writing the user input to the array every time a new line Is made.
Code:
//CSC 211 Spring 2019
//Program Description:
//
// Originally From:
// CSC 211 Spring 2018
// Dr. Sturm
// This program...
//
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
// outputHtmlTitle
// parameters
// This function...
void outputHtmlTitle(ofstream & fout, string title){
fout << "<!DOCTYPE html>" << endl;
fout << "<body style = \"background-color:yellow;\">" << endl;
fout << "<html>" << endl;
fout << "<title>" << endl;
fout << title << endl;
fout << "</title>" << endl;
}
void outputHtmlFooter(ofstream & fout){
fout << "</body>" << endl;
fout << "</html>" << endl;
}
void outputHtmlList(ostream & fout, string first, string second, string third){
fout << "<ul>" << endl;
fout << "\t<li>" << first << "</li>" << endl;
fout << "\t<li>" << second << "</li>" << endl;
fout << "\t<li>" << third << "</li>" << endl;
fout << "\t</ul>" << endl;
}
int main(int argc, char * *argv){
ofstream htmlFile("myIntro.html");
string title;
string t;
cout << "Please enter the title: ";
getline(cin, title);
outputHtmlTitle(htmlFile, title);
string name;
char courses[50] = {"", "", "", "", "", "", "", "", "", "", ""};
cout << "Please enter your name: ";
getline(cin, name);
htmlFile << "<h2>" << "My name is " << name << "</h2>" << endl;
cout << "Please enter the courses you are taking; one per line" << endl;
for(t = courses[0];t < courses[50];courses[]++) {
cin.getline(courses[t]);
};
htmlFile << "<h3>" << "This semester I am taking: " << "</h3>" << endl;
outputHtmlList(htmlFile, courses[1], course[2], courses[3], courses[4], courses[5], courses[6], courses[7], courses[8]);
outputHtmlFooter(htmlFile);
}
In: Computer Science
List the five top considerations to reduce network congestion and improve network performance.
In: Computer Science
In this project you will implement the DataFrame class along
with the all the methods that are represented in the class
definition. DataFrame is a table with rows and columns – columns
and rows have names associated with them also. For
this project we will assume that all the values that are stored in
the columns and rows are integers.
After you have tested your class, you have to execute the main
program that is also given below.
DataFrame Class
#include
using namespace std;
class DataFrame {
protected:
int** table;
int noRows, noCols;
char** colNames;
char** rowNames;
public:
//Constructors
DataFrame ();
DataFrame (int rows, int cols);
//Output Method
void display();
//Setters
void setRowName(int row, char* name);
void setColName(int col, char* name);
int* operator[] (int i); //get row i;
//Getters
char** getRowNames();
char** getColNames();
int getNumberRows();
int getNumberCols();
DataFrame* getColumns(int* columns, int cLen);
DataFrame* getRows(int* rows, int rLen);
DataFrame* getRowsCols(int* rows, int rLen, int* cols, int
cLen);
//Destructor
~DataFrame();
};
The main function
int main () {
int c, r;
int selectC[3];
int selectR[10];
// Read the dataframe from input
// First line: two numbers seperated by space;
// first number is the number of rows (r) and
// second number is the number of columns (c)
cin >> r >> c;
DataFrame* firstDF = new DataFrame(r,c);
// Second line: strings seperated by a comma (c of them);
representing column names
// Third line: strings seperated by a comma (r of them);
representing row names
// Fourth line and more: c number of integers in each of the r rows
(seperated by)
// a space between integers in the same row.
// TODO: Student completes code for the above comment block to get
them as input
// using the display method, print (in the same format as the
input):
// - the column names of the dataframe
// - the row names of the dataframe
// - the contents of the table in dataframe
// TODO: Student completes code for the above comment block
// Execute the following code
// Read the column numbers that you want to extract
for (int i=0; i < 3; i++)
cin >> selectC[i];
DataFrame* tempColumns = (*firstDF).getColumns(selectC, 3);
(*tempColumns).display();
// Change the row names of select rows
(*tempColumns).setRowName(2, "Jack");
(*tempColumns).setRowName(3, "Peter");
(*tempColumns).display();
// Read the row numbers that you want to extract
for (int i=0; i < 10; i++)
cin >> selectR[i];
DataFrame* tempRows = (*firstDF).getRows(selectR, 10);
(*tempRows).display();
// Change the column names of selected columns
(*tempRows).setColName(2, "Scores");
(*tempRows).setColName(3, "Values");
(*tempRows).display();
// Extract the rows in SelectR and columns in SelectC
DataFrame* tempColsRows = (*firstDF).getRowsCols(selectR, 10,
selectC, 3);
(*tempColsRows).display();
delete tempRows;
delete tempColumns;
delete tempColsRows;
// Sample Code for you and you must execute this
DataFrame* myTable = new DataFrame(5,5);
for (int i =0; i < 5; i++) {
for (int j=0; j < 5; j++) {
(*myTable)[i][j] = i*j;
}
}
(*myTable).display();
delete myTable;
}
In: Computer Science
Summary
In this lab, you use a counter-controlled while loop in a Java program provided for you. When completed, the program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. The data file contains the necessary variable declarations and some output statements.
Instructions
Ensure the file named Multiply.java is open.
Write a counter-controlled while loop that uses the loop control variable to take on the values 0 through 10. Remember to initialize the loop control variable before the program enters the loop.
In the body of the loop, multiply the value of the loop control variable by 2 and by 10. Remember to change the value of the loop control variable in the body of the loop.
Execute the program by clicking Run. Record the output of this program.
// Multiply.java - This program prints the numbers 0 through 10
along
// with these values multiplied by 2 and by 10.
// Input: None.
// Output: Prints the numbers 0 through 10 along with their values
multiplied by 2 and by 10.
public class Multiply
{
public static void main(String args[])
{
String head1 = "Number: ";
String head2 = "Multiplied by 2:
";
String head3 = "Multiplied by 10:
";
int numberCounter; //
Numbers 0 through 10.
int byTen;
// Stores the number multiplied by 10.
int byTwo; // Stores
the number multiplied by 2.
final int NUM_LOOPS = 10; //
Constant used to control loop.
// This is the work done in the
housekeeping() method
System.out.println("0 through 10
multiplied by 2 and by 10" + "\n");
// This is the work done in the
detailLoop() method
// Initialize loop control
variable.
// Write your counter controlled
while loop here
// Multiply by
2
// Multiply by
10
System.out.println(head1 + numberCounter);
System.out.println(head2 + byTwo);
System.out.println(head3 + byTen);
// Next
number.
// This is the work done in the
endOfJob() method
System.exit(0);
} // End of main() method.
} // End of Multiply class.
In: Computer Science
Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the circle, which is calculated as area = pi * radius * radius • getDiameter. Returns the diameter of the circle, which is calculated as diameter = radius * 2 • getCircumference. Returns the circumference of the circle, which is calculated as circumference = 2 * pi * radius Write a program that demonstrates the Circle class by asking the user for the circle’s radius, creating a Circle object, and then reporting the circle’s area, diameter, and circumference.
SAMPLE RUN : ./circle_Non-Interactive
Calling·defeault·constructor:·The·circle's·radius·in·the·default·Circle·Object·is:·0↵
↵
Calling·setRadius(20)·to·change·radius·of·default:↵
The·circle's·radius·in·the·default·Circle·Object·is·Now:·20↵
↵
Creating·Circle·circle2(10):·↵
The·circle2's·radius·in·the·circle2·Object·is:·10↵
↵
The·circle2's·area·is·therefore:·314.159↵
The·circle2's·diameter·is·therefore:·20↵
The·circle2's·circumference·is·therefore:·62.8318↵
In: Computer Science
USE Python 3, please type thanks!
Write a Python 3 program to calculate the Body Mass Index (BMI) of a person if they enter their weight and their height to your program. Check out the formula here:
http://www.freebmicalculator.net/calculate-bmi.php
Your program should first print "Body Mass Index Calculator"
The program will then ask the user if they want to enter Metric Units or English Units.
Using the appropriate formula (see link above) calculate their BMI.
Depending on their BMI show their body type (Underweight, Normal Weight, Overweight or Obese).
For BMI ranges see the following link:
http://www.freebmicalculator.net/healthy-bmi.php
HINT: to find the appropriate body type you might want to study this program:
score = input("Enter score: ") score = int(score) if score >= 80: grade = 'A' elif score >= 70: grade = 'B' elif score >= 55: grade = 'C' elif score >= 50: grade = 'Pass' else: grade = 'Fail' print ("\n\nGrade is: " + grade)
Include in the comments a set of test runs to show that your program is correct.
Double check your results by testing using the same values in your program as in the following online BMI calculator:
http://www.nhlbi.nih.gov/health/educational/lose_wt/BMI/bmicalc.htm
Thank you for your help!!
In: Computer Science
Task 2: Random Number Generator (10 Pts)
Random numbers are usually computed using a formula from discrete mathematics. This type of random number generator is called the linear congruential generator and it is described by the following formula
Xn+1=(aXn+c)modm
where a, c and m are parameters of the generator, with Xn being the previous random number, and Xn+1 being the next random number. Variable X0 is referred to as the seed. Note: this is integer arithmetic, not floating-point arithmetic. Term mod is symbol % in Python.
This algorithm is used extensively throughout the computing world, e.g., the random number generator implemented in the C programming language, and available in the glibc library, has parametric values of
a = 1,103,515,245 c = 12,345 m=231 -1
Numerical random number generators are not random; they are deterministic! Given a seed, the sequence of random numbers that follows will be the same. Such methods are referred to as being pseudo-random, because they seem to behave as randomly generated, but are reproducible given the starting condition.
In practice, one selects different seeds with each application that is run that relies on a random number generator, like for a monte carlo simulation. What I typically do in these cases is to set the seed (first call to the generator) using the current
time stamp supplied by the operating system, expressed as an
integer.
Write a Python function
def randomNbr(rnPrev):
that implements the above algorithm. Here rnPrev is Xn in the above
formula. Then write a script
def runTask2():
that calls this function five successive times, where the returned random number from the prior call becomes the argument rnPrev in the next call to the generator, with the first call having an argument of 543,210. Print these integers out to the command window using the following format:
random number 1 is <computed random number> random number 2 is <computed random number> random number 3 is <computed random number> random number 4 is <computed random number> random number 5 is <computed random number>
where the first call to the random number generator uses 543,210 as rnPrev.
In: Computer Science
Summary
In this lab, you will make additions to a C++ program that is provided. The program is a guessing game. A random number between 1 and 10 is generated in the program. The user enters a number between 1 and 10, trying to guess the correct number.
If the user guesses correctly, the program congratulates the user, and then the loop that controls guessing numbers exits; otherwise, the program asks the user if he or she wants to guess again. If the user enters a "Y", he or she can guess again. If the user enters "N", the loop exits. You can see that the "Y" or an "N" is the sentinel value that controls the loop.
Note that the entire program has been written for you. You need to add code that validates correct input, which is "Y" or "N", when the user is asked if he or she wants to guess a number, and a number in the range of 1 through 10 when the user is asked to guess a number.
Instructions
Ensure the source code file named GuessNumber.cpp is open in the code editor.
Write loops that validate input at all places in the code where the user is asked to provide input. Comments have been included in the code to help you identify where these loops should be written.
Execute the program by clicking the Run button. See if you can guess the randomly generated number. Execute the program several times to see if the random number changes. Also, test the program to verify that incorrect input is handled correctly. On your best attempt, how many guesses did you have to take to guess the correct number?
// GuessNumber.cpp - This program allows a user to guess a
number between 1 and 10.
// Input: User guesses numbers until they get it right
// Output: Tells users if they are right or wrong
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int number; // Number to be guessed
int userNumber; // User's guess
string keepGoing; // Contains a "Y" or "N" determining if the user
wants to continue
// This is the work done in the detailLoop() function
srand((unsigned)time(NULL));
number = (rand() % 10) + 1; // Generate random number
// Prime the loop
cout << "Do you want to guess a number? Enter Y or N:
";
cin >> keepGoing;
// Validate input
// Enter loop if they want to play
while(keepGoing == "Y")
{
// Get user's guess
cout << "I'm thinking of a number. .\n Try to guess by
entering a number between 1 and 10: ";
cin >> userNumber;
// Validate input
// Test to see if the user guessed correctly
if(userNumber == number)
{
keepGoing = "N";
cout << "You are a genius. That's correct!";
}
else
{
cout << "That's not correct. Do you want to guess again?
Enter Y or N: ";
cin >> keepGoing;
// Validate input
}
} // End of while loop
return 0;
} // End of main()
In: Computer Science
Demonstrate knowledge of what a Private Cloud is (Concept of Orchestration, What OpenStack is, and What Elasticity means) & the difference between a private cloud and traditional data center / virtualized environments.
In: Computer Science
Read programs and find out their outputs. Please provide process tree with our answer to get full points.
(a)
#include <unistd.h> #include <stdlib.h> #include
<stdio.h>
int main()
{ for(i=0;i<3;i++)
if(fork()>0) printf(“A\n”); }
(b)
#include <unistd.h> #include <stdlib.h> #include
<stdio.h>
int gVar=0;
int main() {
int lVar=0;
int *p;
p=(int *)malloc(sizeof(int));
int pid=fork(); if(pid>0){
gVar=1;
lVar=1;
*p=1;
printf("%d, %d, %d\n", gVar, lVar, *p);
}else{
gVar=2;
lVar=2;
*p=2;
printf("%d, %d, %d\n", gVar, lVar, *p);
} }
(c) Read the following code and answer the questions below:
#include <unistd.h> #include <stdio.h>
main() {
int i;
for(i=0;i<3;i++) if(i%2==1)
fork(); else{
fork();
fork(); }
}
(1) How many processes are created by the OS when it runs the following program?
(2) Suppose your answer to (1) is n, and let us denote the n processes as P1, P2, ..., Pn, please describe the parent-child relations among the processes.
In: Computer Science
1.If one statement is nested within another statement, as in a loop or recursive call, what is the running time of the two statements when considered as a block?
the running time for the inner statement added to the running time for the outer statement |
||
the running time for the inner statement multiplied by the running time for the outer statement |
||
the running time for the inner statement divided by the running time for the outer statement |
||
the running time for the outer statement divided by the running time for the inner statement |
2. Which of the following is false regarding a recursive algorithm?
It should proceed towards a base case. |
||
Each recursive call places another activation record on the stack. |
||
It will always be more efficient than a corresponding iterative solution. |
||
Each recursive call should operate on a smaller version of the original problem |
3. What will happen if you execute a recursive algorithm that does not have a base case?
The algorithm will immediately fail. |
||
The algorithm will execute, but it will take much longer to terminate than it would if it had a base case. |
||
The algorithm will never terminate. |
||
It can not be said what will happen with only the given information |
4. What is the advantage of using dynamic programming?
Dynamic programming will work with dynamic data instead of static data (i.e., data that do not change). |
||
Dynamic programming allows a recursive algorithm to be used, but prevents the algorithm from solving the same instance of a problem more than once. |
||
Dynamic programming is an iterative, rather than a recursive technique, and thus performs more efficiently. |
||
Dynamic programming is the only way to handle multiple base cases in a recursive problem |
In: Computer Science