2 Write a Java program called Pattern that prints an 8-by-8 checker box pattern using an if loop.
In: Computer Science
Write a Java program called Decision that includes a while loop to prompt the user to enter 5 marks using the JOptionPane statement and a System. Out statement to output a message inside the loop highlighting a pass mark >= 50 and <= 100. Any other mark will output a messaging stating it’s a fail.
In: Computer Science
PLEASE USE PYTHON CODE
7. determine the two roots of sinx+3cosx-2 =0 that lie in the interval (-2,2). use the Newton- Raphson method and solve by the secant formula
In: Computer Science
Translate the following C program to Pep/9 assembly language:
#include <stdio.h>
char toLower(char ch)
{
if (ch >= 'A' && ch <= 'Z' )
ch += 'a' - 'A';
return ch;
}
int main()
{
char ch, conversion;
printf("Enter an uppercase letter: ");
scanf("%c", &ch);
conversion = toLower(ch);
printf("\nLetter after conversion: %c\n\n", conversion);
return 0;
}
In: Computer Science
4 Write an algorithm to settle the following questions:
Accept a starting balance (For example :A bank account starts out with $10,000) Accept an Interest rate (For example: 6 percent per year is 0.005 percent per month).
Accept an amount to withdraw every month (For example: Every month, $500 is withdrawn to meet college expenses.)
After how many years is the account depleted? (You are to loop and find out how many months this will take) (For example: Suppose the values ($10,000, 6 percent, $500) were user selectable, then how many months would it take to deplete the account?)
Are there values for which the algorithm you developed would not terminate? (For example if the interest calculated for each month exceeds the withdrawal every month). If so, change the algorithm to make sure it always terminates.
Don't write the program, just write it in pseudo
English.
In: Computer Science
Software Testing Question
Program P2 CFG.
a) Identify the basic blocks for the following program P2 written in pseudo-code.
b) Draw the control flow graph.
Program P2
1) integer A, B;
2) input (A);
3) B = 1;
4) while (int i=1; i<=A; i++)
5) {
6) B = B * i;
7) if (B>13)
8) B = B / 2;
9) else 1
0) B = B * 2;
11) }
12) output (A,B);
13) end;
In: Computer Science
String Input Console Application and Program Analysis
Demonstrate an understanding of basic C++ programming concepts by completing the following:
In: Computer Science
Please, write code in c++. Using iostream and cstring library
Use pointers!
You given a text.Your task is to write a function that will find
the longest sequence of digits inside.
Note that the output have to be presened just like in sample.
Note. The program have to use pointer.
Input:
First line contains one line that is not longer than 1000.
Output:
The longest sequence of numbers.All numbers are positive and
integers.
Samples:
№ | INPUT | OUTPUT |
1 | This is the longest - 10001 number | 10 001 |
2 | 101 fdvnjfkv njfkvn fjkvn jffdvfdvfd2010 | 2 010 |
2 | 1a11 | 11 |
In: Computer Science
IP address: 158.234.28.72 Subnet Mask: 255.248.0.0 Find Network Address and Broadcast address. Provide all necessary steps.
In: Computer Science
Write a C program that runs on ocelot for a mini calculator
using only the command line options. You must use getopt to parse
the command line.
Usage: minicalc [-a num] [-d num] [-m num] [-s num] [-e]
value
• The variable value is the starting value.
• Value should be validated to be an integer between 1 and 99.
Error message and usage shown if not.
• -a adds num to value.
• -d divides value by num.
• -m multiplies value by num.
• -s subtracts num from value.
• -e squares value. (Note: no num is needed.)
• Output should have exactly 2 decimal places no matter what the
starting values are.
• If –e is included, it is executed first.
• Use standard order of operations for all operations.
Code should be nicely indented and commented. Create a simple
Makefile to compile your program into an executable called
minicalc.The Makefile should be called Makefile with no extension.
I should be able to type make at the command line to compile your
program.
In: Computer Science
Working with Files in C++.
Create the following program called payroll.cpp. Note that the file you read must be created before you run this program. The output file will be created automatically by the program. You can save the input file in the same directory as your payroll.cpp file by using Add New Item, Text File.
// File: Payroll.cpp
// Purpose: Read data from a file and write out a payroll
// Programmer: (your name and section)
#include <cstdlib> // for the definition of EXIT_FAILURE
#include <fstream> // required for external file streams
#include <iostream> // required for cin cout
using namespace std;
int main ()
{
ifstream ins; // associates ins as an input stream
ofstream outs; // associates outs as an output stream
int id; // id for employee
double hours, rate; // hours and rate worked
double pay; // pay calculated
double total_pay; // grand total of pay
// Open input and output file, exit on any error
ins.open ("em_in.txt"); // ins connects to file "em_in.txt"
if (ins.fail ())
{
cout << "*** ERROR: Cannot open input file. " << endl;
getchar(); // hold the screen
return EXIT_FAILURE;
} // end if
outs.open ("em_out.txt"); // outs connects to file "em_out.txt"
if (outs.fail ())
{
cout << "*** ERROR: Cannot open output file." << endl;
getchar();
return EXIT_FAILURE;
} // end if
// Set total_pay to 0
total_pay = 0;
ins >> id; // get first id from file
// Do the payroll while the id number is not the sentinel value
while (id != 0)
{
ins >> hours >> rate;
pay = hours * rate;
total_pay += pay;
outs << "For employee " << id << endl;
outs << "The pay is " << pay << " for " << hours
<< " hours worked at " << rate << " rate of pay" << endl << endl;
ins >> id;
} // end while
// Display a message on the screen
cout << "Employee processing finished" << endl;
cout << "Grand total paid out is " << total_pay << endl;
ins.close(); // close input file stream
outs.close(); // close output file stream
return 0;
}
Create the input file:
Inside C++ go to File Add New Item and then Text to create a text file.
Type in the data below
In the same directory as your .cpp file for Payroll.cpp click Files and Save As em_in.txt
1234
35 10.5
3456
40 20.5
0
solution should show :
-the output file
-the input file
-the screen output
-the source program
In: Computer Science
For this problem, complete the function stub to simulate the following random variable: Suppose we have a (possibly) unfair coin where the probability of Head is ? and we flip this coin ? times. Let X = "the number of heads showing."
Demonstrate your solution by generating 105 random variates for the parameters shown and displaying them using show_distribution(...).
STARTER CODE:
# First, create a function which simulates the coin, where
# you return 1 with probability p and 0 with probability 1-p.
N = 10
p = 0.25
num_trials = 10**5
def coinFlip(p):
return 0 # Just to get it to compile
def coinFlips(N,p):
return 0 # Just to get it to compile
print("Demonstration:")
seed(0)
In: Computer Science
-----xxxxx-------Could you please use java language. thank you. :::::: XXXX:::::::::::
Implement a recursive reverse sorting algorithm. The following requirements should meet:
a The program shall graphically prompt the user for a file.
bThe program shall read the selected file which will contain 1 integer per line.
c. The program shall sort the values it reads from the file from largest to smallest.
d.The program shall write the values to an output file from largest to smallest in the same directory as the input file.
eThe program shall write 1 integer per line in the output file.
f.The program shall use a recursive algorithm to sort the values
This assignment should be based on:
i) Functionality - Does the program meet the requirements?
ii) Style - Do you have comments and well-written code?
iii) Design - Were good design principles used in the construction of the program?
iv) Additional Elements - Error handling, unit tests, input checking, etc.
In: Computer Science
Requirements: You are to write a class called Point – this will represent a geometric point in a Cartesian plane (but x and y should be ints). Point should have the following:
Data:
Constructors:
throw new IllegalArgumentException(<”your meaningful String here”>);
If it is OK, the it should initialize the data (of the new instance being created) to be the same as the Point that was received.
Methods:
public class Point implements PointInterface
When your Point.java compiles, Java will expect all methods in the interface to be implemented and will give a compiler error if they are missing. The compiler error will read “class Point is not abstract and does not implement method ”.
You can actually copy the PointInterface methods definitions into your Point class so it will have the comments and the method headers. If you do this, be sure to take out the ; in the method headers or you will get a “missing method body” syntax error when compiling…
public interface PointInterface
{
// toString
// returns a String representing this instance in the form (x,y)
(WITHOUT a space after the ,)
public String toString();
// distanceTo
// throws a new IllegalArgumentException(
if null is received
// returns the distance from this Point to the Point that was
received
// NOTE: there is a static method in the Math class called hypot
can be useful for this method
public double distanceTo(Point otherPoint);
//equals - returns true if it is equal to what is received (as an Object)
public boolean equals(Object obj);
// inQuadrant
// returns true if this Point is in the quadrant specified
// throws a new IllegalArgumentException if the quadrant is
out of range (not 1-4)
public boolean inQuadrant(int quadrant);
// translate
// changes this Point's x and y value by the what is received (thus
"translating" it)
// returns nothing
public void translate(int xMove, int yMove);
// onXAxis
// returns true if this Point is on the x-axis
public boolean onXAxis();
// onYAxis
// returns true if this Point is to the on the y-axis
public boolean onYAxis();
//=============================================
// The method definitions below are commented out and
// do NOT have to be implemented
// //===========================================
// halfwayTo
// throws a new IllegalArgumentException(
if null is received
// returns a new Point which is halfway to the Point that is
received
//public Point halfwayTo(Point another);
// slopeTo
// throws a new IllegalArgumentException(
if null is received
// returns the slope between this Point and the one that is
received.
// since the slope is (changeInY/changeInX), then first check to see if
changeInX is 0
// if so, then return Double.POSITIVE_INFINITY; (since the
denominator is 0)
//public double slopeTo(Point anotherPoint)
}
In: Computer Science
Q1: Constraint:
Use concept of dynamic allocation for implementation
Statement:
In a class there are N students. All of them have appeared for the
test. The teacher evaluated
the test and noted marks according to their roll numbers. Marks of
each students has to be incremented
by 5. Print list of marks of students before and after
increment.
In: Computer Science