Questions
This is one lab question. I can not get this to work because of the templates,...

This is one lab question. I can not get this to work because of the templates, please help. It is extremely important the driver is not changed!!!!

Recall that in C++, there is no check on an array index out of bounds. However, during program execution, an array index out of bounds can cause serious problems. Also, in C++, the array index starts at 0.Design and implement the class myArray that solves the array index out of bounds problem and also allows the user to begin the array index starting at any integer, positive or negative.

Every object of type myArray is an array of type int. During execution, when accessing an array component, if the index is out of bounds, the program must terminate with an appropriate error message. Consider the following statements:
myArray list(5);                                   //Line 1
myArray myList(2, 13);                      //Line 2
myArray yourList(-5, 9);                     //Line 3

The statement in Line 1 declares list to be an array of 5 components, the component type is int, and the components are: list[0], list[1], ..., list[4]; the statement in Line 2 declares myList to be an array of 11 com- ponents, the component type is int, and the components are: myList[2], myList[3], ..., myList[12]; the statement in Line 3 declares yourList to be an array of 14 components, the component type is int, and the components are: yourList[-5], yourList[-4], ..., yourList[0], ..., yourList[8].

  1. Add an overloaded operator!=(…) and operator==(…) functions.
  2. Use the attached driver to test the program (lab6_Driver.cpp):
   
#include <iostream> 
#include "myArray.h"

using namespace std;

int main()
{ 
    myArray<int> list1(5);
    myArray<int> list2(5);

    int i;

    cout << "list1 : ";
    for (i = 0 ; i < 5; i++)
        cout << list1[i] <<" ";
    cout<< endl;

    cout << "Enter 5 integers: ";
    for (i = 0 ; i < 5; i++)
        cin >> list1[i];
    cout << endl;

    cout << "After filling list1: ";

    for (i = 0 ; i < 5; i++)
        cout << list1[i] <<" ";
    cout<< endl;

    list2 = list1;
    cout << "list2 : ";
    for (i = 0 ; i < 5; i++)
        cout << list2[i] <<" ";
    cout<< endl;

    cout << "Enter 3 elements: ";

    for (i = 0; i < 3; i++)
        cin >> list1[i];
    cout << endl;

    cout << "First three elements of list1: ";
    for (i = 0; i < 3; i++)
        cout << list1[i] << " ";
    cout << endl;

    myArray<int> list3(-2, 6);

    cout << "list3: ";
    for (i = -2 ; i < 6; i++)
        cout << list3[i] <<" ";
    cout<< endl;

    list3[-2] = 7;
    list3[4] = 8;
    list3[0] = 54;
    list3[2] = list3[4] + list3[-2];

    cout << "list3: ";
    for (i = -2 ; i < 6; i++)
        cout << list3[i] <<" ";
    cout<< endl;

        if (list1 == list2)
                cout << " list 1 is equal to list2 " << endl;
        else
                cout << " list 1 is not equal to list2" << endl;

        if (list1 != list2)
                cout << " list 1 is not equal to list2 " << endl;
        else
                cout << " list 1 is equal to list2" << endl;

    system("pause");
    return 0;
}

So I need to write a myArray class that will work with this driver, that also overloads the operators. Do not change the driver. It must use a template <T>.

In: Computer Science

Java Language Add a method (deleteGreater ()) to the LinkedList class to delete the node with...

Java Language

Add a method (deleteGreater ()) to the LinkedList class to delete the node with the higher value data.

Code:

class Node {

int value;

Node nextNode;

Node(int v, Node n)

{

value = v;

nextNode = n;

}

Node (int v)

{

this(v,null);

}

}

class LinkedList

{

Node head; //head = null;

LinkedList()

{

}

int length()

{

Node tempPtr;

int result = 0;

tempPtr = head;

while (tempPtr != null)

{

tempPtr = tempPtr.nextNode;

result = result + 1;

}

return(result);

}

void insertAt(int v, int position)

{

Node newNode = new Node(v,null);

Node tempPtr;

int tempPosition = 0;

if((head == null) || (position ==0))

{

newNode.nextNode = head;

head = newNode;

}

else {

tempPtr = head;

while((tempPtr.nextNode != null)&&(tempPosition < position -1))

{

tempPtr = tempPtr.nextNode;

tempPosition = tempPosition + 1;

}

if (tempPosition == (position - 1))

{

newNode.nextNode = tempPtr.nextNode;

tempPtr.nextNode = newNode;

}

}

}

public String toString()

{

Node tempPtr;

tempPtr = head;

String result = "";

while(tempPtr != null)

{

result = result + "[" + tempPtr.value + "| ]-->";

tempPtr = tempPtr.nextNode;

}

result = result + "null";

return result;

}

}

public class LinkedListDemoInsDel

{

public static void main(String[] args)

{

LinkedList aLinkedList = new LinkedList();

aLinkedList.insertAt(1,0);

aLinkedList.insertAt(9,1);

aLinkedList.insertAt(13,2);

aLinkedList.insertAt(8,1);

aLinkedList.insertAt(3,2);

System.out.println(aLinkedList);

System.out.println("Largo de lista: " + aLinkedList.length());

}

}

In: Computer Science

For this IP, you will create a very simple drawing app using Android Studio. The purpose...

For this IP, you will create a very simple drawing app using Android Studio. The purpose of this assignment is to give you more building blocks to use when programming apps. For full credit for this assignment, you should complete the following: Create a menu and display menu items on the app bar Detect when the user touches the screen and moves a finger Be able to change the color and width of a line Be able to save an image To turn in this assignment, upload screenshots of the working app (from the emulator) as a Word document. The screenshots need to show that the app works and that all of the parts listed work. At a minimum, students should upload 2 screenshots showing: A drawing Menu showing the different color choices and line widths.

In: Computer Science

A (7, 4) cyclic code is designed with a generator polynomial, g(D) = D3 + D...

A (7, 4) cyclic code is designed with a generator polynomial, g(D) = D3 + D + 1. a) (10 points) Determine the code word for the message, 1010. b) (10 points) Determine the code word for the message, 1100. c) (9+1= 10 points) Determine the error polynomial for the received word, 1110101. Is the received word correct?

In: Computer Science

For java. It's your turn to write a test suite! Let's start out simple. Create a...

For java.

It's your turn to write a test suite! Let's start out simple. Create a public class TestArraySum that provides a single void class method named test. test accepts a single parameter: an instance of ArraySum.

Each ArraySum provides a method sum that accepts an int[] and returns the sum of the values as an int, or 0 if the array is null. However, some ArraySum implementations are broken! Your job is to identify all of them correctly.

To do this you should use assert to test various inputs. Here's an example:

assert sum.sum(null) == 0;

Your function does not need to return a value. Instead, if the code is correct no assertion should fail, and if it is incorrect one should.

As you design test inputs, here are two conflicting objectives to keep in mind:

  • Less is more. The fewer inputs you need to identify all broken cases, the more readable your test suite will be.
  • Think defensively. At the same time, you want to anticipate all of the different mistakes that a programmer might make. You've probably made many of these yourself! Examples include forgetting to check for null, off-by-one errors, not handling special cases properly, etc.

In: Computer Science

Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking...

Please answer with code for C language

Problem: Counting Numbers

Write a program that keeps taking integers until the user enters -100.

In the end, the program should display the count of positive, negative (excluding that -100) and zeros entered.

Sample Input/Output 1:

Input the number:

0

2

3

-9

-6

-4

-100

Number of positive numbers: 2

Number of Negative numbers: 3

Number of Zero: 1

In: Computer Science

Java homework problem. This is my hotel reservation system. I'm trying to add a few things...

Java homework problem. This is my hotel reservation system. I'm trying to add a few things to it.

You will be changing your Hotel Reservation system to allow a user to serve more rooms and the rooms will be created as objects.

  1. For this project you will be modifying the Hotel Reservation system to allow a user to serve more rooms and the rooms will be created as objects.

    1. You will be create a Room object that will allow the user to set the type of room, if they want pets, and if they want Oceanview.

      1. OV is $50 more

      2. Pets $25 more

      3. King, Suite and Queen style rooms and you can set the prices

    2. You will have an array for username and password that hold 3 userNames and 3 passwords. These will be parallel arrays. I am allowed to enter username and password 3 times and then I get kicked out.

    3. Main

      1. The main method will keep track of information for 5 room reservations objects all for 1 night

        1. Be sure to use looping, somewhere in the main java file.

        2. Create a method that will catch the object and create it. Remember you can pass by reference or return the object back to the main.

        3. Create a method to handle printing out each of the objects to the screen and the total for each room. (You can set this total in the Room Class if you wish.)

        4. Finally Create a method that will show out the grand total.

Here is my original code to be modified:

import java.util.Scanner;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public class hotelreservation {
  
  
      public static double roomSelection(Scanner scan)
   {

       String roomSelection;
       System.out.print("Please enter the type of room desired for your stay (King/Queen/Suite/Two doubles): ");
       roomSelection = scan.nextLine();
    
       if(roomSelection.equalsIgnoreCase("Suite"))
           return 275;
       else if(roomSelection.equalsIgnoreCase("Queen"))
           return 150;
       else if(roomSelection.equalsIgnoreCase("King"))
           return 150;
       else
           return 125;
   }

   public static double roomOceanView(Scanner scan)
   {
       String response;
       System.out.print("Would you like an oceanview room (Yes/No) ? ");
       response = scan.nextLine();
    
       if(response.equalsIgnoreCase("Yes"))
           return 45;
       else
           return 0;
   }

   public static double roomPets(Scanner scan)
   {
       String response;
       System.out.print("Do you have any pets (Yes/No) ? ");
       response = scan.nextLine();
    
       if(response.equalsIgnoreCase("Yes"))
           return 50;
       else
           return 0;
   }

   public static void main(String[] args) {
     
       DecimalFormat decFormat = new DecimalFormat("0.00");
       Scanner scan = new Scanner(System.in);
       double roomReservation[] = new double[3];
       double subTotal = 0;
    
       for(int x=0;x        {
           System.out.println("Welcome to our Hotel Room Reservation Pricing System.");
           System.out.println("Please answer the following questions regarding your reservation of room #"+(x+1)+" : ");
           roomReservation[x] = roomPets(scan);
           roomReservation[x] += roomSelection(scan);
           roomReservation[x] += roomOceanView(scan);
       }
     
       for(int x=0;x        {
           System.out.println("Total cost for room #"+(x+1)+" : $"+decFormat.format(roomReservation[x]));
           subTotal += roomReservation[x];
       }
    
       System.out.println("Subtotal: $"+decFormat.format(subTotal));
       double tax = subTotal*0.05;
       System.out.println("Total Tax (5%): $"+decFormat.format(tax));
       System.out.println("Grand Total: $"+(decFormat.format(subTotal+tax)));
       scan.close();
   }

}

In: Computer Science

For Java Let's get more practice testing! Declare a public class TestRotateString with a single void...

For Java

Let's get more practice testing! Declare a public class TestRotateString with a single void static method named testRotateString. testRotateString receives an instance of RotateString as a parameter, which has a single method rotate. rotate takes a String and an int as arguments, and rotates the passed string by the passed amount. If the amount is positive, the rotation is to the right; if negative, to the left. If the String is null, rotate should return null.

Your testRotateString method should test the passed implementation using assert. Here's an example to get you started:\

assert rotate.String.rotate(null, 0) == null;

As you create your test suite, consider the various kinds of mistakes that you might make when implementing rotate. Maybe getting the direction wrong, or using the modulus improperly? There are lots of ways to mess this up! You need to catch all of them. Good luck!

In: Computer Science

True or False: It's easy to loop through an array using a for loop in C++...

True or False: It's easy to loop through an array using a for loop in C++ because you can use the .size() function to get the total number of spaces in the array

True or False: It's easy to loop through a vector using a for loop in C++ because you can use the .size() function to get the total number of spaces in the vector

In: Computer Science

*2-  Describe the role of the communication layer, the network-wide state-management layer, and the network-control application layer...

*2-  Describe the role of the communication layer, the network-wide state-management layer, and the network-control application layer in the SDN controller.

*3- Name the four different types of ICMP messages including type and code. What two types of ICMP messages are received at the sending host executing the Traceroute program?

*4- Why are different inter-AS and intra-AS protocols used in the internet? Explain your answer.

In: Computer Science

Step 1: Respond to the following: Planning and Executing Chapter 2 discusses the various project management...

Step 1: Respond to the following: Planning and Executing Chapter 2 discusses the various project management processes. In your initial discussion post, address the following:

 What does research suggest about the amount of time that should be spent on the initiating and planning processes?

 Do you think that the suggested amount of time is realistic? Why or why not?

 Why do you think spending more time on planning helps reduce time spent on executing?

Step 2: Read other students' posts and respond to at least three other students. Use any personal experience if appropriate to help support or debate other students' posts. If differences of opinion occur, students should debate the issues and provide examples to support opinions.

In: Computer Science

Write a C++ program that will use good object-oriented principles. You have been tasked to write...

Write a C++ program that will use good object-oriented principles.

You have been tasked to write an application that will allow a user to change their system password. The XYZ Corporation has the following rules for passwords:

  • each password should have a minimum of 8 characters
  • each password should have a minimum of 2 uppercase characters (A - Z)
  • each password should have a minimum of 2 lowercase characters (a - z)
  • each password should have a minimum of 2 digits (0 - 9)
  • each password should have a minimum of 2 special characters of which the following characters are allowed: !, @, $, %, and & (in any combination)

Once the user has created a new password that passes the above requirements, the user must then retype the password for the program to verify that the same password was entered by the user.

If the user creates a password that does not meet the minimum requirements, be sure to let the user know the entered password does not meet the minimum requirements and allow the user to retype the password.
If the user creates a password that does not match the second entry of the password (both entries much match), then be sure to let the user know the password update is unsuccessful.


If the password entered does not meet the minimum requirements, an error message should be displayed and allow the user to try again.

If the password entered contains the minimum requirements listed, then ask the user to retype the password for verification.
If the two entered passwords do not match, an error message should be displayed and the user should be allowed to retype the password.


An Example:

Update Your Password

Password Requirements:
- minimum of 8 characters
- minimum of 2 uppercase characters (A - Z)
- minimum of 2 lowercase characters (a - z)
- minimum of 2 digits (0 - 9)
- minimum of 2 special characters: !, @, $, %, &, _

Enter a new password: Pa$$word123

Error: password does not meet minimum requirements, try again:

Enter a new password: Pa$$Word123

Password meets minimum requirements.

Reenter the new password: Pa$$Word223

Error: update unsuccessful. Entries do not match, try again:

Reenter the new password: Pa$$Word123

Password Update successful.


Remember to change your password every 90 days.




The program should have as a minimum:

a class named Password

private member variables:

  • string to hold the initial password entry
  • string to hold the second password entry
  • int variables (4 minimum) to hold the count of:
    • number of uppercase characters entered
    • number of lowercase characters entered
    • number of digits entered
    • number of valid special characters entered

private member functions (all called from the driver() method):

  • void setPassword1() - prompts and reads in the initial password entry from the user
  • void validateRequirements() - validates the initial password entered meets the minimum requirements established
  • void setPassword2() - prompts the user to reenter the password and reads in the value entered ONLY when the initial password is valid
  • void validateMatch() - validates that both password entries match exactly
  • void display() - displays the result


public member functions:

  • class constructor - initialize variables
  • void driver() - called from main() and is the order of execution


!!!NOTE: any program submission that does not use a class and object and/or does not use appropriate methods will result in a grade submission of 0.
Use of global variables will also result in a grade submission of 0.

In: Computer Science

Python: What are the defintions of the three method below for a class Date? class Date(object):...

Python: What are the defintions of the three method below for a class Date?

class Date(object):
"Represents a Calendar date"
  
def __init__(self, day=0, month=0, year=0):
"Initialize"
pass


def __str__(self):
"Return a printable string representing the date: m/d/y"
pass
  

def before(self, other):
"Is this date before that?"

In: Computer Science

What are the different areas of application of social network analysis? Mention at least 5 areas...

  1. What are the different areas of application of social network analysis? Mention at least 5 areas with one application in each area.
  2. What are the different levels of social network analysis? What is the difference between them?
  3. Why do we need a different level of social network analysis?
  4. What is a clique? What are the advantages and disadvantages of a clique?
  5. What is the difference between K-plex and K-core?

In: Computer Science

In the given instruction, I am to use while loops only. The goal is to prompt...

In the given instruction, I am to use while loops only. The goal is to prompt the user to select an acceptable input. If the wrong input is given, the program forces the user to select an appropriate input. The program also keeps running until the user chooses to exist by selecting a very specific input which in my case is the upper or lower case "E".

The problem is even after selecting upper or lower case "E", my program keeps running. I am using the "i" variable as the condition for my while loop. I initialized the variable to 2, for example, and set my while loop to 2 which means the condition is true and the while loop will keep running. I changed my "i" variable to 3 for example only when upper or lower case "E" is pressed. This according to my thinking should make the loop false and essentially not run the loop anymore but my loop keeps running

#include<stdio.h>

int main()
{
    char selection;
    float length, width, area, base, height, apothem, side;
    int i=2;
    while (i=2)
    {
    printf("Press R to calculate the area of a rectangle\nPress T to calculate the area of a right angled triangle\nPress M to calculate the area of a polygon\nPress E to exit the program\n");
    scanf(" %c", &selection);
    switch (selection)
    {
    case 'R':
    case 'r':
        printf("Enter the length of the rectangle\n");
        scanf("%f", &length);
        printf("Enter the width of the rectangle\n");
        scanf("%f", &width);
        area=length*width;
        printf("The area of the rectangle is %f\n", area);
        break;
    case 'T':
    case 't':
        printf("Enter the base of the triangle\n");
        scanf("%f", &base);
        printf("Enter the height of the triangle\n");
        scanf("%f", &height);
        area=(0.5)*base*height;
        printf("The area of the triangle is %f\n", area);
        break;
    case 'M':
    case 'm':
        printf("Enter the length of one side of the polygon\n");
        scanf("%f", &length);
        printf("Enter the apothem of the polygon\n");
        scanf("%f", &apothem);
        printf("Enter the number of sides of the polygon\n");
        scanf("%f", &side);
        area=0.5*length*side*apothem;
        printf("The area of the polygon is %f\n", area);
        break;
    case 'E':
    case 'e':
        printf("You are exiting the program\n");
        i=3;
        break;
    default:
        printf("You have selected an invalid input\n");
        break;
    }
    }
    return 0;
}

In: Computer Science