In this program, use binary search to search for an element in 2D sorted matrix, the program should include binary search which has two arguments(element to search, and matrix as a List [List])
The Binary search function should return the row and column of the matrix if the element is found. Use a tuple to return the row and column. Return "Not Found" if the element is not exist
Please comment the code
Sample Input:
Case 1: binarysearch(4, [[1, 2, 3],[4, 5, 6],[7, 8, 9]] )
Case 2: binarysearch(10,[[2, 3, 4],[5, 7, 9],[11, 12, 13],[20, 22, 24]]
Sample Output :
Case 1: (1 , 0)
Case 2: Not Found
In: Computer Science
Research whether SYN cookies, or other similar mechanism, are supported on an operating system you have access to (e.g., BSD, Linux, MacOS, Windows). If so, determine whether they are enabled by default and, if not, how to enable them.
In: Computer Science
What would version control be for this piece of code in C++?
#include <iostream>
using namespace std;
int main()
{
int x = 5;
int *p = &x;
*p = 6;
int **q = &p;
int ***r = &q;
cout <<*p<<endl;
cout <<*q<<endl;
cout <<**q<<endl;
cout <<*(*r)<<endl;
cout <<*(*(*r))<<endl;
***r = 10;
cout <<x<<endl;
**q = *p + 2;
cout <<x<<endl;
return 0;
}
In: Computer Science
6.6 Lab: Rectangle Class
This program creates a Rectangle object, then displays the rectangle's
length,
width, and
area
Change this program to calculate and display the rectangle's
perimeter.
Example:
In feet, how wide is your house? 20 In feet, how long is your house? 25 The house is 20.00 feet wide. The house is 25.00 feet long. The house has 500.00 square feet of area. The house has 90.00 feet of perimeter.
/**
This program creates a Rectangle object, then displays the
rectangle's
- length,
- width, and
- area
Change this program to calculate and display the rectangle's
- perimeter.
*/
#include <iostream>
#include <iomanip>
using namespace std;
class Rectangle
{
private:
double width;
double length;
public:
// setters
void setWidth(double w) { width = w; }
void setLength(double len) {length = len; }
// getters
double getWidth() const { return width; }
double getLength() const { return length; }
// other functions
double calculateArea() const { return width * length; }
/* Write your code here */
};
int main()
{
double houseWidth; // To hold the room width
double houseLength; // To hold the room length
// Get the width of the house.
cout << "In feet, how wide is your house? ";
cin >> houseWidth;
// Get the length of the house.
cout << "In feet, how long is your house? ";
cin >> houseLength;
// Create a Rectangle object and use setters to assign values to
its data members
Rectangle house;
house.setWidth(houseWidth);
house.setLength(houseLength);
// Display the house's width, length, and area.
cout << setprecision(2) << fixed;
cout << endl;
cout << "The house is " << house.getWidth()
<< " feet wide.\n";
cout << "The house is " << house.getLength()
<< " feet long.\n";
cout << "The house has " << house.calculateArea()
<< " square feet of area.\n";
// Display the perimeter below
/* Write your code here */
return 0;
}
/***************************************************************
Save the OUTPUT below
*/
//Change the code only ever so slighty, not using advanced
algorithims
In: Computer Science
Design and implement a Java program to create a GUI application that for calculating an employee’s travel expenses and reimbursement. The user will enter the following data:
∙ Number of days on the trip
∙ Amount of the airfare, if any
∙ Amount of car rental fees, if any
∙ Number of miles driven, if a private vehicle is used
∙ Amount of parking fees, if any
∙ Amount of taxi charges, if any
∙ Conference or seminar registration fees, if any
∙ Lodging charges, per night
Once all expanses are entered the program should then calculate what the employee’s reimbursement will be based on the following guidelines:
∙ $17 per day for meals
∙ Parking fees, up to $10.00 per day
∙ Taxi charges up to $20.00 per day
∙ Lodging charges up to $95.00 per day
∙ If a private vehicle is used, $0.27 per mile driven
Once calculated your program should display the following information:
∙ Total expenses incurred by the business person
∙ The total allowable expenses for the trip
∙ The excess that must be paid by the business person, if any
∙ The amount saved by the business person if the expenses are under the total allowed
The layout and formatting of your GUI interface should be creative, attractive and easy to use.
In: Computer Science
I need this in C++ please. I started it, but I need to add Get Average, Get Row total, and Get highest in row to my source code. But I keep getting build errors. Can someone please help me with my code. I attached my code after the question. Thank you!
Write a program that create a two-dimensional array initialized with test data. The program should have the following functions:
getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array.
getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array.
getRowTotal - This function should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The function should return the total of the values in the specified row.
getColumnTotal - This function should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The function should return the total of the values in the specified column.
getHighestInRow - This function should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The function should return the highest value in the specified row in the array.
getLowestInRow - This function should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The function should return the lowest value in the specified row in the array.
Demonstrate each of the function in this program.
my source code:
#include <iostream>
using namespace std;
const int ROWS = 4;
const int COLS = 5;
int getTotal(int [][COLS], int, int);
int getColumnTotal(int [][COLS], int, int);
int getLowestInRow(int [][COLS], int, int);
int main()
{
int paArray[ROWS][COLS] = { {1, 2, 3, 4, 5}, {6, 7, 8,
9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20} };
cout << "The total equals " <<
getTotal(paArray, ROWS, COLS) << "\n";
cout << "The total of column 3 is " <<
getColumnTotal(paArray, 3, ROWS) << "\n";
cout << "The lowest in row 3 is " <<
getLowestInRow(paArray, 3, COLS) << "\n";
system("pause");
return 0;
}
int getTotal(int array[][COLS], int rows, int cols)
{
int sum = 0;
for (int row = 0; row < rows; row++)
{
for (int col = 0; col < cols;
col++)
sum +=
array[row][col];
}
return sum;
}
int getColumnTotal(int array[][COLS], int colToTotal, int
rows)
{
int sum = 0;
for (int row = 0; row < rows; row++)
{
sum +=
array[row][colToTotal];
}
return sum;
}
int getLowestInRow(int array[][COLS], int rowToSearch, int
cols)
{
int lowest = array[rowToSearch][0];
for (int col = 1; col < cols; col++)
{
if (array[rowToSearch][col] <
lowest)
lowest =
array[rowToSearch][col];
}
return lowest;
}
In: Computer Science
Financial technology, also known as FinTech is an industry composed of companies that use new technology and innovation with available resources in order to compete in the marketplace of traditional financial institutions and intermediaries in the delivery of financial services. The recent COVID 19 curfew period in Mauritius saw a huge surge in demand for such services, both for consumer and corporate use, as it helped to perform financial activities without risks of infection.
a) List at least 2 Fintech services that are provided by local companies in Mauritius. (1 mark)
b) List and explain two benefits of each Fintech services mentioned.
c) List and explain two possible drawbacks of each Fintech services mentioned.
d) Will Fintech have a very high adoption of active users in Mauritius by 2021? Debate.
In: Computer Science
why do I keep getting errors?
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const int CHEESE_PIZZA = 11;
const int SPINACH_PIZZA = 13;
const int CHICKEN_PIZZA = 14;
cout << "Assignment 07" << endl;
cout << "Program written by Carol" << endl <<
endl;
cout << " *********** MENU ***********" << endl;
cout << setw(9) << "ITEM" << setw(20) << "PRICE" << endl;
cout << " (1) Cheese Pizza" << setw(8) << "$"
<< CHEESE_PIZZA << endl;
cout << " (2) Spinach Pizza" << setw(7) << "$"
<< SPINACH_PIZZA << endl;
cout << " (3) Chicken Pizza" << setw(7) << "$"
<< CHICKEN_PIZZA << endl;
cout << endl;
cout << "What do you want? ";
int option;
cin >> option;
cout << "How many? ";
int quantity;
cin >> quantity;
int price;
switch (option)
{
case 1:
price = CHEESE_PIZZA;
break;
case 2:
price = SPINACH_PIZZA;
break;
case 3:
price = CHICKEN_PIZZA;
break;
default:
cout << "Please select valid item from menu. ";
break;
return 1;
}
int amount = price * quantity;
cout << "Your Bill: $ " << amount << endl;
cout << endl;
return 0;
In: Computer Science
Compare the State Pattern and the Strategy Pattern. What is the main difference? Explain their uses and provide an example of where you would use the State Pattern
In: Computer Science
C++ programming
please i need all codes in this homework
Homework
1) Call foo() three times to print below.
1 2
3 4
5 6
2) Modify the calculator in lect16 as follows using argument-passing functions.
....................
// function prototypes
void show_menu();
void add(int x, int y);
void sub(int x, int y);
.............
// function definitions
void main(){
int s;
for(;;){
show_menu();
scanf(“%d”, &s);
if (s==1){
int x, y;
printf(“enter two numbers\n”);
scanf(“%d %d”, &x, &y);
add(x, y);
}else if (s==2){
...............
}
.................
}
}
void show_menu(){
printf(“1. add 2. sub 3. square 4. factor_of 5. power 6. factor 7. quit\n”);
printf(“select operation\n”);
}
void add(int x, int y){
// print x+y
int z;
z=x+y;
printf(“the sum is %d\n”, z);
}
void sub(int x, int y){
// print x-y
.........
}
void square(int x){
// print x*x
........
}
void power(int x, int y){
// print x*x*...*x (y times)
........
}
void factor_of(int x, int y){
// if x is a factor of y, print “x is a factor of y”
// otherwise “x is not a factor of y”
// for example if x=3, y=12, x is a factor of y
// because 12%3 = 0
.......
}
void factor(int x){
// display all factors of x
...................
}
In: Computer Science
Answer the following question in Java.
Create a class called Movie. Move should contain:
Two instance variables: title of type String and rating of type int. Remember to encapsulate them.
Two constructors: One that takes a tile and rating as arguments and a copy constructor.
Getter and setter methods for both instance variables.
A method called getCategory that takes no arguments and return something of type char.
Additional information about the Movie class:
Title: The instance should always store the string in all upper case, if the method is called with a string that contains any lower case characters, the lower case characters should be converted to upper case.
Rating must be a value between 0 and 10 (inclusive). If the rating provided is outside of that range, the rating should remain unchanged.
getCategory: A movie is considered A category if its rating is 9 or 10, B category if the rating is 7 or 8, C category if the rating is 5 or 6, D category if the rating is 3 or 4 and F category otherwise.
In: Computer Science
What is the function for printVector that takes a vector of ints, and prints the values one after the other to screen, with commas in between the values.
For example,
vector<int> numbers{0,3,9};
printVector(numbers);
...should print out:
0,3,9
In: Computer Science
Suppose some FSM has 3 inputs, internal Ready, external
bus-grant Grant, and external bus-free Free signals, as well as 2
outputs, bus-request Req and bus-lock Lock signals. Show its
Moore-type state diagram, assuming that the FSM implements the
following bus protocol: (1) initially, the FSM outputs Req = 0 and
Lock = 0 and waits for both Ready and Free to be asserted; (2)
After receiving Ready = 1 and Free = 1, the FSM outputs Req = 1 and
Lock = 0 and waits for Grant to be asserted; (3) After receiving
Grant = 1, provided that both Ready and Free still equal 1, the FSM
outputs Req = 0 and Lock = 1 and waits for Ready to become 0; once
Ready = 0, the FSM returns to step (1).
NOTE: Should Ready and/or Free become 0 while waiting for Grant =
1, the FSM returns to step (1). The FSM ignores the Grant input in
steps (1) and (3), and it ignores the Free input in step (3).
In: Computer Science
c#
Create a class named TelpaMotion.
The inMotion field must not be accseible outside of the class. This fields can be initialized 3 different ways.
Default 67 mulltiplied by the value of 9.80665
A value being passed to it
A starting value and an acceleration rate can also be passed, the value should be multiplied by the acceleration rate to set the initial value.
Create a static field called tractionValue with a default value of 0.33.
In the same class create a public method called OverCompensate which allows your team to increase and return a result by multiplying the inMotion value by 1.5 and adding the tractionValue to the result (i.e. (inMotion *1.5)+tractionValue)
In your main method:
Call your class:
TelpaMotion optionA= new TelpaMotion();
TelpaMotion optionB= new TelpaMotion(100.45);
TelpaMotion optionC= new TelpaMotion(27.9, 0.321);
Using the object created for option c, call the OverCompensate method to assign the calculated value to a variable called emergencyStop and display the results. Option created Display to the console the results of each call to the class
In: Computer Science
Create a PDA accepting the following languages:
(a) {v$w$v R | w, v ∈ {0, 1} ∗}
(b) {w | in w, the number of 0’s is the same as the number of 1’s}.
In: Computer Science