Questions
/* CIS 251 In Class Assignment    This program performs various operations on a ten element...

/*

CIS 251 In Class Assignment

  

This program performs various operations on a ten

element int array.

*/

#include <iostream>

using namespace std;

void start (int boxes [10]);

void move (int squares [10], int x, int y, int z);

void add (int arr [10], int first, int last);

void print (int arr [10]);

int main ()

{

int my_arr [10];

  

cout << "The original array is:\n";

print (my_arr);

  

start (my_arr);

cout << "\n\nThe array after start is:\n";

print (my_arr);

  

move (my_arr, 2, 4, 6);

cout << "\n\nThe array after move is:\n";

print (my_arr);

  

add (my_arr, 3, 7);

cout << "\n\nThe array after add is:\n";

print (my_arr);

  

cout << "\n\n";

return 0;

}

void start (int boxes [10])

{

   int index, count;

   count = 17;

   for (index = 0; index < 10; index++)

   {

   boxes [index] = count;

   count--;

   }

}

void move (int squares [10], int x, int y, int z)

{

   int temp;

   temp = squares [x];

   squares [x] = squares [y];

   squares [z] = squares [y];

   squares [y] = temp;

}

void add (int arr [10], int first, int last)

{

   int m;

   for (m = first; m <= last; m++)

   arr [m]++;

}

void print (int arr [10])

{

   int z;

   for (z = 0; z < 10; z++)

   cout << z << " ";

}

Questions and Experiments:

1. The function print is supposed to print each element of the array but does not work. What does it print?

  • Fix the print function so that it works properly.

2. Now that print has been fixed, run your program again. Why did “funny” values show up for the first call to print?

3. The array has different names in the functions than it does in main. Explain why this is not a problem.

4. Would the program still work if the array had the same name in the functions as in main?

5. What values would be placed in the array by the function start if count was initially set equal to 0 instead of 17? Show the values.

6. Remove the { } associated with the for statement in the function start. Run your program and explain clearly why the output changes as shown.

Add the {} back to the program.

7. Say that we have an array, my_arr, with the following values:

   5 9 3 4 6 12 19 22 3 4

[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]

and the function move is called as follows:

move (my_arr, 1, 3, 5);

Show above how this call would change the array.

8. Explain clearly what the function add does. Include the parameters first and last in your explanation.

9. How would add change the array if called as follows:

add (my_arr, 7, 2);

Explain your answer.

  • Add a function prototype and definition for a function called print_reverse to your program. print_reverse takes an array as a parameter and prints the array values in reverse order. Have your program call this function after the last print. Have main print a label indicating that the array is being printed in reverse before the call.

In: Computer Science

Be sure to statically disable both the Enter Subtotal label and the Enter Subtotal textbox. If...

  1. Be sure to statically disable both the Enter Subtotal label and the Enter Subtotal textbox. If you do not know what this means, ask.
  2. Add a label, a text box, and an OK button (see Exercise 3.1 X if you need a refresher) to your form to enable the user to enter his or her name and click OK.

3. In the handler code for the OK button, first check (as you did in Exercise 1 X) to ensure that the name is not blank. If the name is blank generate a message as requested in Exercise 1 X, reset focus and have the user try again to enter a non-blank name.

4. Once a non-blank name has been entered, dynamically (in your own code) enable the Enter Subtotal label and the Enter Subtotal text box.

5. Now in your handler code for btnCalculate, insert try-catch code (see p. 193 for an example) to catch an invalid decimal value entry and ask the user to re-enter his or her data.  

6. Test your project and if the code you have added does not catch a negative input value, make sure you correct this problem and retest your project.

This is the code that I have.

namespace InvoiceTotal
{
   public partial class frmInvoiceTotal : Form
   {
public frmInvoiceTotal()
       {
           InitializeComponent();
       }

       int numberOfInvoices = 0;
       decimal totalOfInvoices = 0m;
       decimal invoiceAverage = 0m;
       decimal largestInvoice = 0m;
       decimal smallestInvoice = Decimal.MaxValue;

       private void btnCalculate_Click(object sender, EventArgs e)
       {
           decimal subtotal = Convert.ToDecimal(txtEnterSubtotal.Text);
           decimal discountPercent = .25m;
           decimal discountAmount = Math.Round(subtotal * discountPercent, 2);
           decimal invoiceTotal = subtotal - discountAmount;

           txtSubtotal.Text = subtotal.ToString("c");
           txtDiscountPercent.Text = discountPercent.ToString("p1");
           txtDiscountAmount.Text = discountAmount.ToString("c");
           txtTotal.Text = invoiceTotal.ToString("c");

           numberOfInvoices++;
           totalOfInvoices += invoiceTotal;
           invoiceAverage = totalOfInvoices / numberOfInvoices;
           largestInvoice = Math.Max(largestInvoice, invoiceTotal);
           smallestInvoice = Math.Min(smallestInvoice, invoiceTotal);

           txtNumberOfInvoices.Text = numberOfInvoices.ToString();
           txtTotalOfInvoices.Text = totalOfInvoices.ToString("c");
           txtInvoiceAverage.Text = invoiceAverage.ToString("c");
           txtLargestInvoice.Text = largestInvoice.ToString("c");
           txtSmallestInvoice.Text = smallestInvoice.ToString("c");

           txtEnterSubtotal.Text = "";
           txtEnterSubtotal.Focus();
       }

       private void btnClearTotals_Click(object sender, System.EventArgs e)
       {
           numberOfInvoices = 0;
           totalOfInvoices = 0m;
           invoiceAverage = 0m;
           largestInvoice = 0m;
           smallestInvoice = Decimal.MaxValue;

           txtNumberOfInvoices.Text = "";
           txtTotalOfInvoices.Text = "";
           txtInvoiceAverage.Text = "";
           txtLargestInvoice.Text = "";
           txtSmallestInvoice.Text = "";

           txtEnterSubtotal.Focus();
       }

       private void btnExit_Click(object sender, EventArgs e)
       {
           this.Close();
       }

   }
}

In: Computer Science

Write single linux commands for each question. 2. Find every file ends with “.py” or “.txt”...

Write single linux commands for each question.

2. Find every file ends with “.py” or “.txt” or “.cpp” from your root directory, and list the detail of each file.
3. Find every line that contains two or more space in every file in “Folder1” include subdirectory.
4. Find every line that contains two or more “<<” symbol in “Folder2” include subdirectory.
5. Find every line that contains parentheses inside parentheses in “Folder3” include subdirectory, such as print(type(6*2)).
6. Find every line that contains at least two digits in folder “Folder1”, “Folder2” and “Folder3” include subdirectory. The two digits can be two separate digit, such as “1.5” or “1 and 2”.
7. Find every line that start with “}” or ends with “{” in “Folder2” include subdirectory. Example: “int main(){” or “}”.
8. Find every line that contains any pair of repeated words in folder “Folder1”, “Folder2” and “Folder3” include subdirectory. Example: a + a, b b, c d c d. (The command should be able to find the ‘c = a + “ ” + b’)
9. List every filename contains at least two digits from folder “Folder1”, “Folder2” and “Folder3” include subdirectory.
10. List every filename contains a number that greater than 11 and less than 22 from folder “Folder1”, “Folder2” and “Folder3” include subdirectory.

In: Computer Science

What are design patterns in object oriented programming? Minimum 200 words

What are design patterns in object oriented programming?

Minimum 200 words

In: Computer Science

The biggest mysteries of the IEEE 754 Floating-Point Representation are “hidden bit” and “Bias. Can someone...

The biggest mysteries of the IEEE 754 Floating-Point Representation are “hidden bit” and “Bias.

Can someone explain to me why the "hidden bits" and "bias" are considered to be mysteries for the IEEE 754 floating point representation

In: Computer Science

Android Studio (Java) I'm trying to create a simple calculator. I want to put out a...

Android Studio (Java)

I'm trying to create a simple calculator. I want to put out a message if they try to divide by 0.

I have this so far. What code should I put?

divide.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if (number1.getText().length() != 0 && number2.getText().length() != 0) {
            double n1= Double.parseDouble(number1.getText().toString());
            double n2= Double.parseDouble(number2.getText().toString());

            double res= n1 / n2;

            result.setText(String.valueOf(res));
        } else {
            Toast.makeText(view.getContext(), "Please enter the numbers properly", Toast.LENGTH_SHORT).show();
        }
    }

});

In: Computer Science

There are issue the muy code The Body Mass Index (BMI) is a calculation used to...

There are issue the muy code

The Body Mass Index (BMI) is a calculation used to categorize whether a person’s weight is at a healthy weight for a given height. The formula is as follows:

                bmi = kilograms / (meters2)

                where kilograms = person’s weight in kilograms, meters = person’s height in meters

BMI is then categorized as follows:

Classification

BMI Range

Underweight

Less than 18.5

Normal

18.5 or more, but less than 25.0

Overweight

25.0 or more, but less than 30.0

Obese

30.0 or more

To convert inches to meters:

                meters = inches / 39.37

To convert pounds (lbs) to kilograms:

                kilograms = lbs / 2.2046

Assignment

Ask the user for their weight in pounds and height in inches. Compute their BMI and BMI classification and output the results.

The program must implement and use the following methods:

convertToKilograms – convert pounds to kilograms

convertToMeters – convert inches to meters

calcBMI – take weight in kilograms and height in meters and return the BMI

bmiClassification – take the value for the BMI and return a String with the BMI classification

Use the following code as a starting point for your assignment:

import java.util.Scanner;

// TODO Student name, date, purpose
public class Main {

    private static Scanner input = new Scanner(System.in);

    public static void main(String[] args) {
        double lbs, inches, meters, kgs, bmi;
        String classification;

       // TODO add code here
   
}

   // TODO add your methods here (make them static)
}

As always use the package name edu.cscc and include a comment with your name, the date, and the purpose of the program.

Example Output

Calculate BMI

Enter weight (lbs): 200

Enter height (inches): 72

Your BMI is 27.124767811523153

Your BMI classification is Overweight

My code:

public class Main {

    private static Scanner input = new Scanner(System.in);

    public static void main(String[] args) {
        double lbs, inches, meters, kgs, bmi;
        String classification;
        System.out.println("Calculate BMI");
        System.out.println("Enter weight(lbs):");
        lbs = input.nextDouble();
        System.out.println("Enter height (inches):");
        meters = input.nextDouble() * 0.0254;
        //Converting pounds to kegs
        kgs = lbs / 2.2;
        //Calculation of BMI
        bmi = calculateBMI(kgs, meters);
        //Classification of bmi
        classification = classify(bmi);
        System.out.println("Your BMI is " + bmi);
        System.out.println("Your BMI classification is " + classification);
    }

    public static double calculateBMI(double weight,double height) {
        return weight/ (height*height);
    }
    // Classify the BMI to string
    public static String classify(double bmi) {
        if(bmi < 18.5) {
            return "Underweight";
        }else if(bmi < 25.0) {
            return "Normal";
        }else if(bmi < 30.0) {
            return "Overweight";
        }else {
            return "Obese";
        }
    }
}

In: Computer Science

Cyber security Security Policy: , write a small antivirus policy for the IT infrastructure and users...

Cyber security

Security Policy:

  1. , write a small antivirus policy for the IT infrastructure and users in a
    1. small business
    2. an elementary school
    3. You may research anti-virus policies of organizations on the web, please use and cite responsibly.

Security Recommendation: Rose Shumba manages the IT security for a school. Given the wide range of people who use the school’s computers, it is challenging for Rose to prevent virus infections. She has installed an anti-virus on each machine and has a policy prohibiting software downloads.

Comment on:

  1. How secure is the network from viruses?
  2. What areas has Rose not secured?
  3. What recommendations would you make to Rose to increase the security?

In: Computer Science

In C++, Write the following program using a vector: A common game is the lottery card....

In C++, Write the following program using a vector:

A common game is the lottery card. The card has numbered spots of which a certain number are selected at random. Write a Lotto() function that takes two arguments. The first should be the number of spots on a lottery card and the second should be the number of spots selected at random. The function should return a vector object that contains, in sorted order, the numbers selected at random. Use your function as follows:

Vector winners;

winners = Lotto(51,6);

This would assign to winners a vector that contains six numbers selected randomly from the range 1 through 51.

Also write a short program that lets you test the function,

In: Computer Science

Using Visual Studio in C#; create a grading application for a class of ten students. The...

Using Visual Studio in C#; create a grading application for a class of ten students. The application should request the names of the students in the class. Students take three exams worth 100 points each in the class. The application should receive the grades for each student and calculate the student’s average exam grade. According to the average, the application should display the student’s name and the letter grade for the class using the grading scheme below. Grading Scheme: • A = 90-100 • B = 80-89 • C = 70-79 • D = 60-69 • F = <60

In: Computer Science

Question: In a package named "oop" create a Scala class named "Team" and a Scala object...

Question: In a package named "oop" create a Scala class named "Team" and a Scala object named "Referee". Team will have:

• State values of type Int representing the strength of the team's offense and defense with a constructor to set these values. The parameters for the constructor should be offense then defense

• A third state variable named "score" of type Int that is not in the constructor, is declared as a var, and is initialized to 0 Referee will have:

• A method named "playGame" that takes two Team objects as parameters and return type Unit. This method will alter the state of each input Team by setting their scores equal to their offense minus the other Team's defense. If a Team's offense is less than the other Team's defense their score should be 0 (no negative scores)

• A method named "declareWinner" that takes two Teams as parameters and returns the Team with the higher score. If both Teams have the same score, return a new Team object with offense and defense both set to 0

In: Computer Science

In this assignment, you will write a class that implements a contact book entry. For example,...

In this assignment, you will write a class that implements a contact book entry. For example, my iPhone (and pretty much any smartphone) has a contacts list app that allows you to store information about your friends, colleagues, and businesses. In later assignments, you will have to implement this type of app (as a command line program, of course.) For now, you will just have to implement the building blocks for this app, namely, the Contact class.
Your Contact class should have the following private data:
• The first name of the person
• The last name of the person •The phone number of the person • The street address of the person • The city of the person
• The state of the person
The Contact class should implement the Comparable interface. More on this later.
Of course, you may implement private helper methods if it helps your implementation.
Your class should have the following public methods:
• A constructor that initializes all the fields with information.
• A constructor that initializes only the name and phone number.
• accessor (getter) methods for all of the data members.
• an update method that allows the user to change all information. (They must change all of it).
• An overridden equals() method that can tell if one Contact is the same as another. It should have the method signature:
public boolean equals(Object obj);
We will define one Contact as being the same as another contact if the first and last names both match. (Be careful! The parameter may not be a bona fide Contact!)
• An overridden toString() method that creates a printable representation for a Contact object.
  
It should have the method signature:
public String toString();
The String should be created in the following form:
<First name> <last name> Phone number: <phone number> <street address>
<city> , <state>
For example my contact info would look like:
john Doe Phone number: (111) 111-1111
2900 XYZ Avenue
city, state
• A comparison method that looks like this:
public int compareTo(Contact another);
We will define this method in the following way:
If the last name of “another” is lexicographically first, return a positive
number.
If the last name of “another” is lexicographically second, return a negative
number.
If the last names are the same and the first names are also the same, return 0. If the last names are the same and the first names are different, use the first
names to determine the order.
You must also declare the fact that Contact implements the Comparable interface.
You must also write a main program that tests each of these functions and
shows me that you understand how to use the Contact class in a program.
You can choose to write this main program as a stand alone class that sits in the same directory as the Contact class, or you can just make the main program the main program of the Contact class itself.

In: Computer Science

Create a method that takes a HashMap<Integer, Integer> and returns the sum of the keys of...

Create a method that takes a HashMap<Integer, Integer> and returns the sum of the keys of the HashMap.

In: Computer Science

Explain Interpolation: Reverse neighbor interpolation, subject is digital image processing

Explain Interpolation: Reverse neighbor interpolation, subject is digital image processing

In: Computer Science

I am having trouble fixing my build errors. The compiler I am using is Visual Studio.Thanks....

I am having trouble fixing my build errors. The compiler I am using is Visual Studio.Thanks.

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

/*
* structure to store employee details
* employee details are stored as linked list
*/
struct Employee
{
private:

   string full_name; //full name
   double net_income; //income

public:
   struct Employee *next; //pointing to the next employee details in the list

                       /*
                       * create new employee node
                       */
   Employee(string full_name, double net_income)
   {
       this->full_name = full_name;
       this->net_income = net_income;
       this->next = NULL;
   }

   /*
   * display the details of this employee
   */
   void displayDetails()
   {
       cout << "\tFull name : " << full_name << endl;
       cout << "\tDaily salary: " << net_income << endl << endl;
   }
};

/*
* Implementation of Queue
*/
class EmployeeQueue
{
   struct Employee *front = NULL, *rear = NULL; // front and rear pointers of queue

public:
   /*
   * inset a new employee details into queue
   * this function take argument as a pointer to employee struct
   */
   void enqueue(struct Employee *newEmployee)
   {
       if (rear == NULL)
       {
           /*
           * empty wueue
           */
           rear = newEmployee;
           front = newEmployee;
       }
       else
       {
           /*
           * not empty
           * inseting new details at rear
           */
           rear->next = newEmployee;
           rear = newEmployee;
       }
   }

   /*
   * remove employee who is in front of the queue
   * this function return a pointer to employee struct
   */
   Employee* dequeue()
   {
       if (front == NULL)
       {
           /*
           * empty queue
           */
           return NULL;
       }

       /*
       * details of employee who is in front
       */
       struct Employee *leavingEmployee = front;

       front = front->next;

       if (front == NULL)
           rear = NULL;

       return leavingEmployee;
   }
};

int main()
{
   Employee * employee; //pointer of employee structure
   EmployeeQueue *queue = new EmployeeQueue(); //pointer of employee queue

   int ch = 0;
   string first_name;
   string last_name;
   string full_name;
   double work_hours;
   double hourly_rate;
   double tax_rate;
   double gross_salary;
   double net_salary;

   /*
   * iterate user inputs until exit command
   */

   while (ch != 3)
   {
       /*
       * displaying main menu
       */
       cout << endl << "1. Enter an employee information" << endl;
       cout << "2. Display information of employee who is leaving the work" << endl;
       cout << "3. Exit program" << endl;
       cout << "Enter your choice: ";
       cin >> ch; //getting choice

               /*
               * processing user choice
               */
   }

   switch (ch)
   {
   case 1:
   {   /*
       * choice to add new employee
       *
       * getting input of employee details
       */
       cout << "\tEnter first name of employee : ";
       cin >> first_name;
       cout << "\tEnter the last name of the employee : ";
       cin >> last_name;
       cout << "\tEnter working hours of the employee : ";
       cin >> work_hours;
       cout << "\tEnter the hourly working rate of the employee: ";
       cin >> hourly_rate;
       cout << "\tEnter the tax rate (%) of the employee : ";
       cin >> tax_rate;

       /*
       * finding full name
       *
       * full name = first name + last name
       */
       full_name = first_name + " " + last_name;

       /*
       * calculating gross salary
       *
       * gross salary = working hours * hourly rate
       */
       gross_salary = (work_hours * hourly_rate);

       /*
       * calculating net salary
       *
       * net salary = gross salary - (gross salary * (tax rate / 100)
       */
       net_salary = gross_salary - (gross_salary * tax_rate / 100.0);

       /*
       * creating new employee structure
       */
       employee = new Employee(full_name, net_salary);

       /*
       * inserting new employee details into queue
       */

       queue->enqueue(employee);
   }
   break;
   {case 2:
       /*
       * choice to display details
       */
       /*
       * getting details of employee who is leaving
       */
       employee = queue->dequeue();
   }
   if (employee != NULL)
   {
       /*
       * if not null displaying details
       */
       cout << "\tDetails of employee who is leaving:" << endl;
       employee->displayDetails();
   }
   else
   {
       /*
       * queue is empty
       */
       cout << "Queue is empty." << endl;
   }
   break;
   {   case 3:
       /*
       * choice to exit
       *
       * free all memories allocated dynamically
       */

   Employee * employee = NULL;
   free(employee);
   free(queue);
   break;
  
   default:
       /*
       * invalid choice
       */
       cout << "Invalid choice. Please enter it again." << endl;
  
   }
   }
   system("pause");
   return 0;

};


In: Computer Science