In C++ Complete the template program.
ADD to your c++ program as a comment
the PARTIAL output from executing your
program - Only copy the last 6 lines of output.
There is no input data for this problem.
// Find Pythagorean triples using brute force computing.
#include <iostream>
using std::cout;
using std::endl;
int main()
{
int count = 0; // number of triples found
long int hypotenuseSquared; // hypotenuse squared
long int sidesSquared; // sum of squares of sides
cout << "Side 1\tSide 2\tSide3" << endl;
// side1 values range from 1 to 500
/* Write a for header for side1 */
{
// side2 values range from current side1 to 500
/* Write a for header for side2 */
{
// hypotenuse values range from current side2 to 500
/* Write a for header for hypotenuse */
{
// calculate square of hypotenuse value
/* Write a statement to calculate hypotenuseSquared */
// calculate sum of squares of sides
/* Write a statement to calculate the sum of the sides Squared
*/
// if (hypotenuse)^2 = (side1)^2 + (side2)^2,
// Pythagorean triple
if ( hypotenuseSquared == sidesSquared )
{
// display triple
cout << side1 << '\t' << side2 << '\t' << hypotenuse << '\n';
count++; // update count
} // end if
} // end for
} // end for
} // end for
// display total number of triples found
cout << "A total of " << count << " triples were found." << endl;
return 0; // indicate successful termination
} // end main
In: Computer Science
Qa: For fitness proportional, ranking and tournament selection
separately, discuss
a) convergence speed, is it problem-specific or not?
b) can convergence speed be controlled and how?
Qb: What you possibly lose by increasing convergence speed?
In: Computer Science
Java.
You are creating a 'virtual pet' program. The pet object will have a number of attributes, representing the state of the pet. You will need to create some entity to represent attributes in general, and you will also need to create some specific attributes. You will then create a generic pet class (or interface) which has these specific attributes. Finally you will make at least one subclass of the pet class which will be a specific type of pet, and at least one instance of that class.
Attributes
An attribute is a characteristic of a pet. Each attribute is
essentially a list of values. For example, a hunger attribute may
have values from "famished" through "content" to "bloated." There
should be some way to check the value of the attribute, as well as
to increase and decrease the value. Note that you will be expected
to create some sort of abstract data type (ADT) to represent the
attribute. You are not yet building SPECIFIC attributes (like
hunger or happiness) but a type that represents the common
characteristics of all attributes. You might use an interface or an
abstract class to generate your abstraction, but plan it first as
an abstract data type.
Specific Attributes
Once you have created a generic attribute class, make some
subclasses to represent the specific attributes you want your pets
to have. If you designed the ADT well, creating specific subclasses
should be quite easy. The main method of the specific classes
should test the main functionality of the class.
Making your abstract pet
Now create a pet class that uses the attributes you have generated.
This class is also abstract, as it represents just a type of pet.
It will include attributes as data members, and it may also have
other characteristics. You may also add methods that indicate
actions the user can take with the pet, including things like feed
and play (which may affect attributes) and perhaps other activities
like rename (which might change another data member of the pet) and
sleep (which might indicate the passage of time.)
Build a specific pet class
Finally you should be able to build a specific type of pet (like a
lizard or a unicorn) that inherits from the pet class. This should
begin (of course) with characteristics derived from the abstract
pet, but you could then add new attributes or behaviors specific to
your type of pet.
The main method of this pet class should instantiate an instance of the pet and indicate all the things it can do.
Create an interface for interacting with the pet.
Build some type of tool for interacting with the pet. At minimum
this should allow the user to create a pet, interact with it in the
ways you have defined, save its current status for future play
(using object serialization) and load a previously saved pet.
In: Computer Science
Write a function forward_eval that evaluates the interpolating polynomial using Newton’s Forward Difference table. The function prototype and descriptive comments have been provided:
function y = forward_eval(X, T, x)
%FORWARD_EVAL Evaluate Newton's forward difference form of the
%interpolating polynomial
% y = FORWARD_EVAL(X, T, x) returns y = Pn(x), where Pn is the
% interpolating polynomial constructed using the abscissas X and % forward difference table T.
In: Computer Science
How would I add a quickSort function to the below C++ code to sort the randomly generated numbers?
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int i;
int array[10];
int odd;
int Max;
int counter = 0;
int main()
{
cout << "The 10 random elements are: ";
cout << endl;
srand ( time(0) );
for (int j = 0; j < 99; j++)
{
i = rand() % 100;
if (i != i - 1)
array[j] = i;
else
{
i = rand() % 100;
array[j] = i;
}
}
for (int k = 0; k < 10 ; k++)
{
cout << array[k] << "\n";
}
cout << endl;
return 0;
}In: Computer Science
Try to make it as simple as you can and explain as much as it needed.
Ans:
Ans:
Ans:
Ans:
Ans:
In: Computer Science
Write a C++ or Java application to create BOTH Stack & Queue data structures.
The application also creates a "DisplayStackElement" and "DisplayQueueElement" routine. The application must be menu driven (with an option to terminate the application) and provide the following features.
Allow insertion of a "Circle" object/structure in the Stack data structures.
The Circle contains a "radius" data member.
The Circle also uses functions/methods "setRadius", "getRadius" and calculateArea (returns a double data type).
Allow insertion of a "Circle" object/structure in the Queue data structures.
Allow display of an element from Stack data structure by Invoking a method/function "DisplayStackElement" (uses the "Pop" method)
Allow display of elements from Queue data structure by Invoking a method/function "DisplayQueueElement" (uses "DeQueue" method).
Allow for deletion of the Stack Allow for deletion of the Queue
In: Computer Science
The Sum and The Average
In C++,
Write a program that reads in 10 integer numbers. Your program should do the following things:
Use a Do statement
Determine the number positive or negative
Count the numbers of positive numbers, and negative
Outputs the sum of:
all the numbers greater than zero
all the numbers less than zero (which will be a negative number or zero)
all the numbers
Calculate the average of all the numbers.
The user enters the ten numbers just once each and the user can
enter them in any order. Your program should not ask the user to
enter the positive numbers and the negative numbers separately
In: Computer Science
Try to make it as simple as you can and explain as much as it needed.
Ans:
Ans:
Ans:
Ans:
Ans:
In: Computer Science
Try to make it as simple as you can and explain as much as it needed.
Ans:
Ans:
Ans:
Ans:
Ans:
In: Computer Science
package edu.depaul.triangle;
import java.util.Scanner;
/**
* A class to classify a set of side lengths as one of the 3 types
* of triangle: equilateral, isosceles, or scalene.
* If classification is not possible it emits an error message
*/
public class Triangle {
/**
* Define as private so that it is not a valid
* choice.
*/
private Triangle() {}
public Triangle(String[] args) {
//
// TODO: keep this simple. Constructors should not do a lot of work
//
}
// TODO: Add methods to validate input, and classify the triangle (if possible) here
private static String[] getArgs(Scanner s) {
System.out.println("press Enter by itself to quit");
System.out.println("enter 3 integers separated by space.");
String args = s.nextLine();
return args.split(" ");
}
public static void main(String[] a) {
try (Scanner scanner = new Scanner(System.in)) {
String[] args = getArgs(scanner);
// Loop until the user enters an empty line
while(args[0].length() !=0) {
//
// TODO: create a new Triangle here and call it
//
args = getArgs(scanner);
}
System.out.println("Done");
}
}
Write a Java program to determine types of triangles. The program reads 3 values from the standard input. The values represent the lengths of the sides of a triangle. The program prints a message to the standard output that indicates whether the triangle represented by the input is • an equilateral (all 3 sides are equal), or • an isosceles (exactly 2 of the 3 sides are equal), or • a scalene (all 3 sides are of different lengths) Expected behavior: a. The user enters 3 values at a prompt and presses return b. The values must be converted to integers. If they cannot be converted, the system displays an error. c. The valid values for these integers are values from 1 to and including 300. Any other integers should cause an error to be shown to the user. d. The values are delimited with spaces e. The system evaluates the results, shows either a triangle type or an error, then prompts for input again. f. When the user enters a blank line followed by return, the program ends. g. An error is shown whenever the user’s input cannot be interpreted as a triangle or when the handling of the input results in exception.
In: Computer Science
Write a C++ program to ask the user to enter the shape type: square, sphere or circle and the appropriate dimensions of the shape.. The program should output the following information about the shape:
a.for a square. it output the area and perimeter.
b. for a sphere, it outputs the area.
c. fir a circle, it outputs the volume.
if the user input anything else, your program should output: "the program does not recognize this shape". Use const whenever it is appropriate (use the nested if)
area of sphere is 4*PI*r^2
area of circle is Pi*r^2 (Pi=3.1416)
In: Computer Science
Write a C program to create a series of processes, as shown below in the diagram.
P |------ ---- > c1 |------------>c2
|------- ------>c3 ---------->c4
In other words, the parent process p creates process c1, c1 creates c2 and c3, and c3 creates c4.
A sample run of the program shows
Your program should output something similar to what is shown above. You could optionally use wait/waitpid/sleep/exit in your program.
Comment your code to show where you created p, c1, c2, c3, c4, etc.
In: Computer Science
1.For Python Which statement(s) are true regarding private class variables?
private variables can be accessible inside the class.
private variables can be accessible outside the class.
private variable values can be changed directly outside of the class
private variables can be changed outside the class through set methods.
2.
In the following code,
def A:
def __init__(self):
__a = 1
self.__b = 1
self.c = 1
__d__ = 1
# Other methods omitted
Which of the following is a private data field?
Group of answer choices
__a
__b
c
__d__
3.
Analyze the following code and choose the more accurate
statement.
class A:
def __init__(self, s):
self.s =
s
def print(self):
print(s)
a = A("Welcome")
a.print()
Group of answer choices
The program has an error because class A does not have a constructor.
The program has an error because class A should have a print method with signature print(self, s).
The program has an error because class A should have a print method with signature print(s).
The program would run if you change print(s) to print(self.s).
4.
Which of the following statement is most accurate?
Group of answer choices
A reference variable is an object.
An object is a reference type variable
An object may contain other objects.
An object may contain the references of other objects.
5.
Which special method returns a string representation of the object?
Group of answer choices
__init__ method
print method
__str__ method
constructor
6.
Class design should include ________
Group of answer choices
fields
constructor
accessor and mutator methods
other useful methods
All of the above
7.
What is max("Programming is fun")?
Group of answer choices
P
r
blank space character
u
8.
What is "Programming is fun"[1:3]?
Group of answer choices
Pr
Pro
ro
rog
In: Computer Science
Replace <missing value> and <missing code> with your answers. Your code should compute the factorial of n. For example, if n = 5, your code should compute the following 5 * 4 * 3 * 2 * 1 (which is 120).
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int factorial = <missing value>;
<missing code>
System.out.println("factorial = " + factorial);
In: Computer Science