Questions
Rewrite the following Matlab code so it does the same thing but with complete new variable...

Rewrite the following Matlab code so it does the same thing but with complete new variable names and structure.


function stump = stumpGenerator(dataX, dataY, Dt)
intervals = 100;

rangex1 = max(dataX(:,1)) - min(dataX(:,1));
rangex2 = max(dataX(:,2)) - min(dataX(:,2));

width = (rangex1/intervals);
height = (rangex2/intervals);

starterx1 = min(dataX(:,1)) - (width/2);
starterx2 = min(dataX(:,2)) - (height/2);

currepsilon = inf;

stump = [0,0,0,1,0,0];

for i = 1:(intervals + 1)
  
horzRightError = sum(Dt(find(((dataX(:,1) - starterx1) .* dataY) < 0)));
horzLeftError = sum(Dt(find(((dataX(:,1) - starterx1) .* dataY) > 0)));
vertUpError = sum(Dt(find(((dataX(:,2) - starterx2) .* dataY) < 0)));
vertDownError = sum(Dt(find(((dataX(:,2) - starterx2) .* dataY) > 0)));
  
if (horzRightError <= horzLeftError)
horzError = horzRightError;
else
horzError = -horzLeftError;
end
  
if (vertUpError <= vertDownError)
vertError = vertUpError;
else
vertError = -vertDownError;
end
  
  
if (abs(horzError) <= abs(vertError))
if (currepsilon > abs(horzError))
currepsilon = abs(horzError);
stump(1) = 1;
stump(2) = 0;
stump(3) = starterx1;
stump(4) = horzError/(abs(horzError));
stump(5) = (log((1 - currepsilon)/currepsilon))/2;
stump(6) = currepsilon;
else
% do nothing, we already have the best stump
end
  
else
if (currepsilon > abs(vertError))
currepsilon = abs(vertError);
stump(1) = 0;
stump(2) = 1;
stump(3) = starterx2;
stump(4) = vertError/(abs(vertError));
stump(5) = (log((1/currepsilon) - 1))/2;
stump(6) = currepsilon;
else
% do nothing, we already have the best stump
end
end

starterx1 = starterx1 + width;
starterx2 = starterx2 + height;
end

end

In: Computer Science

Are the following languages regular languages or not ? Justify your answer with a proof. ?...

Are the following languages regular languages or not ? Justify your answer with a proof.

  1. ? = {? | ? represents an integer strictly greater than 2020}, on alphabet Σ = {0,…,9}.
  2. ? = {? | |?|a > |?|b} on alphabet Σ = {a,b}
  3. ? = {? | ? is the code of a LOOP program syntactically correct }
  4. ? = {02?| ? ∈ ℕ} sur alphabet Σ = {0}.

In: Computer Science

Write a C program that has a local and a global variable. The program uses a...

Write a C program that has a local and a global variable. The program uses a fork to create a child process. The parent process modifies both variables to be 10 and 20 and prints out the values. Then the child process modifies both variables to be 100 and 200 and prints out the values?
Explain the program output?

In: Computer Science

Discuss cabling and what you would use for a smaller Mom and Pop type business. Define...

Discuss cabling and what you would use for a smaller Mom and Pop type business. Define the business and how you would set up a network and what hardware and connection mechanisms need to be in place. How many computers would be needed? What other information do you need? (employees, locations, size, etc.)

In: Computer Science

What are the benefits and disadvantages of each of the following? Consider both the system level...

What are the benefits and disadvantages of each of the following? Consider both the system level and programmer level.

  1. Blocking send and non-blocking send in IPC
  2. Blocking receive and non-blocking receive in IPC
  3. zero-capacity and bounded capacity in IPC buffers

In: Computer Science

Write a python source code for a Unit class corresponding to the UML model of a...

Write a python source code for a Unit class corresponding to the UML model of a Unit shown. The description method should return a string value corresponding to the attributes of a Movie.

Unit

-code: String

-name: String

-credit points: int

+ __init__ (self, code, name, credit_points)

+ description (): String

In: Computer Science

PROBLEM: c++ code You are to write a program to tell you how many months it...

PROBLEM: c++ code

You are to write a program to tell you how many months it will take to pay off a loan, as well as the total amount of interest paid over the life of the loan.

You have just purchased a stereo system that costs $1000 on the following credit plan: No down payment, an interest rate of 18% per year (and hence 1.5% per month), and monthly payments of $50. The monthly payment of $50 is used to pay the interest and whatever is left is used to pay part of the remaining debt. Hence, the first month you pay 1.5% of $1000 in interest. That is $15 in interest. So, the remaining $35 is deducted from your debt which leaves you with a debt of $965.00. The next month you pay interest of 1.5% of $965.00, which is $14.48. Hence, you can deduct $35.52 (which is $50 - $14.48) from the amount you owe.

Write a program that will tell you how many months it will take you to pay off the loan, as well as the total amount of interest paid over the life of the loan. Use a loop to calculate the amount of interest and the size of the debt after each month. Put out the monthly amount of interest paid and remaining debt. Use a variable to count the number of loop iterations and hence the number of months until the debt is zero. You may want to use other variables as well.

You are to hand in:

  • a Title page
  • a Hierarchy Chart
  • a fully commented Program Listing
  • 3 sample runs (one run uses the above example, one run with your data, one run with invalid loan, interest rate and amount paid)
  • a User’s Guide (showing Purpose, Sample Input, Sample Output, Assumptions/Limitations)

A sample session may run as follows:

Enter the amount of the loan                           1000.00

Enter the yearly interest rate                           18.0

Enter the monthly amount paid                      50.00

Month                  Principle              Interest                 Principle              Remaining

Paid                      Paid                      Balance

              

1                            1000.00                15.00                    35.00                    965.00

2                            965.00                 14.48                    35.52                    929.48

3                            929.48                 13.94                    36.06                    893.42

.

.

24                             47.12                   0.71                    49.29                    -2.17

Number of months to pay of the loan:           24

Total interest paid on loan:                             197.83

You have a credit of:                                       -2.17

In: Computer Science

In C++ The greatest common divisor (GCD) of two integers in the largest integer that evenly...

In C++

The greatest common divisor (GCD) of two integers in the largest integer that evenly divides each of the numbers. Write a function called GCD that has a void return type, and accepts 3 parameters (first two by value, third by reference). The function should find the greatest common divisor of the first two numbers, and have the result as its OUTGOING value.

Write a main function that asks the users for two integers, and uses your function to find the greatest common divisor and then prints that value out.

In: Computer Science

Hi, I have created the following code and I was wondering if it is possible to...

Hi, I have created the following code and I was wondering if it is possible to make an "if" statement in the first for loop that would output an error if the user enters a float, character or string? I was thinking of something along the lines of: if(a[i] != int) but that didn't work :( Thank you.

#include <iostream>
using namespace std;
// Creating a constant for the number of integers in the array
const int size = 10;
int main()
{
// Assigning literals to the varibles
int a[size];
int sum=0;
float avg;
// For loop that will reiterate until all 10 integers are entered by the user
for(int i=0; i<size; i++)
{
cout<<"Enter integer value: ";
cin>>a[i];
}

cout<<"Your array contains the following numbers: "<<endl;
// For loop will display all the integers entered by the user
for(int i=0; i<size; i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
cout<<"From your list of 10 numbers:"<<endl;
// Determines the minimum integer entered
int min = a[0];
for(int i=1; i<size; i++)
{
if (min>a[i])
min=a[i];
}
// Displays the minimum
cout<<"The minimum is: "<<min<<endl;
// Determines the maximum integer entered by the user
int max = a[0];
for (int i=1; i<size; i++)
{
if (max<a[i])
max=a[i];
}
// Displays the maximum
cout<<"The maximum is: "<<max<<endl;
// Computes the sum of all the integers entered by the user
for (int i=0; i<size; i++)
{
sum+=a[i];
}
}
// Displays and computes the sum off all the integers
cout<<"The sum is: "<<sum<<endl;
// Computes the average of all the integers
avg = sum/10.0;
cout<<"Average is: "<<avg<<endl;
return 0;
}

In: Computer Science

Q1: What is the difference between function prototype and function definition in C++? Explain. Q2: What...


Q1: What is the difference between function prototype and function definition in C++? Explain.

Q2: What does function prototype consist off and what does function definition consists of? (hint: components)

Q3: Do the names of parameters have to agree in the prototype, definition, and call to the function? Why or why not, explain?

In: Computer Science

Write a class named Car that has the following fields: • yearModel: The yearModel field is...

Write a class named Car that has the following fields: • yearModel: The yearModel field is an int that holds the car's year model. • make: The make field is a String object that holds the make of the car. • speed: The speed field is an int that holds the car's current speed. In addition, the class should have the following methods: • Constructor: The constructor should accept the car's year model and make as arguments. These values should be assigned to the object's yearModel and make fields. The constructor should also assign 0 to the speed field. • Accessor: The appropriate accessor methods should be implemented to access the values stored in the object's yearModel, make, and speed fields. • accelerate: The accelerate method should add 5 to the speed field when it is called. • brake: The brake method should subtract 5 from the speed field each time it is called. Demonstrate the class in a program that contains a Car object, and then calls the accelerate method five times. After each call to the accelerate method, get the current speed of the car and print it on a separate line. Then, call the brake method five times, each time printing the current speed of the car on a separate line.

In: Computer Science

Using Java Calculating the tip when you go to a restaurant is not difficult, but your...

Using Java

Calculating the tip when you go to a restaurant is not difficult, but your restaurant wants to suggest a tip according to the service diners receive. Write a program that calculates a tip according to the diner’s satisfaction as follows:

•Ask for bill amount

•Ask for the diners’ satisfaction level using these ratings: 1 = Totally satisfied, 2 = Satisfied, 3 = Dissatisfied.

•If the diner is totally satisfied, calculate a 20 percent tip.

•If the diner is satisfied, calculate a 15 percent tip.

•If the diner is dissatisfied, calculate a 10 percent tip.

•Report the satisfaction level and tip in dollars and cents

Format tips to 2 decimal points; if the bill is 105$ and satisfaction level is 3, then the tip will be $10.50

In: Computer Science

Students in an institute have their name, id, and total score (out of 100) recorded. You...

Students in an institute have their name, id, and total score (out of 100) recorded. You are required to write a Python class to represent the student. Your code should display “Pass” or “Fail”, where the pass-score is above 60. Write the constructor, and other required methods to complete your code. Test the class by creating two objects of the class, where one student fails and the other passes.

In: Computer Science

Write a Python class to represent a Salik account. The account has three attributes, a name,...

Write a Python class to represent a Salik account. The account has three attributes, a name, id, and the balance. The balance is a private attribute. The class has extra functions to add to the balance and reduce the balance. Both, these functions should return the current balance and if the balance is below AED 50.0 print the message “Note: Balance Below 50”.

Your class must work for the code given below.

 
#Test
myCar = SalikAccount()
myCar.setName("John")
myCar.setID("190300300333")
myCar.setBal(20.0)

yourCar = SalikAccount("Ahmed", "102003993", 78.5)

myCar.addBalance(500)
yourCar.reduceBalance(40)

In: Computer Science

c++ input 10 number and calclute the midrange using (largest - smallest)/2.0. use for loop note...

c++
input 10 number and calclute the midrange using (largest - smallest)/2.0. use for loop
note : dont use arrays

In: Computer Science