Questions
Im trying to create a function in C where it takes an array and size and...

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...

(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

Given two integers N1 and N2, display the given box number pattern of '1's with a...

Given two integers N1 and N2, display the given box number pattern of '1's with a '0' at the center (Square number patterns).

Input:
5

5

    where:

  • First line represents the value of N1( number of rows ).
  • Second line represents the value of N2( number of columns ).

In: Computer Science

question 1) Differentiate between distance vector routing and link state routing. Your answer should describe the...

question 1) Differentiate between distance vector routing and link state routing. Your answer should describe the key features of the two utilising some real time examples and where possible supported by diagrams. [5 Marks]
question 2) Compare and contrast Address Resolution Protocol (ARP) & Network Discovery Protocol (NDP). What is the major difference between ARP and NDP? [5 Marks]
question 3) Explain the purpose of QoS on a TCP/IP network. Define the basic purpose of IP precedence, TOS, Diffserv, and ECN functionality.

In: Computer Science

Why are naming conventions important in designing a database?

Why are naming conventions important in designing a database?

In: Computer Science

The answer should be in JAVA. You will design and implement two classes to support a...

The answer should be in JAVA.

You will design and implement two classes to support a client program, RockPaperScissorsGame.java, to simulate Rock-Paper-Scissors game.

Read and understand the client program to find out the requirements for the HandShape and Player classes.

The rules of the Rock-Paper-Scissors game are:

    Scissors✌️ beats Paper✋ that beats Rock✊ that beats Scissors✌️

Additionally, to simplify the game logic (and complexify a little bit the HandSahpe class) , two players cannot show the same hand shape.

The followings are some sample runs:

$java RockPaperScissorsGame
Alice shows Paper
Bob shows Scissors
Bob wins!


$java RockPaperScissorsGame
Alice shows Paper
Bob shows Rock
Alice wins!


$java RockPaperScissorsGame
Alice shows Scissors
Bob shows Rock
Bob wins!

RockPaperScissorsGame.java

public class RockPaperScissorsGame {

        public static void main(String[] args) {
                
                String[] handShapeName = {"Rock", "Paper", "Scissors"};
                
                HandShape handShape = new HandShape();
                
                Player player1 = new Player("Alice");
                Player player2 = new Player("Bob");

                System.out.println(player1.getName() + " shows " + handShapeName[player1.showHand(handShape)]);
                System.out.println(player2.getName() + " shows " + handShapeName[player2.showHand(handShape)]);         
                
                System.out.println(player1.findWinner(player2) + "  wins!");
        }
}

In: Computer Science

question 1) what is ICMP and at which layer of OSI reference model does it work?...

question 1) what is ICMP and at which layer of OSI reference model does it work? explain the process at Path Maximum Transmission Unit discovering utillising ICMP?
question 2) Give some advantages and disadvantages of :
a. Stateless Address Auto configuration in IPv6 (2.5 marks)
b. Stateful Address Auto configuration in IPv6 (2.5 marks)
question 3) . (a) What is the purpose of extension headers in IPv6? List the names of at least two extension headers used in IPv6. [2.5 Marks]
   (b) How are jumbograms used in the IPv6 environment? (2.5 marks)
question 4)  Compare and contrast the OSI reference model with the TCP/IP networking model. Which one do you think is more useful when working with and describing networks and why? [5 Marks]
question 5) In the context of securing TCP/IP environment, provide a brief discussion on typical TCP/IP attacks, exploits and break-ins [5 Marks]
question 6) Explain the three ways, route entries are placed in a routing table ?

In: Computer Science

Draw a flowchart that asks the user to enter an array of random numbers, then sorts...

Draw a flowchart that asks the user to enter an array of random numbers, then sorts the numbers (ascending order), then prints the new array, after that asks the user for two new numbers and adds them to the same array and keeps the array organization.

In: Computer Science

Write a program that does the following things: in C++ 1 ) ask the user for...

Write a program that does the following things: in C++

1 ) ask the user for 2 primary colors (red, blue, yellow) [should be in main]

2 ) determine the secondary color the 2 primarily colors make [should be in newColor function]

red + blue = purple

red + yellow = orange

blue + yellow = green

3 ) Print the following message

<color1> and <color2> makes <color3>


In: Computer Science

Q2.1 [RSA Signature Scheme] (Marks: 2) Suppose Bob (the sender) wants to send a message m=123456...

Q2.1 [RSA Signature Scheme] (Marks: 2) Suppose Bob (the sender) wants to send a message m=123456 to Alice (the receiver). However, before sending the message he would like to sign the message. When Alice receives the signed message, she would like to verify that the message is indeed from Bob. To facilitate signing and verification Bob generates public and private keys using RSA encryption algorithm and sends the public key to Alice. Bob uses parameter p = 5563 and q = 3821, and chooses a suitable public key parameter e=9623. How would Bob sign message m=123456? How would Alice verify the signed message from Bob? [Hints: Refer to the lecture-6 and tutorial-6. You do not need to generate hash of the message m.]

Q2.2 [ElGamal Signature Scheme] (Marks: 2) Suppose Bob (the sender) wants to send a message m=4567 to Alice (the receiver). However, before sending the message he would like sign the message. When Alice receives the signed message, she would like to verify that the message is indeed from Bob. To facilitate signing and verification Bob generates public and private keys using ElGamal encryption algorithm and sends the public key to Alice. Bob chooses p= 7331, g=3411, x=41. How would Bob sign message m=4567? How would Alice verify the signed message from Bob? [Hints: Refer to the lecture-6 and tutorial-6. You do not need to generate hash of the message m.]

In: Computer Science

Hi there, I am making a program using trees, and recursion to compute prefix, infix, and...

Hi there, I am making a program using trees, and recursion to compute prefix, infix, and postfix expressions. I am struggling with placing parentheses to separate the infix numbers, and with how I should write my evaluation. (In java) if someone could please help me out. I included my evaluation class, and my current output.

public class Evaluation {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a prefix expression:");
        Node root = buildTree(sc);
        System.out.println("Infix expression:");
        infix(root);
        System.out.println("\nprefix expression:");
        prefix(root);
        System.out.println("\npostfix expression:");
        postfix(root);
        evaluate(root);
    }

    static Node buildTree(Scanner sc) {
        String input = sc.next();
        if (!input.contains("+") && !input.contains("-") && !input.contains("*") && !input.contains("/")) {
            return new Node(input);
        } else {
            Node right = buildTree(sc);
            Node left = buildTree(sc);
            return new Node(input, left, right);
        }
    }

    static void infix(Node node) {
        if (node != null) {
            infix(node.right);
            System.out.print(node.value + " ");
            infix(node.left);
        }
    }

    static void prefix(Node node) {
        if (node != null) {
            System.out.print(node.value + " ");
            prefix(node.right);
            prefix(node.left);

        }
    }

    static void postfix(Node node) {
        if (node != null) {
            postfix(node.right);
            postfix(node.left);
            System.out.print(node.value + " ");
        }

        static int evaluate (Node node){


                }
            }
        }
    }

Enter a prefix expression:
- + 10 * 2 8 3
Infix expression:
10 + 2 * 8 - 3 ------> should be ( ( 10 + ( 2 * 8 ) ) - 3 )
prefix expression:
- + 10 * 2 8 3
postfix expression:
10 2 8 * + 3 -
Process finished with exit code 0

In: Computer Science

I need to make an application that calculates the occupancy rate for a hotel with eight...

I need to make an application that calculates the occupancy rate for a hotel with eight floors. The user will be asked how many rooms are occupied on each floor. The program will iterate for each floor. Users must enter numbers and the rooms occupied on each floor cannot exceed 30. The occupancy rate is the number of occupied rooms/ unnoccupied.  The application also needs to display the occupancy for each individual floor aswell. Each floor has a maximum of 30 rooms. There are 240 rooms in total. The application doesn't need any fancy graphics just simple text. I'm really lost where to start. I know I need to use for loops and while but I'm not sure how to apply it. Can I get some help?

Python

The code needs to be in Python

In: Computer Science

11.2 Exercise 2: You are required to write a program that creates a float array of...

11.2 Exercise 2:

You are required to write a program that creates a float array of size 90. Using a for loop, populate the array element whose index is the value of the loop variable with the value of the loop variable (e.g. array[0] = 0, array[1] = 1 etc.) Using a second loop display the loop index and the value in the array - each pair of numbers is to be displayed on a new line.

Hi, could you please hlp me with this simple c programming problem? I'm not sure what the part in bold is asking. Below is my code for the problem so far.

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
// Declare variables
int Array[90];
int i;

// Loop from 0 to 90 inclusive
for ( i = 0 ; i < 91 ; i++ )
{
Array[i] = i;
printf ("Array number %d contains value %d\n", i, Array[i]);
}

// Exit the application
return 0;
}

In: Computer Science

1. Give a command using find to search from the root directory the file program.f and...

1. Give a command using find to search from the root directory the file program.f and redirect any errors to the file myerrors.txt

2. Give a command for finding files having the letters index as the beginning of the file name and located in your home directory (provide the absolute path)

3. Give a command for finding within a directory called /mp3collection, only those mp3 files that have a size less than 5000 Kilobytes (< 5MB).

4. Give a commmand that searches for those files that are present in the directory /home/david and its subdirectories which end in .c and which have been accessed in the last 10 minutes.

5. Give a command that searches within the directory /mp3-collection for files that have their names beginning with ’Metallica’ and whose size is greater than 10000 kilobytes (> 10 MB).

6. Give a command that searches in the same directory as above case but only for files that are greater than 10MB, but they should not have ’Metallica’ as the starting of their filenames.

7. Explain what the following commands do. What is the major difference between their outputs? a) chmod -R 755 . b) chmod -R 755 *

8. Explain the output of the following command:

pr -t -n -d -o 10 group12

9. Study the cut command and describe what is its function, provide some examples including options like -c, and -f.

10. What is the output of the following command?

sort -t: -k3,3 -n /etc/group

In: Computer Science

Ex: Write a program to randomly generate 31 positive integers below 100 to find the median...

Ex: Write a program to randomly generate 31 positive integers below 100 to find the median and display it on the root, and display the remaining integers as BST (Binary Search Tree).
(Generate JTextArea panels at the bottom to display the results of the potential, intermediate, and rearward tours.)

Write java code (Using GUI,no javafx)and show me the output.

If you can't understand the question, let me know. :)

Thank you :)

In: Computer Science