Write two functions called permutation() and combination(), where permutation() computes and returns n!/(n-r)!whereas combination() returns. n!/(n-r)!r!A third function called par_input() gets the input values for n and r. An example of correct program behavior follows: Input: 3 2 Output: The permutation is 6, and the combination is 3.

Answers

Answer 1

Answer:

Here is the program in C.

#include<stdio.h>   // header file used to input output operations

int permutation(int n, int r);  // function to computer permutation

int combination(int n, int r);  //function to compute combination

int factorial(int number);  // function to computer factorial

void par_input(int n, int r);    // function take take input value of n and r

int main()  //start of main() function body

{    

   int n,r;  // declare n and r variables

   par_input(n,r);  //calls par_input() function to get values of n and r

}

 

int permutation(int n, int r)   // method to calculate permutation

{

   return factorial(n) / factorial(n-r);  //formula for permutation

}

 

int combination(int n, int r)  // method to calculate combination

{

   return permutation(n, r) / factorial(r); //formula for combination

}

 

int factorial(int number)  // to find factorial of a number

{

   int fact = 1;      

   while(number > 0)  //loop continues until value of number gets <=0

   {

       fact = fact *number;  

       number--;

   }      

   return fact;

}

void par_input(int n, int r)  //function to take input values

{

   printf("Enter n: ");  //prompts user to enter the value of n

   scanf("%d", &n);      //reads the value of n from user

   printf("Enter r: "); ////prompts user to enter the value of r

   scanf("%d", &r); //reads the value of r from user

  //calls the combination and permutation methods to display results

   printf("The permutation is = %d\n", permutation(n, r));    

   printf("The Combination is = %d", combination(n, r));      

}

Explanation:

The main() function calls par_input() function. This function asks user to enter values of n and r and then calls permutation() and combination() methods to compute the combination and permutation using these input values. Lets say user enters n=3 and r=2The permutation() function computes and returns permutation using the following formula: n! / (n-r)! factorial(n) / factorial(n-r); This function calls factorial method which calculates the factorial of n and n-r.This function then returns the permutation.3! / (3-2)! = 3*2*1 / 1! = 6Next the combination() function computes and returns combination using the following formula: n! / r! * (n - r)!permutation(n, r) / factorial(r)This function calls permutation() and factorial() methods which calculate the combination of n and n-rThis function then returns the combination.3! / 2! * (3-2)! = 3*2*1 / 2*1 * 1 = 6 / 2 = 3 Factorial function computes and returns the factorial of n, r and n-r.Lets take n! When n=3 So this function computes factorial as follows:while loops checks if number>0 It is true as number is 3It multiplies 3 by fact. fact is initialized to 1 So1*3 = 3Then it decreases number=3 by 1 so number=2Now while loops checks if number>0 It is true as number is 2It multiplies 2 by fact. Value of fact is now 3 So3*2 = 6Then it decreases number=2 by 1 so number=1Now while loops checks if number>0 It is true as number is 1It multiplies 1 by fact. Value of fact is now 6 So6*1 = 6Then it decreases number=1 by 1 so number=0Now while loops checks if number>0 It is false as number is 0So the loop breaks and the value of fact is returned.As fact= 6 So factorial of n is 6.

The output of the program is attached in the screen shot.

Write Two Functions Called Permutation() And Combination(), Where Permutation() Computes And Returns

Related Questions

What is wrong with line 1?

public class G
{
private int x;
public G() { x=3;}
public void setX(int val){
x=val;
}
public String toString(){
return ""+x;
}
}

public class H extends G
{
private int y;
public H() { y=4;}
public void setY(int val){
y=val;
}
public String toString() {
return ""+y+super.toString();
}
}

//test code in the main method
G bad = new H();
bad.setY(9); //line 1

Answers

Answer:

The set is a object of the class 'H' and the setY method is a member of G class which is not called by the object of H class.

Explanation:

If a user calls the G function which is not a private by the help of H class objects then it can be called. It is because all the public and protected methods of A class can be accessed by the B class if B extends the A-class.If any class is extended by the other class then the derived class holds the property of the base class and the public and protected method can be accessed by the help of a derived class object.The derived class object can be created by the help of base class like written in the "line 1".But the base class can not call the member of the derived class.

In this chapter, you saw an example of how to write an algorithm that determines whether a number is even or odd. Write a program that generates 100 random numbers and keeps a count of how many of those random numbers are even, and how many of them are odd.]

Answers

Answer:

// Program is written in Java Programming Language

// Comments are used for explanatory purpose

// Program starts here

public class RandomOddEve {

/** Main Method */

public static void main(String[] args) {

int[] nums = new int[100]; // Declare an array of 100 integers

// Store the counts of 100 random numbers

for (int i = 1; i <= 100; i++) {

nums[(int)(Math.random() * 10)]++;

}

int odd = 0, even = 0; // declare even and odd variables to 0, respectively

// Both variables will serve a counters

// Check for odd and even numbers

for(int I = 0; I<100; I++)

{

if (nums[I]%2 == 0) {// Even number.

even++;

}

else // Odd number.

{

odd++;

}

}

//.Print Results

System.out.print("Odd number = "+odd);

System.out.print("Even number = "+even);

}

Answer:

Complete python code along with comments to explain the whole code is given below.

Python Code with Explanation:

# import random module to use randint function

import random

# counter variables to store the number of even and odd numbers

even = 0

odd = 0

# list to store randomly generated numbers

random_num=[]

# A for loop is used to generate 100 random numbers

for i in range(100):

# generate a random number from 0 to 100 and append it to the list

   random_num.append(random.randint(0,100))

# check if ith number in the list is divisible by 2 then it is even

   if random_num[i] % 2==0:

# add one to the even counter

        even+=1

# if it is not even number then it must be an odd number

   else:

# add one to the odd counter

        odd+=1

# finally print the count number of even and odd numbers

print("Total Even Random Numbers are: ",even)

print("Total Odd Random Numbers are: ",odd)

Output:

Total Even Random Numbers are: 60

Total Odd Random Numbers are: 40

Total Even Random Numbers are: 54

Total Odd Random Numbers are: 46

The factorial of an integer N is the product of the integers between 1 and N, inclusive. Write a while loop that computes the factorial of a given integer N.

Answers

the function and loop will be

def factorial(x):

   total = 1

   if x != 1 and x != 0:

       for i in range(x,1,-1):

           total *= i

   return total

The program is an illustration of loops

Loops are program statements that are used to perform repeated operations

The program in python, where comments are used to explain each line is as follows:

#This gets input for N

N = int(input())

#This initializes factorial to 1

factorial = 1

#This opens the while loop

while N >1:

   #This calculates the factorial

   factorial*=N

   N-=1

#This prints the factorial

print(factorial)

Read more about loops at:

https://brainly.com/question/14284157

construct an AVL tree. For each line of the database and for each recognition sequence in that line, you will create a new SequenceMap object that contains the recognition sequence as its recognition_sequence_ and the enzyme acronym as the only string of its enzyme_acronyms_ main function

Answers

Answer:

Explanation:

AVL trees are used frequently for quick searching as searching takes O(Log n) because tree is balanced. Where as insertion and deletions are comparatively more tedious and slower as at every insertion and deletion, it requires re-balancing. Hence, AVL trees are preferred for application, which are search intensive.

The attached diagramm further ilustrate this

Your friend is an intern at the local Department of Health and needs to prepare a report about the recent activity of the influenza virus. She has recorded the number of cases of each type of flu (A, B, and C) over the last several weeks. Write a C program that will calculate the total cases for each week, determine the level of activity for the week (low, moderate, or widespread) and print a report to a file, including a small bar chart for the weekly cases.

Answers

Answer:

#include<bits/stdc++.h>

using namespace std;

int main(){

  // Defining Variables

  int no_of_weeks;

  int total_cases = 0;

  //Declaring Vector of Pair of Integer and string

  std::vector<pair<int,string>> data;

  // Taking Input for the Number of Weeks

  cout<<"Enter No. of Weeks\n";

  cin >> no_of_weeks;

  // Running the Loop for no_of_weeks times

  for(int i = 0; i < no_of_weeks ; i++){

      int A,B,C;

      // Taking Input for different types of flus

      cout<<"Enter No. of Cases of Flu A, B, C for week" << i + 1 << " seperated by space : \n";

      cin >> A >> B >>C;

      // Adding all the cases in a week

      int cases_in_a_week = A + B + C;

      // Updating total cases

      total_cases += cases_in_a_week;

      // Declaring the level variable

      string level;

      // Updating the level of the week corresponding to each case

      if(cases_in_a_week < 500) level = "Low";

      else if(cases_in_a_week >= 500 && cases_in_a_week < 2000) level = "Moderate";

      else level = "Widespread";

      // Storing the Week's information by using a vector of pairs

      // in which pair's first is the number of cases which is of type int

      // while the second is the level of the flu which is of the type string

      data.push_back(make_pair(cases_in_a_week,level));

  }

  // Linking the stdoutput to the flu_report.txt file

  // this also creates the file with the same name if it doesn't exists

  freopen("flu_report.txt", "w", stdout);

  // Printing the respective output data with Bar Chart of stars for each level

  for(int i = 0;i < no_of_weeks ; i++){

      //printing the week no. and number of cases

      cout<<i+1<<" "<<data[i].first<<" "<<data[i].second<<" |";

      //calculating the number of stars

      int stars = data[i].first/250;

      //printing the stars of the bar chart

      for(int j = 0; j < stars ; j++) cout<<"*";

      cout<<endl;

  }

  //printing the total number of cases

  cout<<total_cases;

}

Explanation:

Answer:

C code explained below

Explanation:

I have provided the proper commented code below.

I hope that you find the answer helpful.

CODE:

-------------------------------------------------------------------------------------------------------------

#include<bits/stdc++.h>

using namespace std;

int main(){

  // Defining Variables

  int no_of_weeks;

  int total_cases = 0;

  //Declaring Vector of Pair of Integer and string

  std::vector<pair<int,string>> data;

  // Taking Input for the Number of Weeks

  cout<<"Enter No. of Weeks\n";

  cin >> no_of_weeks;

  // Running the Loop for no_of_weeks times

  for(int i = 0; i < no_of_weeks ; i++){

      int A,B,C;

      // Taking Input for different types of flus

      cout<<"Enter No. of Cases of Flu A, B, C for week" << i + 1 << " seperated by space : \n";

      cin >> A >> B >>C;

      // Adding all the cases in a week

      int cases_in_a_week = A + B + C;

      // Updating total cases

      total_cases += cases_in_a_week;

      // Declaring the level variable

      string level;

      // Updating the level of the week corresponding to each case

      if(cases_in_a_week < 500) level = "Low";

      else if(cases_in_a_week >= 500 && cases_in_a_week < 2000) level = "Moderate";

      else level = "Widespread";

      // Storing the Week's information by using a vector of pairs

      // in which pair's first is the number of cases which is of type int

      // while the second is the level of the flu which is of the type string

      data.push_back(make_pair(cases_in_a_week,level));

  }

  // Linking the stdoutput to the flu_report.txt file

  // this also creates the file with the same name if it doesn't exists

  freopen("flu_report.txt", "w", stdout);

  // Printing the respective output data with Bar Chart of stars for each level

  for(int i = 0;i < no_of_weeks ; i++){

      //printing the week no. and number of cases

      cout<<i+1<<" "<<data[i].first<<" "<<data[i].second<<" |";

      //calculating the number of stars

      int stars = data[i].first/250;

      //printing the stars of the bar chart

      for(int j = 0; j < stars ; j++) cout<<"*";

      cout<<endl;

  }

  //printing the total number of cases

  cout<<total_cases;

}

The shipping charges per 500 miles are not prorated. For example, if a 2-pound package is shipped 550 miles, the charges would be $2.20. Write a program that asks the user to enter the weight of a package and then displays the shipping charges.

Answers

Answer:

The solution code is written in Python:

COST_PER_500MI = 1.1 weight = float(input("Enter weight of package: ")) total_cost = weight * COST_PER_500MI print("The shipping charges is $" + str(round(total_cost,2)))

Explanation:

Based on the information given in the question, we presume the cost per 500 miles is $1.10 per pound ($2.20 / 2 pound).

Create a variable COST_PER_500MI to hold the value of cost per 500 miles (Line 1). Next, prompt user input the weight and assign it to variable weight (Line 3). Calculate the shipping charge and display it using print function (Line 4-5).

Final answer:

A program to calculate shipping charges can be created by converting the weight of a package to ounces and using the provided rate structure. For a 2-pound package, the cost to ship would be $6.88, following the given rate system where the first 3 ounces cost $1.95 and each additional ounce costs $0.17. The per 500-mile charges are not prorated.

Explanation:

The given scenario requires the creation of a simple program that calculates shipping charges based on the weight of a package and the distance it needs to be shipped. According to the details, there's a flat rate for the first 3 ounces, and then an additional, per ounce charge after that. If a 2-pound package is shipped, we can calculate the cost based on the conversion of pounds to ounces, and then apply the pricing rules provided. Since there are 16 ounces in one pound, a 2-pound package would be equivalent to 32 ounces. The cost would then be computed as follows:

Total Cost = Base cost for first 3 ounces + (Number of additional ounces x Cost per additional ounce)

For a 32 ounce package, this would be:

Total Cost = $1.95 + (29 x $0.17) = $1.95 + $4.93 = $6.88

There is no need to prorate the charge per 500 miles as the example provided indicates a flat charge is applied per 500-mile increment. Handling user input correctly in a program is also essential to ensure the right calculations are made based on what the user enters for the package weight and distance.

Consider the following code: // Linked Lists: TRAVERSE

struct ListNode { int data; struct ListNode *next; };

Assume that a linked list has been created and head points to a sentinel node. A sentinel node is an empty data node in the beginning of the list. It sometimes holds a sentinel value. The use of sentinel nodes is a popular trick to simplify the insert and delete operations.

You may also assume that the list is not empty. Each node in the list contains an integer representing a digit in a number. The data in the sentinel node is -1.

For instance, n = 234 will be stored as {-1, 4, 3, 2} in the linked list.

Write a function based on the list traversal named computeNumFromList that is passed the pointer to the first node in the list, it prints the digits in the list one per line, and it returns a long integer, the number calculated from its digits in the list (234 see the above example). You may assume that long int will hold the converted number (no need to check for numeric overflow).

Answers

Answer:

See attached file for detailed code.

Explanation:

See attached file.

Write a function called name_facts that will take a firstname (string) as an input parameter, and print out various facts about the name, including:
1) its length, 2) whether it starts with the letter A, and 3) whether it contains a Z or X.
To gain full credit for this exercise, you must use string formatting to print out the result. Hints: You will probably want to convert the string to lowercase when checking conditions 2 and 3. You can get by without it, but you'll have to make sure you check both lower and uppercase versions of the letters. You will have to use the in operator for condition 3. You will also probably want to make a separate message for conditions 2 and 3 (depending on the answer) and use string formatting to join them into the final message.

Answers

Answer:

def name_facts(firstname):

   print("Your name is",len(firstname),"letters long",end=", ")

   if(firstname[0] == 'A'):

       print("does start with the letter A",end=", ")

   else:

       print("does not start with the letter A", end=", ")

   if(firstname.count('Z')>0 or firstname.count('X')>0):

       print("and does not contain a Z or X")

   else:

       print("and does not contain a Z or X")

#Testing

name_facts("Allegra")

name_facts("Xander")

Explanation:

Answer:

// Comments are used for explanatory purpose

// Program starts here

#include<iostream>

using namespace std;

int main()

{

// Declare firstname

string firstname;

//Prompt to enter firstname

cout<<"What's your first name: ";

// Accept input

cin>>firstname;

// A. Get string's length

int length = firstname.length();

// Print length

cout<<"Length = "<<length<<endl;

// Copy string to chat array

char char_array[length + 1];

// copying the contents of the string to char array

strcpy(char_array, firstname.c_str());

// B. Check if it starts with letter A

if(char_array[0] == 'A')

{

cout<<"Your Firstname begins with letter A"<<endl;

}

else

{

cout<<"Your Firstname doesn't begin with letter A"<<endl;

}

// Check if it contains X or Z

int k = 0;

for (int i = 0; i < n; i++) {

if(char_array[i] == 'Z' || char_array[i] == 'X')

{

k++;

}

if(k == 0)

{cout<<"Your Firstname doesn't contain Z or X";}

else

{cout<<"Your Firstname contains Z or X";}

}

return 0;

}

Modify the URL_reader.py program to use urllib instead of a socket. This code should still process the incoming data in chunks, and the size of each chunk should be 512 characters.

Answers

Answer:see the picture attached

Explanation:

Craig likes to work on his computer at his local coffee shop, but people around him may be able to see what he is doing, including entering passwords for his accounts. This method of gaining confidential information is referred to as ________.

(A) phishing
(B) shoulder surfing
(C) man-in-the-middle attacks
(D) spear phishing

Answers

Answer:

B

Explanation:

Craig could of left the coffee shop but instead he could just shoulder surfing so no one could see all the other options are just plain Wrong shoulder surfing can do no harm

Choose two prime numbers p and q (these are your inputs). Suppose that you need to send a message to your friend, and you implement the RSA algorithm for secure key generation. You need public and private keys (these are your outputs). You are free to choose other parameters or inputs if you need any. Write a program for the RSA algorithm using any programing language you know (such as C++) to generate your public and private key.

Answers

Answer:

#include <iostream>

#include<math.h>

using namespace std;

int findGcd(int x, int y) {

int t;

while(1) {

t= x%y;

if(t==0)

return y;

x = y;

y= t;

}

}

int main() {

int v1,v2,p,q,flag = 0;

cout<<"Please enter 1st prime number: ";

cin>>p;

v1 = p/2;

cout<<"Please enter 2nd prime number: ";

cin>>q;

v2 = q/2;

for(int i = 2; i <= v1; i++)

{

if(p%i == 0)

{

cout<<"The number is not prime";

flag = 1;

return 0 ;

}

}

for(int i = 2; i <= v1; i++)

{

if(q%i == 0)

{

cout<<"You entered a number which is not prime";

flag = 1;

return 0;

}

}

double n=p*q;

double tr;

double phi= (p-1)*(q-1);

double e=7;

if( flag == 0)

{

while(e<phi) {

tr = findGcd(e,phi);

if(tr==1)

break;

else

e++;

}

cout<<"public key: "<<e<<endl;

double d1=1/e;

double d=fmod(d1,phi);

cout<<"private key: "<<d<<endl;

double message;

cout<<"please enter a message: ";

cin>>message;

double cipher = pow(message,e);

double m = pow(cipher,d);

cipher = fmod(cipher,n);

m = fmod(m,n);

cout<<"Encrypted message: "<<cipher;

}

}

Explanation:

Find n = p*q and calculate phi = (p-1) * (q-1). Select a number e such that 1 < e < phi(n) and findGcd(e, phi(n)) = 1. Find d which is private key  as d = e−1 (mod phi(n)).As m is original message so encrypt using, cipher = m*e mod n.

Read the PIC Data sheet Chapter 2.0 and 3.0 2. List at least 3 big differences between the Flash and RAM 3. How many RAM locations are there and how many bits in each location 4. How many Flash locations are there and how many bits in each location 5. Based on the diagram in figure 2-1, what memory are the configuration words associated with 6. In section 3.5.2 there is a description of Linear Data Memory". This is accessed using indirect addressing via the registers FS0 or FSland it allows one to have an array or buffer that is more than 80 bytes long. Explain why this is needed. 7. When you access data RAM, you must always make sure that the BSR is pointing to the right memory bank if you are using the normal mode of direct addressing. Are there any locations in data RAM where you don't have to worry about having the right bank selected? Explain your answer.

Answers

Final answer:

Flash and RAM are two types of memory used in microcontrollers like PIC, with differences such as Flash being non-volatile and RAM being volatile. Configuration words are usually stored in Flash memory, and special linear data memory can be used for larger structures. Even while accessing data RAM, the Bank Select Register should typically be set to the correct bank, but some common areas are accessible from all banks.

Explanation:

1. Flash and RAM are two types of memories used in microcontrollers like PIC, with significant differences. Flash Memory, being non-volatile, retains its information even when power is turned off, generally used for storing the program. On the other side, RAM (Random Access Memory) is volatile and loses its information when power is removed, typically used for temporary storage during program execution.

2+3. The specific number of RAM and Flash locations, as well as the bit size at each location, depends on the specific PIC microcontroller model. In general, one could read these details from the datasheet for the specific part.

4. Configuration words are usually associated with the Flash memory, as they are used to set up certain parameters for the chip that remain constant during operation.

5. Linear Data Memory is important for larger data structures such as arrays or buffers that require more than 80 bytes. Having this extra memory space allows more complex calculations and data manipulations.

6. Lastly, when accessing data RAM with direct addressing, the correct memory bank that includes our desired memory location should be selected into the BSR (Bank Select Register). However, there are ‘common’ areas in data RAM accessible from all banks, typically which include Special Function Registers (SFRs) and some general purpose registers.

Learn more about Memory Management in Microcontrollers here:

https://brainly.com/question/33223494

#SPJ3

Write a test program that creates two Rectangle objects—one with width 4 and height 40 and the other with width 3.5 and height 35.7. Display the width, height, area, and perimeter of each rectangle in this order.

Answers

Answer:

public class Rectangle {

   private double width;

   private double heigth;

   public Rectangle(double width, double heigth) {

       this.width = width;

       this.heigth = heigth;

   }

   public double getWidth() {

       return width;

   }

   public void setWidth(double width) {

       this.width = width;

   }

   public double getHeigth() {

       return heigth;

   }

   public void setHeigth(double heigth) {

       this.heigth = heigth;

   }

   public double perimeter(double width, double heigth){

       double peri = 2*(width+heigth);

       return peri;

   }

   public double area(double width, double heigth){

       double area = width*heigth;

       return  area;

   }

}

class RectangleTest{

   public static void main(String[] args) {

       //Creating two Rectangle objects

       Rectangle rectangle1 = new Rectangle(4,40);

       Rectangle rectangle2 = new Rectangle(3.5, 35.7);

       //Calling methods on the first Rectangel objects

       System.out.println("The Height of Rectangle 1 is: "+rectangle1.getHeigth());

       System.out.println("The Width of Rectangle 1 is: "+rectangle1.getWidth());

       System.out.println("The Perimeter of Rectangle 1 is: "+rectangle1.perimeter(4,40));

       System.out.println("The Area of Rectangle 1 is: "+rectangle1.area(4,40));

       // Second Rectangle object

       System.out.println("The Height of Rectangle 2 is: "+rectangle2.getHeigth());

       System.out.println("The Width of Rectangle 2 is: "+rectangle2.getWidth());

       System.out.println("The Perimeter of Rectangle 2 is: "+rectangle2.perimeter(4,40));

       System.out.println("The Area of Rectangle 2 is: "+rectangle2.area(4,40));

   }

}

Explanation:

Firstly A Rectangle class is created with two fields for width and heigth, a constructor and getters and setters the class also has methods for finding area and perimetersThen a RectangleTest class containing a main method is created and two Rectangle objects are created (Follow teh comments in the code)Methods to get height, width, area and perimeter are called on each rectangle object to print the appropriate value

Write a switch statement that checks nextChoice. If 0, print "Rock". If 1, print "Paper". If 2, print "Scissors". For any other value, print "Unknown". End with newline.

Answers

Answer:

case 0:

           System.out.println("Rock");

           break;

       

        case 1:

           System.out.println("Paper");

           break;

       

        case 2:

           System.out.println("Scissors");

           break;

           

        default:

           System.out.println("Unknown");

           break;

       

     }

Explanation:

In this exercise we have to use the knowledge of computational language in python to describe a code, like this:

The code can be found in the attached image.

To make it easier the code can be found below as:

case 0:

          System.out.println("Rock");

          break;

case 1:

          System.out.println("Paper");

          break;

case 2:

          System.out.println("Scissors");

          break;

       default:

          System.out.println("Unknown");

          break;

    }

See more about python at brainly.com/question/26104476

We have seen in class that the sets of both regular and context-free languages are closed under the union, concatenation, and star operations. We have also seen in A2 that the regular languages are closed under intersection and complement. In this question, you will investigate whether the latter also holds for context-free languages.
(a) Use the languages A = {a^mb^nc^n \ m, n greaterthanorequalto 0} and B = {a^nb^nc^m \ m, n greaterthanorequalto 0} to show that the class of context-free languages is not closed under intersection. You may use the fact that the language C = {a^nb^nc^n | n greaterthanorequalto 0} is not context-free.
(b) Using part (a) above, show now that the set of context-free languages is not closed under complement.

Answers

Answer:

Attached is the solution. Hope it helps:

a) The class of context-free languages is not closed under intersection, as shown by the example of[tex]A = [ a^m b^n c^n | m, n \geq 0 ][/tex] and [tex]B = [a^n b^n c^m | m, n \geq 0 ][/tex]

Given that;

We have seen in class that the sets of both regular and context-free languages are closed under the union, concatenation, and star operations.

(a) We're given two languages A and B:

[tex]A = [ a^m b^n c^n | m, n \geq 0 ][/tex]

[tex]B = [a^n b^n c^m | m, n \geq 0 ][/tex]

We want to show that the intersection of A and B is not context-free.

To do this, we can use the fact that the language [tex]C = [a^n b^n c^n | n \geq 0 ][/tex] is not context-free.

Assume for contradiction that the intersection of A and B, which we'll call D, is context-free.

Since context-free languages are closed under intersection, we'd have D = A ∩ B is also a context-free language.

Now, notice that D is a subset of C (if a string belongs to D, it must belong to C as well).

However, C is not context-free, as given.

This contradicts our assumption that D is context-free.

Therefore, we can conclude that the class of context-free languages is not closed under intersection, as shown by the example of[tex]A = [ a^m b^n c^n | m, n \geq 0 ][/tex] and [tex]B = [a^n b^n c^m | m, n \geq 0 ][/tex]

(b) Using the result from part (a), we can now show that the set of context-free languages is not closed under complementation.

Let's consider the complement of a context-free language.

If the complement of a context-free language were always context-free, we could take the complement of C and obtain a context-free language.

However, as established earlier, C is not context-free.

Hence, we can conclude that the set of context-free languages is not closed under complementation.

Learn more about Programs here:

brainly.com/question/14368396

#SPJ3

Write a program that generates a random integer number in the range of 1 through 100 inclusively, and then asks the user to guess what the number is (User should be informed at the beginning that the number is between 1 to 100). If the user’s guess (input) is higher than the random number, the program should display "Too high, try again." If the user’s guess is lower than the random number, the program should display "Too low, try again." If the user guesses the number, the program should congratulate the user with a message as well as to display the number of guesses to get the right number. Next asking the user if he/she wants to play one more time. If yes, then generate a new random number so the game can start over

Answers

Answer:

Here is the Python program:

import random  #to generate random numbers

low = 1  #lowest range of a guess

high = 100  #highest range of a guess

attempts=0   # no of attempts

def guess_number(low, high, attempts):  #function for guessing a number

   print("Guess a number between 1 and 100")      

#prompts user to enter an integer between 1 to 100 as a guess

   number = random.randint(low, high)  

#return randoms digits from low to high

   for _ in range(attempts):  #loop to make guesses

       guess = input("Enter a number: ")   #prompts user to enter a guess

       num = int(guess)  #reads the input guess

       if num == number:  # if num is equal to the guess number

           print('Congratulations! You guessed the right number!')    

           command= input("Do you want to play another game? ")

#asks user if he wants to play another game

           if command=='Y':  #if user enters Y  

               guess_number(low,high,attempts)  #starts game again

           elif command=='N':  #if user types N

               exit() #exits the program

       elif num < number:   #if user entered a no less than random no

           print('Too low, Try Higher')  # program prompts user to enter higher no

       elif num > number: #if user entered a no greater than random no

           print('Too high, Try Lower') # program prompts user to enter lower no

       else:  #if user enters anything else

           print("You must enter a valid integer.")  

#if user guessed wrong number till the given attempts

   print("You failed to guess the number correctly in {attempts} attempts.".format(attempts=attempts))  

   exit() # program exits

Explanation:

The program has a function guess_number which takes three parameters, high and low are the range set for the user to enter the number in this range and attempts is the number of tries given to the user to guess the number.

random.randint() generates integers in a given range, here the range is specified i.e from 1 to 100. So it generates random number from this range.

For loop keeps asking the user to make attempts in guessing a number and the number of tries the user is given is specified in the attempts variable.

If the number entered by the user is equal to the random number then this message is displayed: Congratulations! You guessed the right number! Then the user is asked if he wants to play one more time and if he types Y the game starts again but if he types N then the exit() function exits the game.

If the number entered as guess is higher than the random number then this message is displayed Too high, Try Lower and if the number entered as guess is lower than the random number then this message is displayed Too low, Try Higher.

If the user fails to guess the number in given attempts then the following message is displayed and program ends. You failed to guess the number correctly in {attempts} attempts.

You can call this function in main by passing value to this function to see the output on the screen.

guess_number(1, 100, 5)

The output is shown in screenshot attached.

Write the definition of a method printAttitude, which has an int parameter and returns nothing. The method prints a message to standard output depending on the value of its parameter. If the parameter equals 1, the method prints disagree. If the parameter equals 2, the method prints no opinion. If the parameter equals 3, the method prints agree. In the case of other values, the method does nothing.

Answers

Answer:

void printAttitude (int pint){

if (pint == 1){

System.out.println("disagree");

}

if (pint == 2){

System.out.println("no opinion");

}

if (pint == 3){

System.out.println("agree");

}

}

Explanation:

Answer:

public class num4 {

   public static void main(String[] args) {

       int para =2;

       printAttitude(para);

   }

   static void printAttitude( int para){

       if(para==1){

           System.out.println("disagree");

       }

       else if (para == 2){

           System.out.println("no option");

       }

       else if (para==3){

           System.out.println("agree");

       }

   }

}

Explanation:

Using Java Programming language:

Three if and else if statements are created to handle the conditions as given in the question (1,2,3) The output of disagree, no option and agree respectively is displayed using Java's output method System.out.println When these conditions are true

No else statement is provided to handle situations when the parameter value is neither (1,2,3), as a result, then program will do nothing and simply exits.

Consider a point to point link 50 km in length. At what speed would propagation delay (at a speed 2 x 108 meters/second) equal transmit delay for 100 byte packets.

Answers

Answer:

The bandwidth is 3200 Kbps

Explanation:

Given:

The length of the point to point link = 50 km = 50×10³ = 50000 m

Speed of transmission = 2 × 10⁸ m/s

Therefore the propagation delay is the ratio of the length of the link to speed of transmission

Therefore,  [tex]t_{prop} = \frac{distance}{speed}[/tex]

[tex]t_{prop} = \frac{50000}{2*10^{8} }=2.5*10^{-4}[/tex]

Therefore the propagation delay in 25 ms

100 byte = (100 × 8) bits

Transmission delay = [tex]\frac{(100*8)bits }{(x)bits/sec}[/tex]

If propagation delay is equal to transmission delay;

[tex]\frac{(100*8)bits }{(x)bits/sec}= \frac{50000}{2*10^{8} }[/tex]

[tex]x=\frac{100*8*2*10^{8} }{50000}[/tex]

[tex]x=\frac{100*8}{2.5*10 ^-4}=3200000[/tex]

x = 3200 Kbps

Answer:

The complete question is here:

Consider a point-to-point link 2 km in length. At what bandwidth would propagation delay (at a speed of 2 x 108 m/s) equal transmission delay for

(a) 100-byte packets?

(b) 512-byte packets?

Explanation:

Given:

Length of the link = 50 km

Propagation delay = distance/speed = d/s

To find:

At what speed would propagation delay (at a speed 2 x 10^8 meters/second) equal transmit delay for 100 byte packets?

Solution:

Propagation Delay = t prop

                                 = 50 * 10^3 / 2 * 10^8

                                 = 50000 / 200000000

                                 = 0.00025

                                 = 25 ms

(a) When propagation delay is equal to transmission delay for 100 packets:

Transmission Delay = packet length / data rate = L / R

So when,

Transmission Delay = Propagation Delay

100 * 8  / bits/sec = 50 * 10^3  / 2 * 10^8

Let y denotes the data rate in bit / sec

speed = bandwidth = y bits/sec

         100 * 8  / y bits/sec = 50 * 10^3  / 2 * 10^8

                        y bit/sec   =  100 * 8  / 25 * 10^ -5

                                         = 800 / 0.00025

                                     y  = 3200000 bit/sec

                                      y = 3200 Kbps

(b) 512-byte packets

512 * 8  / y bits/sec = 50 * 10^3  / 2 * 10^8

                        y bit/sec   =  512 * 8  / 25 * 10^ -5

                                         = 4096 / 0.00025

                                     y  = 16384000 bit/sec

                                      y = 16384 Kbps

Consider the following program:

void fun1(void); /* prototype */
void fun2(void); /* prototype */
void fun3(void); /* prototype */
void main() {
int a, b, c;
...
}
void fun1(void) {
int b, c, d;
...
}
void fun2(void) {
int c, d, e;
...
}
void fun3(void) {
int d, e, f;
...
}

Given the following calling sequences and assuming that dynamic scoping is used, what variables are visible during the execution of the last subprogram activated? Include with each visible variable the name of the unit where it is declared.
1. main calls sub1; sub1 calls sub2; sub2 calls sub3.
2. main calls sub1; sub1 calls sub3.
3. main calls sub2; sub2 calls sub3; sub3 calls sub1.
4. main calls sub3; sub3 calls sub1.
5. main calls sub1; sub1 calls sub3; sub3 calls sub2.

Answers

Answer:

Following are the variables which is visible in when the last module is called:

d,e,fd,e,fb,c,db,c,dc,d,e

Explanation:

Missing information :

The above question option needs to holds the function name as fun1,fun2 or fun3, but the options are holding the sub1,sub2, and sub3.The above question asked about the variable when the last function is called. The explanation of the visible variable is as follows:For the first option, the last function is called is fun3 which holds the variable as d,e, and f, and no variable is passed as the argument, So currently visible variable are d,e, and f.For the second option, the last function is called is fun3 which holds the variable as d,e, and f, and no variable is passed as the argument, So currently visible variable are d,e, and f.For the third option, the last function is called is fun1 which holds the variable as b,c and d and no variable is passed as the argument, So currently visible variable are b,c, and d.For the fourth option, the last function is called is fun1 which holds the variable as b,c and d and no variable is passed as the argument, So currently visible variable are b,c, and d.For the fifth option, the last function is called is fun2 which holds the variable as c,d and e and no variable is passed as the argument, So currently visible variable are c,d, and e.

Choose the correct code assignment for the following scenario:
15-year-old seen in the ER after being kicked by another soccer player today on a soccer field at the state soccer play-off tournament game.

a) W50.0XXA, Y92.213, Y93.66
b) W50.0XXA, Y92.322, Y93.6A
c) W50.1XXA, Y92.322, Y93.66
d) W50.1XXA, Y92.213, Y93.6A.

Answers

Answer:

C

Explanation:

W50.1XXA, Y92.322, Y93.66

Cheers

Define the body of the function read_data(filename). If filename is None, return the sentence (already defined for your), otherwise return the contents of the file (whose name is in the parameter filename). If there is any error during the opening or reading of the file, print out a warning and return sentence. If you haven't completed the lesson on Python local I/O, do so now.

Answers

Answer:

Answer explained

Explanation:

The main difference between parse_text_into_words( v1 and v2) is I have used splitlines also in v1 so the escape sequence '\n' will not be present in the list of words. while in v2 only split function is used so it will have '\n' present in words list.

Code:

def read_file(fileName = None):

  try:

      File = open(fileName,"r") # opening file in read mode

      for row in File:          # for each line in File

          print(row,end="")

  except IOError:      # handling exception of file opening

      print("Could not read file:",fileName)

def parse_text_into_words_v1(text):

  list_words = []

  list_lines = text.splitlines()

  for i in list_lines:

      list_words.extend(i.split(' '))

  return list_words

def parse_text_into_words_v2(text):

  list_words = []

  list_words.extend(text.split(' '))

  return list_words

def determine_difference(a_list,b_list):

  print("first list:",a_list)

  print("second list:",b_list)

  a_set = set(a_list)

  b_set = set(b_list)

  diff = a_set - b_set

  diff = list(diff)

  print("\nDifference between 2 sets: ",diff)

if __name__ == '__main__':

  print("Reading file using function read_file() to read \"data.txt\" :")

  read_file("data.txt")

  print("\n\n")

  t = '''vhfhyh ghgggj ghchvjhvj'''

  print("\nDemonstrating implementation of parse_text_into_words_v1:")

  l = parse_text_into_words_v1(t) # calling function with text parameter

  print("list of words:")

  print(l)

  print("\nDemonstrating implementation of parse_text_into_words_v2:")

  b = parse_text_into_words_v2(t) # calling function with text parameter

  print("list of words:")

  print(b)

  print("\nDemonstrating difference between two lists")

  a_list = [1,2,3,4,5,6,7,8,9,10]

  b_list = [2,4,6,8,10]

  determine_difference(a_list,b_list) # passing two list to take difference

When it comes to social media technologies and formal learning in the corporate environment, the only social media platform that can be used effectively for teaching and learning purposes is Twitter (Steer, 2015).

Answers

Ootions: TRUE OR FALSE

Answer: FALSE

Explanation: According to (Steer,2015) there are many platforms for learning and teaching purposes in corporate Organisations, they include PINTEREST,WIKI,GOOGLE+, LINKEDIN,TWITTER etc, The social media platforms are available for effective and efficient Communication and has been the main driving force for Businesses the world over.

These social media platforms have aided the growth and expansion of product marketing strategies and enhanced the over all business efficiency.

Search online for a Request for Proposal relating to IT. Critically evaluate the proposal. If you were a vendor receiving this proposal, do you have enough information to reply with a quote. What is good? What is missing? What would you change?

Answers

Answer and Explanation:

The company of that same Pasadena area thereafter named as "Center" allows RFP to apply regarding contracts for Contractor, but should not be restricted to providing the information infrastructure facilities to complement the Centre's in-house development solutions at either the optimum level of benefits.The contractor or provider shall offer the best facilities on just the basis of the services listed in the preceding documentation by sending two formal submissions no earlier than noon 14 December 2016 to certain stakeholders are encouraged to react towards this RFP.Sure I would also have bought that if I were a dealer since it is worth the investment.

So, it's the right answer.

A company is utilizing servers, data storage, data backup, and software development platforms over an Internet connection.

Which of the following describes the company’s approach to computing resources?

a. Cloud computing

b. Client-side virtualization

c. Internal shared resources

d. Thick client computing

Answers

Answer:

The answer is A. Cloud computing

Explanation:

Cloud computing is the process of using the internet to store, mange and process data rather than using a local server or a personal computer.

The term  cloud computing is generally used to describe data centers available to many users over the Internet.  

Therefore the company's approach to computing resources can be said to be cloud computing because it uses the internet  for data storage, data backup, and software development  

What term is defined as a private data placed in a packet with a header containing routing information that allows the data to travel across a network, such as the Internet?

Answers

Answer:

Data encapsulation

Explanation:

When we send data to someone else across another network, this data travels down a stack of layers of the TCP/IP model. Each layer of the TCP/IP layer encapsulates data or hides the data by adding headers and sometimes trailers. This packaging is what is known as data encapsulation. The data starts at the application layer and trickles down beneath. As it moves down the layers, it is encoded or compressed to a standard format and sometimes encrypted for security purposes.

A company ABC asked you to design a simple payroll program that calculates and employee's weekly gross pay, including any overtime wages. If employees work over 40 hours in a week, they will get 1.5 times of their regular hourly rate for all hours over 40. Your program asks the user to input hours worked for a week, regular hourly rate, and then display the weekly gross pay. Draw the Raptor flowchart to represent the logic of the problem. Name the Raptor flowchart file as lab5.rap. Output sample Enter weekly hours worked: 35 Enter hourly rate: 30 Weekly gross pay: $ 1050 Output sample Enter weekly hours worked: 50 Enter hourly rate: 30 Weekly gross pay: $ 1650

Answers

Answer:

C++.

#include <iostream>

using namespace std;

////////////////////////////////////////////////////////////////

int main() {

   int weekly_hours = 0;

   int hourly_rate;

   float gross_pay = 0;

   cout<<"Enter weekly hours worked: ";

   cin>>weekly_hours;

   

   cout<<"Enter hourly rate: ";

   cin>>hourly_rate;

   

   cout<<endl;

   ////////////////////////////////////////////////

   if (weekly_hours > 40) {

       gross_pay = (weekly_hours*hourly_rate) + ((weekly_hours*hourly_rate)*0.5);

   }

   else

       gross_pay = weekly_hours*hourly_rate;

       

   cout<<"Weekly gross pay: $"<<gross_pay;

   ////////////////////////////////////////////////

   return 0;

}

Given three dictionaries, associated with the variables, canadian_capitals, mexican_capitals, and us_capitals, that map provinces or states to their respective capitals, create a new dictionary that combines these three dictionaries, and associate it with a variable, nafta_capitals.Use python and dictionary. Write code in simplest form.

Answers

Answer:

canadian_capitals = {"Alberta":"Edmonton", "British Columbia":"Victoria", "Manitoba":"Winnipeg"}

mexica_capitals ={"Aguascalientes":"Aguascalientes", "Baja California":"Mexicali", "Baja California Sur":"La Paz"}

us_capitals ={"Alabama":"Montgomery", "Alaska":"Juneau", "Arizona":"Phoenix"}

nafta_capitals = {}

nafta_capitals.update(canadian_capitals)

nafta_capitals.update(mexica_capitals)

nafta_capitals.update(us_capitals)

print(nafta_capitals)

Explanation:

The code is written in python.

canadian_capitals = {"Alberta":"Edmonton", "British Columbia":"Victoria", "Manitoba":"Winnipeg"}   I created the first dictionary with the variable name called canadian_capital.  Notice the province of Canada is mapped to to their respective capitals.

mexica_capitals ={"Aguascalientes":"Aguascalientes", "Baja California":"Mexicali", "Baja California Sur":"La Paz"}   I created the second dictionary with the variable name called mexican_capital. The states are also mapped to their respective capitals.

us_capitals ={"Alabama":"Montgomery", "Alaska":"Juneau", "Arizona":"Phoenix"}   I created the third dictionary with the variable name called us_capital.  The states are also mapped to their respective capitals.

nafta_capitals = {}  This is an empty dictionary with the variable name nafta_capitals to combine the 3 dictionaries.

nafta_capitals.update(canadian_capitals)  I updated the empty dictionary with the canadian_capitals dictionary.

nafta_capitals.update(mexica_capitals)  I also added the mexica_capitals dictionary to the nafta_capitals dictionary.

nafta_capitals.update(us_capitals)  I also added the us_capitals dictionary to the nafta_capitals dictionary.

print(nafta_capitals)   The whole 3  dictionaries have been combined to form the nafta_capitals dictionary. The print function displays the already combine dictionaries.

Chapter 4 is called Claimed Spaces: ""Preparatory Privilege"" and High School Computer Science. Explain two concepts from chapter 4 that create ‘claimed spaces’ (2-3 sentences). Describe an example from your own experience of a claimed space (2-3 sentences)

Answers

Answer: isolation, predominant gender.

Explanation:

Isolation some students felt they were not as smart as their peers and as such were afraid to make contributions because they didn't want to be rediculed by Their peers or tutors.

Predominant gender most calsses are dominated by a certain gender which makes the other gender harbour fears and insecurity

I had difficulty in maths in high school, was always afraid when in class to make contributions because i was insecure, if i had spoken up or met my tutors maybe i would have being better at it

Once sales are​ forecasted, ________ must be generated to estimate required raw materials. A. a pro forma statement B. a production plan C. a cash budget

Answers

Answer:

Option B i.e., a production plan.

Explanation:

While sales are estimated, the manufacturing schedule for estimating the necessary raw materials should be produced.

So when the revenue is already estimated then at that time the manufacturing schedule should be produced approximately that raw material which is needed, so the following option is correct according to the scenario.

Option a is incorrect because it is not related to the following scenario.Option B is incorrect because in the above statement, it is not mentioned or related to the budget plan.

Write a SELECT statement that returns two columns based on the Vendors table. The first column, Contact, is the vendor contact name in this format: first name followed by last initial (for example, "John S.") The second column, Phone, is the VendorPhone column without the area code. Only return rows for those vendors in the 559 area code. Sort the result set by first name, then last name.

Answers

The answer & explanation for this question is given in the attachment below.

The SQL query selects vendor contacts' first names followed by last initials and phone numbers without area codes from the Vendors table. It filters vendors with the 559 area code and sorts results alphabetically by first name and last name.

Below is the SQL SELECT statement that fulfills your requirements:

```sql

SELECT

   CONCAT(SUBSTRING_INDEX(ContactName, ' ', 1), ' ', LEFT(SUBSTRING_INDEX(ContactName, ' ', -1), 1), '.') AS Contact,

   SUBSTRING(VendorPhone, 5) AS Phone

FROM

   Vendors

WHERE

   VendorPhone LIKE '559%'

ORDER BY

   SUBSTRING_INDEX(ContactName, ' ', 1),

   SUBSTRING_INDEX(ContactName, ' ', -1);

```

This query selects the ContactName column from the Vendors table, concatenates the first name and the first letter of the last name, followed by a period, to create the Contact column.

It then extracts the phone number without the area code from the VendorPhone column and stores it in the Phone column.

Finally, it filters the results to include only vendors with the 559 area code and sorts the result set by first name and last name.

Other Questions
A data set consists of the following data points:(2,4),(4,7), (5, 12)The line of best fit has the equation y = 2.5x - 1.5. What does this equationpredict for a value of x = 7?0O A. 16O B. 19O C. 20.5O D. 1750 0 0 A certain drug prevents a neurotransmitter from initiating a response in the receiving neuron. Which of the following statements best describes the mechanism by which the drug may be acting?a) The drug is preventing the neurotransmitter from binding to its receptors in the receiving neuron.b) The drug is causing more neurotransmitter molecules to be released.c) The drug is preventing the neurotransmitter from being degraded.d) All of the listed responses describe how the drug may be acting. Averi was trying to factor 4x2 + 20x - 16. She foundthat the greatest common factor of these terms was 4and made an area model:What is the width of Averi's area model? A trireme is an on-ground battering ram used by the Greeks. True False An automated assembly robot that cost $400,000 has a depreciable life of 5 years with a $100,000 salvage value. The MACRS depreciation rates for years 1, 2, and 3 are 20%, 32% and 19.2% respectively. What is the book value at the end of year 6 9. Jady got a job at Yogurt land. She makes $17 per hour as a store manager. On Friday she worked 6 hours, on Sundayshe worked 4 hours and on Wednesday she worked 5 hours. When she picked up her paycheck her mom reminded herthat she owed her $65 for a pair of shoes she bought her. How much money did she have left after paying back hermom (before taxes)? steps ? Dennis requests his father to buy him a PlayStation for his birthday. With respect to consumer decision roles, which role is Dennis currently playing? Policies, such as building height requirements, can affect urban sprawl. A) True B) False The drawing shows an electron entering the lower left side of a parallel plate capacitor and exiting at the upper right side. The initial speed of the electron is The capacitor is cm long, and its plates are separated by 0.150 cm. Assume that the electric field between the plates is uniform everywhere and find its magnitude. 16k + 24, can you show work? Assume a company does not elect the fair value option for reporting financial assets. Realized gains from the sale of marketable debt securities should be included in net income of the period of sale when the marketable debt securities portfolio of which they are a part is classified asa. Available-for-saleb. Abailable-for-sale or Held-to-maturityc. Held-to-maturityd. Neither A rep at the firm has been working on determining appropriate investments for a client. The rep comes to the conclusion that a deferred variable annuity will be the best choice for this particular client. What determination must be documented by the rep in relation to the investment in the deferred variable annuity under FINRA Regulations? Davy Company had a beginning work in process inventory balance of $32,000. During the year, $54,500 of direct materials was placed into production. Direct labor was $63,400, and indirect labor was $19,500. Manufacturing overhead is applied at 125% of direct labor costs. Actual manufacturing overhead was $86,500, and jobs costing $225,000 were completed during the year. What is the ending work in process inventory balance Anchorage Marina in Bay Harbor sponsors a fishing tournament that the crew of the Chimera enters. The prizes include cash and discount certificates for nautical equipment. Under the principles discussed in "A Sample Court Case," Fehr v. Algard, the offer of a prize in a contest isA. a binding contract in favor of a contestant who complies by the rules.B. a duty to be obeyed that is defined by the risk perceived.C. an equitable remedy that a modern trial court may or may not grant.D. a wager in favor of its offeror that is unenforceable at law. Which of the following statements is false? Each class can define a constructor for custom object initialization. A constructor is a special member function that must have the same name as the class. C++ requires a constructor call for every object thats created. A constructor cannot specify parameters. Suppose that you need to access a data file named "students.txt" to hold student names and GPAs. If the user needs to look at the information in the file, which command could be used to open this file? Solve the equation by graphing. If exact roots cannot be found, state the consecutive integers between which the rootsare locatedx2 + 3x -4 = 0 Researchers have ridden alongside motorcycle enthusiasts to understand the relationship between riders and their beloved Harley-Davidsons. This is an example of ________ research. Which process involves tracking team member performance, motivating team members, providing timely feedback, resolving issues and conflicts, and coordinating changes to help enhance project performance? If A varies directly as b and A=6, when b=1/3, find the equation that relates A and b.