#include <stdio.h>
int main(void) {
int input = -1;
double average = 0.0;
/* Use this for your input */
scanf("%d", &input);
/* This is the only output you need */
printf("%.1lf", average);
return 0;
}
Please write a C coding program (make it simple coding) that find the average of sequence integer. when user enter integers, once at a time. Also, If the user enters 0 (zero), the code will calculates the average and then prints it, and then exits.
In: Computer Science
In: Computer Science
I need to create a servlet that takes in an input that will do the following calculations.
In: Computer Science
When you buy a new computer what would you do to harden it
In: Computer Science
Provide two classification scenarios where you can use classification tree models but not logistic regression models. For each problem, identify a target variable and four possible predictor variables.
In: Computer Science
Part II: Programming Questions
NOTE: CODING LANGUAGE IS C#
PQ1. How would you declare the following scalar and non-scalar (vector) variables?
PQ2.
PQ3.
PQ4. The algorithm for checking if a number is a prime is to check if it is divisible by any number less than itself other than 1. (Divisibility implies that if you use the modulus operator, %, the result will be 0). Write a function to check if a number is a prime.
In: Computer Science
Write a C program to implement Jacobi iterative method for sovling a system of linear equations. Use the skeleton code.
skeleton code:
/*
CS288 HOMEWORK 8
Your program will take in two command-line parameters: n and error
command: jacobi 5 0.0001
command: jacobi 10 0.000001
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>
#define N 100
#define MAX_ITER 10000
int jacobi();
void init();
int convergence();
void srand();
void print_vector();
void print_equation();
float a[N][N], b[N];
float x[N], buf[N];
int n;
float error;
int main(int argc, char **argv){
int n_iter; /* number of iterations */
n = atoi(argv[1]);
error = atof(argv[2]);
init(); /* initalize a, x0 and b - DO not change */
n_iter = jacobi();
return 0;
}
int jacobi(){
int i,j,k;
float sum;
// ...
// ...
// ...
return k;
}
// returns 1 if converged else 0
int convergence(int iter){
int i,j,k,flag=1;
// ...
// ...
// ...
return flag;
}
// Try not to change this. Use it as is.
void init(char **argv){
int i,j,k,flag=0;
float sum;
int seed = time(0) % 100; /* seconds since 1/1/1970 */
srand(seed);
for (i=0;i<n;i++) {
for (j=0;j<n;j++) {
a[i][j] = rand() & 0x7;
if (rand() & 0x1) a[i][j] = -a[i][j];
}
sum = 0;
for (j=0;j<n;j++) if(i!=j) sum = sum + abs(a[i][j]);
if (a[i][i] < sum) a[i][i] = sum + a[i][i];
}
for (i=0;i<n;i++) x[i]=1;
srand(seed);
for (i=0;i<n;i++){
b[i]=rand() & 0x7;
if (rand() & 0x1) b[i] = -b[i];
}
print_equation();
}
void print_equation(){
int i,j;
printf("A*x=b\n");
for (i=0;i<n;i++) {
for (j=0;j<n;j++) printf("%2d ",(int)(a[i][j]));
printf(" * x%d = %d\n",i,(int)(b[i]));
}
printf("\n");
}
void print_vector(float *l){
int i;
for (i=0; i<n; i++) printf("%.6f ",l[i]);
printf("\n");
}
// end of fileIn: Computer Science
In: Computer Science
1. Create a base class called Vehicle that has the manufacturer’s name (type String), number of cylinders in the engine (type int). Then create a class called Truck that is derived from Vehicle and has additional properties: the load capacity in tons (type double) and towing capacity in tons (type double).
Add the following methods to the Vehicle class:
Add the following methods to the Truck class:
Write a driver program that tests all your methods. Create at least two objects of truck class, and two objects of vehicle class.
(JAVA)
In: Computer Science
Design an application that focuses on decreasing the acceptability of and engagement in high-risk drinking among college students. The application should include:
1) files
2) arrays
3) methods
coding language c++
In: Computer Science
Need this in C#
Write a simple lottery program which can do the following:
1. asks the user to provide an integer value from 1 to 5
2. generates one random integer number from 1 to 5
3. display “You lost $1” if the two numbers are different, and display “You won $5” otherwise.the program asks if the user wants to continue playing the lottery.
If yes, the program repeats steps 1-3. If no, the program terminates.
In: Computer Science
Consider the following code:
values = [2, 5, 8, 12, 15]
values2 = {v % 3 for v in values}
What will be the length of values2?
Consider the following code:
values = ["moose", "giraffe", "antelope", "tortoise", "chinchilla"] values2 = [len(s) for s in values if "a" in s]
What will be the value of values2[1]?
Consider the following code:
numbers = [1, 2, 7, 9, 13] numbers2 = [n // 2 for n in numbers]
What will be the value of numbers2[2]?
In: Computer Science
In: Computer Science
Im trying to create a function in C where it takes an array and size and returns the largest absolute value in the array (either negative or positive) using only stdio.h. Any help would be greatly appreciated!
Ex: if the array is { -2.5, -10.1, 5.2, 7.0}, it should return -10.1
Ex: if the array is {5.1, 2.3, 4.9, 1.0}, it should return 5.1.
double getMaxAbsolute(double array[], int size)
{
double max = array[0];
double abs[size];
for (int i = 0; i < size; i++) {
if ( array[i] >=
0){
abs[i] = array[i];
}
else if (abs[i] <
0){
abs[i] = -
array[i];
}
if (abs[i] > max)
{
max = array[i];
}
}
return max;
}
In: Computer Science
(The Colorable interface) Design an interface named Colorable with a void method named howToColor(). Every class of a colorable object must implement the Colorable interface. Design a class named Square that extends GeometricObjectand implements Colorable. Design another class named Trianglethat extends GeometricObjectand implements Colorable. Implement howToColor inSquareto display the message Color all four sides. ImplementhowToColor inTriangleto display the message Color all three sides.
Draw a UML diagram that involves Colorable, Square, Triangle, and GeometricObject.
Write a test program that creates an array of five GeometricObjects. For each object in the array, display its area and invoke its howToColor method if it is colorable.
interface Colorable
{
public void howToColor();
}
abstract class GeometricObject implements Colorable// abstract
base class
{
//abstract methods
abstract public double calculateArea();
abstract public double calculatePerimeter();
abstract public String toString();
}
class Triangle extends GeometricObject
{
private double side1,side2,side3;
public Triangle()
{
side1 = 1.0;
side2 = 1.0;
side3 = 1.0;
}
public Triangle(double side1,double side2,double side3)
{
if ((side1 >= side2 + side3) || (side2 >= side1 +
side3)||(side3 >= side2 + side1))
{
this.side1 = 1.0;
this.side2 = 1.0;
this.side3 = 1.0;
}
else
{
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
}
}
//The accessor(getters and setters) methods for all three data
fields.
public void setSide1(double side1)
{
this.side1 = side1;
}
public double getSide1()
{
return side1;
}
public void setSide2(double side1)
{
this.side2 = side2;
}
public double getSide2()
{
return side2;
}
public void setSide3(double side3)
{
this.side3 = side3;
}
public double getSide3()
{
return side3;
}
//A method named getArea() that returns the area of this
triangle.
public double calculateArea()
{
double s = (side1 +side2+side3)/2;
double area = Math.sqrt(s*(s-side1)*(s-side2)*(s-side3));
return area;
}
//A method named getPerimeter() that returns the perimeter of this
triangle.
public double calculatePerimeter()
{
return(side1+side2+side3);
}
//A method named toString() that returns a string description for
the triangle.
public String toString()
{
return "Triangle side1 : "+side1 +" side2 : "+side2+" side3 :
"+side3 +" Area : "+calculateArea()+" Perimeter :
"+calculatePerimeter();
}
public void howToColor()
{
System.out.println("Color all three sides");
}
}
class Square extends GeometricObject
{
private double side;
public Square(double side)
{
this.side = side;
}
public String toString()
{
return "Square side : "+side+" Area : "+calculateArea()+" Perimeter
: "+calculatePerimeter();
}
public void howToColor()
{
System.out.println("Color all four sides");
}
public double calculateArea()
{
return side*side;
}
//A method named getPerimeter() that returns the perimeter of this
triangle.
public double calculatePerimeter()
{
return 4*side;
}
}
class TestGeometricObject
{
public static void main (String[] args)
{
GeometricObject[] f = new GeometricObject[2];
f[0] = new Square(20);
f[1] = new Triangle(6.5, 14.9, 11.3);
for(int i=0;i<f.length;i++)
{
System.out.println(f[i]);
f[i].howToColor();
}
I get an error do not know why
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at test.TestGeometricObject.main(TestGeometricObject.java:4)
In: Computer Science