Objectives
To apply pattern matching algorithm concepts.
To write the program to represent a Karp-Rabin method
Problem
You are to implement the Karp-Rabin string search algorithm. Your
program will prompt for the name of an input file and then read and
process the data contained in this file. The file contains two
sequences of characters. The first is the target sequence, T, the
second is the search sequence S. Read both strings and find all
occurrences of sequence S in sequence T using the Karp- Rabin
algorithm. For each matched sequence, print the location of the
first matched character in T.
For example, if the test data looked like this: ACGTACGTACCAGTA AC
T
he output should be: 0, 4, 8
Notes: 1. The sequence T is no longer than 500 characters
2. The sequence S is no longer than 10 characters
has to be written in java
In: Computer Science
List three (3) internal stakeholders and three (3) external stakeholders that may be involved in developing programs and describe how could facilitate their input in program development.
In: Computer Science
JAVA
Write a method that removes the duplicate elements from an array list of integers using the following header:
public static void removeDuplicate(ArrayList list)
Write a test program that prompts the user to enter 10 integers to a list and displays the distinct integers separated by exactly one space.
Here is a sample run:
Enter ten integers: 10 20 30 20 20 30 50 60 100 9
The distinct integers are: [10, 20, 30, 50, 60, 100, 9]
In: Computer Science
Write a program that reads a Java source file and produces an index of all identifiers in the file. For each identifier, print all lines in which it occurs. For simplicity, we will consider each string consisting only of letters, numbers, and underscores an identifer. Declare a Scanner in for reading from the source file and call in.useDelimiter("[^AZa-z0-9_]+"). Then each call to next returns an identifier.
Java. Explain logic used lease.
In: Computer Science
Write a complete Java program which takes vertices and edges of an undirected graph from the input file input.txt (the graph as adjacency matrix) ,(adjacent vertics of every vertex ),(DFS traversal of the graph),(BFS traversal of the graph),(Graph is connected or not connected)
In: Computer Science
C++ coding functions
Implement the following class using linked
lists. Creating a simple linked list class to use is
probably your
first step.(Please do not use collections like .push() . pop(),
etc.) and instead create the implementation
A templated stack class that stores
type T with the following public functions:
- void Push(T t) - adds t to the top of the
stack
- T Pop() - asserts that the stack is not empty
then removes and returns the item at the top of the stack.
- T Peek() - asserts that the queue is not empty
then returns the item at the top of the stack without removing
it.
- unsigned int Size() - returns the number of items currently in the stack
In: Computer Science
i am looking to add more detail into my program the runs a game of rock paper scissors
i want to include a function or way to ask the user to input their name so that it could be shown in the results at the end of a round/game.
after a round something like "Mike wins!"
i also want to output the round number when the result of for each round is outputed
Round 1: Mike Wins!
Round 2: Computer wins!
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <vector>
#include <ctime>
using namespace std;
int getCpu();
int getComputerChoice();
int getPlayerChoice();
bool isTie(int, int);
bool isPlayerWinner(int, int);
int menu();
void runGame();
int main()
{
runGame();
return 0;
}
void runGame()
{
int userChoice;
int playerChoice;
int computerChoice;
int rounds;
vector <string> winner;
do
{
winner.clear();
userChoice = menu();
if (userChoice == 1)
{
do
{
cout<<"\n Enter how many rounds to play? ";
cin>>rounds;
if(rounds % 2 == 0)
break;
else
cout<<"\n Enter a even number of rounds. \t Try
again!!";
}while(1);
for(int c = 0; c < rounds; c++)
{
playerChoice = getPlayerChoice();
computerChoice = getComputerChoice();
if (isTie(playerChoice, computerChoice))
cout << "It's a TIE!\n\n";
else if (!isPlayerWinner(playerChoice, computerChoice))
{
cout << "Sorry you LOSE.\n\n";
winner.push_back("Computer WIN!");
}
else if (isPlayerWinner(playerChoice, computerChoice))
{
winner.push_back("Player WIN!");
cout << "You WIN!\n\n";
}
}
cout<<"\n ********** Final Result (Player vs. Computer)
********** ";
for(int c = 0; c < winner.size(); c++)
cout<<"\n"<<winner[c];
}
else if (userChoice == 2)
{
do
{
cout<<"\n Enter how many rounds to play? ";
cin>>rounds;
if(rounds % 2 == 0)
break;
else
cout<<"\n Enter a even number of rounds. \t Try
again!!";
}while(1);
for(int c = 0; c < rounds; c++)
{
playerChoice = getCpu();
computerChoice = getComputerChoice();
if (isTie(playerChoice, computerChoice))
cout << "It's a TIE!\n\n";
else if (!isPlayerWinner(playerChoice, computerChoice))
{
cout << "Player 2 WIN!\n\n";
winner.push_back("Player 2 WIN!");
}
else if (isPlayerWinner(playerChoice, computerChoice))
{
cout << "Player 1WIN!\n\n";
winner.push_back("Player 1 WIN!");
}
}
cout<<"\n ********** Final Result (Computer vs. Computer)
********** ";
for(int c = 0; c < winner.size(); c++)
cout<<"\n"<<winner[c];
}
else if(userChoice == 3)
exit(0);
else
cout << "Invalid selection. Try again.\n\n";
}while(1);
}
int menu()
{
int userChoice;
cout << "\n\n Welcome to rock paper scissors" <<
endl;
cout <<"Please select a game mode" << endl;
cout << "1. Player vs. Computer" << endl;
cout << "2. Computer vs. Computer" << endl;
cout << "3. Exit" << endl;
cin >> userChoice;
return userChoice;
}
int getComputerChoice()
{
srand(time(NULL));
int randomCompNum = rand() % 3 + 1;
if (randomCompNum == 1)
{
cout << "The computer chose : Rock\n\n";
}
else if (randomCompNum == 2)
{
cout << "The computer chose : Paper\n\n";
}
else if (randomCompNum == 3)
{
cout << "The computer chose : Scissors\n\n";
}
return randomCompNum;
}
int getCpu()
{
srand(time(NULL));
int cpu = rand() % 6;
if (cpu == 1 || cpu == 4)
{
cout << "player 1 chose : Rock\n\n";
}
else if (cpu == 2 || cpu == 5)
{
cout << "player 1 chose : Paper\n\n";
}
else if (cpu == 3 || cpu == 6)
{
cout << "player 1 chose : Scissors\n\n";
}
return cpu;
}
int getPlayerChoice()
{
int myChoice;
cout<< "\n\nRock, Paper, or Scissors?\n"
<< "1) Rock\n"
<< "2) Paper\n"
<< "3) Scissors\n"
<< "Please enter your choice : \n";
cin >> myChoice;
if (myChoice == 1)
{
cout << "\nYou chose : Rock\n";
}
else if (myChoice == 2)
{
cout << "\nYou chose : Paper\n";
}
else if (myChoice == 3)
{
cout << "\nYou chose : Scissors\n";
}
return myChoice;
while (myChoice < 1 || myChoice > 3)
{
cout << "Please pick a number between 1 & 3.\n";
cin >> myChoice;
}
}
bool isPlayerWinner(int myChoice, int randomCompNum)
{
if (((myChoice == 1) && (randomCompNum == 3)) || ((myChoice
== 3) && (randomCompNum == 2)) ||
((myChoice == 2) && (randomCompNum == 1)))
{
return true;
}
else if (((randomCompNum == 3) && (myChoice == 1)) ||
((randomCompNum == 3) && (myChoice == 2)) ||
((randomCompNum == 2) && (myChoice == 1)))
{
return false;
}
return 0;
}
bool isTie(int myChoice, int randomCompNum)
{
if (myChoice == randomCompNum)
{
return true;
}
else if (myChoice != randomCompNum)
{
return false;
}
return 0;
}
In: Computer Science
What is promiscuous mode in IDS? What is in-line mode in IDS? When is appropriate to use one or the other in your network?
In: Computer Science
Application on Android Studio
"Tip Calculator" that calculates tip amount and total bill
amount
1. Takes as input a bill amount.
2. Allows user to select a tip percentage between 0-25%
3. Displays tip amount and total amount (total amount = bill amount+ tip amount)
Hint: As tip percentage is a fixed range, you can use a SEEKBAR and as user slides the bar, auto calculate the tip amount and total amount.
In: Computer Science
Application on Android Studio.
"Rock Paper Scissor". The app should ask the user to select "Rock", "Paper" or "Scissor" ; the phone randomly selects a possible choice and then a winner is declared; if it is a tie, the game should continue till a winner emerges.
In: Computer Science
Write an efficient java program to implement an integer doubly linked list Dequeue which insertion and deletion can be than at either end. You have to write 6 methods: add front, delete front, add rear, delete rear, print forward (left to right) and print backward (right to left). After each addition or deletion dequeue elements are printed forward or backward respectively.
Your main method should be as follow:
public static void main(String args[]) {
xxxxx dq = new xxxxx (); // xxxxx is the first 5 characters of your last name
try{
Scanner inf = new Scanner (System.in);
// Read input from KB/ File
while(inf.hasNext()){
// read operation type (optype):
//1:add front, 2:delete front, 3:add rear and delete rear
optype = inf.nextInt();
switch (optype){
case 1: x = inf.nextInt(); // read x
dq.addfront(x);
dq.printfwd(); // print forward dequeuer elements
break;
case 2: j = dq.delfront();// delete front
if(j……….
dq.printbwd(); // print backward dequeuer elements
break;
case 3: x = inf.nextInt(); // read x
dq.addrear(x);
dq.printfwd(); // print forward dequeuer elements
break;
default: j = dq.delrear();// delete front
if(j……….
dq.printbwd(); // print backward dequeuer elements
}//end switch
}// end while
inf.close();// close input file
}catch (Exception e) {prt("\nException " + e + "\n");}
}// end main method
NOTE: Projects will not be graded if:
Your complete project is not in a SINGLE xxxxx.java file, where xxxxx is the first 5 characters of your last name.
It does not read input from System.in. i.e. command prompt.
Sample data file can be as follow:
1 100 2 2 3 500 3 600 3 250 4 1 150 1 220 2 4 1 50 3 55 1 20 1 80 3 90
In: Computer Science
In: Computer Science
Write a code in C or C++ programming language that generates the hexadecimal values in Table 6-2 in the same format.
Table 6-2 Hexadecimal text file specifying the contents of a 4 × 4 multiplier ROM.
00: | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
10: | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 0A | 0B | 0C | 0D | 0E | 0F |
20: | 00 | 02 | 04 | 06 | 08 | 0A | 0C | 0E | 10 | 12 | 14 | 16 | 18 | 1A | 1C | 1E |
30: | 00 | 03 | 06 | 09 | 0C | 0F | 12 | 15 | 18 | 1B | 1E | 21 | 24 | 27 | 2A | 2D |
40: | 00 | 04 | 08 | 0C | 10 | 14 | 18 | 1C | 20 | 24 | 28 | 2C | 30 | 34 | 38 | 3C |
50: | 00 | 05 | 0A | 0F | 14 | 19 | 1E | 23 | 28 | 2D | 32 | 37 | 3C | 41 | 46 | 4B |
60: | 00 | 06 | 0C | 12 | 18 | 1E | 24 | 2A | 30 | 36 | 3C | 42 | 48 | 4E | 54 | 5A |
70: | 00 | 07 | 0E | 15 | 1C | 23 | 2A | 31 | 38 | 3F | 46 | 4D | 54 | 5B | 62 | 69 |
80: | 00 | 08 | 10 | 18 | 20 | 28 | 30 | 38 | 40 | 48 | 50 | 58 | 60 | 68 | 70 | 78 |
90: | 00 | 09 | 12 | 1B | 24 | 2D | 36 | 3F | 48 | 51 | 5A | 63 | 6C | 75 | 7E | 87 |
A0: | 00 | 0A | 14 | 1E | 28 | 32 | 3C | 46 | 50 | 5A | 64 | 6E | 78 | 82 | 8C | 96 |
B0: | 00 | 0B | 16 | 21 | 2C | 37 | 42 | 4D | 58 | 63 | 6E | 79 | 84 | 8F | 9A | A5 |
C0: | 00 | 0C | 18 | 24 | 30 | 3C | 48 | 54 | 60 | 6C | 78 | 84 | 90 | 9C | A8 | B4 |
D0: | 00 | 0D | 1A | 27 | 34 | 41 | 4E | 5B | 68 | 75 | 82 | 8F | 9C | A9 | B6 | C3 |
E0: | 00 | 0E | 1C | 2A | 38 | 46 | 54 | 62 | 70 | 7E | 8C | 9A | A8 | B6 | C4 | D2 |
F0: | 00 | 0F | 1E | 2D | 3C | 4B | 5A | 69 | 78 | 87 | 96 | A5 | B4 | C3 | D2 | E1 |
In: Computer Science
For this portion of the lab, you will reuse the program you
wrote before.
That means you will open the lab you wrote in the previous
assignment and change it. You should NOT start from scratch. Also,
all the requirements/prohibitions from the previous lab MUST also
be included /omitted from this lab.
Redesign the solution in the following manner:
1. Create a menu and ask the user which of the following
conversions they wish to perform:
a. Miles to kilometers
b. Gallons to liters
c. Pounds to kilograms
d. Inches to centimeters
e. Fahrenheit to Celsius
2. Your program must raise an exception if the user chooses any
item not on the menu presented. Along with raising an exception,
write the code to handle this exception.
3. Once the user has chosen a menu item the program should:
a. Ask the user for a value to convert. Refer to the input validations in Lab 4. Your program must raise and exception, and handle the exception, if an input errors occurs.
b. Perform the conversion and write the original value, the original unit, the converted value, and the converted unit to an output file named conversions.txt.
c. Repeat steps a and b 10 times (in a loop).
I have written this code before. I already have added step number 1: the menu. Please add in the code the other requirements: step 2, and step 3 a. b. and c. Thank you!
#Conversions.py
def MilesToKm(Miles):
Km = Miles * 1.6
print(f"Miles: {format(Miles,'.2f')}, kilometers:
{format(Km,'.2f')}")
def FahToCel(Fahrenheit):
Celsius = (Fahrenheit - 32) * 5 / 9
print(f"farehnheit: {format(Fahrenheit,'.2f')}, celsius:
{format(Celsius,'.2f')}")
def GalToLit(Gallons):
Liters = Gallons * 3.9
print(f"gallons: {format(Gallons,'.2f')}, liters:
{format(Liters,'.2f')}")
def PoundsToKg(Pounds):
Kg = Pounds * 3.45
print(f"pounds: {format(Pounds,'.2f')}, kilograms:
{format(Kg,'.2f')}")
def InchesToCm(Inches):
Cm = Inches * 2.54
print(f"inches: {format(Inches,'.2f')}, centimeters:
{format(Cm,'.2f')}")
#Main.py
#Import the package
from Conversions import *
#Create main function to give choice of conversion
def main():
#Intialize the string
string = '''
1: Convert miles to km
2: Convert fahrenheit to celsius
3: Convert gallons to liters
4: Convert pounds to kg
5: Convert inches to cm'''
#Initialize the tupels
metric_name =
('miles','fahrenheit','gallons','pounds','inches')
convert_name = ('km','celsius','liters','kg','cm')
#Print the string
print(string)
#Get the input
choice = int(input('Which of the given conversions would you like
to perform? Enter your choice from 1 to 5: '))
#Set count as "3"
count = 3
#Initialize the boolean variable
flag = True
#Execte the "while" loop
while(flag):
#Get the input
input_value = float(input("Enter how much {0} would you like to
convert into {1}: "
.format(metric_name[choice-1] , convert_name[choice-1])))
#Check for the negative inputs
if input_value < 0:
#Decrement count by "1"
count -= 1
#Print the invalid message
print('Invalid input! You have',count,'chance(s) to enter a valid
input')
#Otherwise
else:
#Check for the choice "1"
if choice == 1:
#Call the function
MilesToKm(input_value)
#Check for the choice "2"
if choice ==2:
#Check whether the input is greater than or equal to "1000"
if input_value >= 1000:
#Decrment the count "1"
count -= 1
#Print the message
print('Invalid input! You have',
count,'chance(s) to enter a valid input')
#Otherwise
else:
#Call the function
FahToCel(input_value)
#Check for the choice "3"
if choice == 3:
#Call the function
GalToLit(input_value)
#Check for the choice "4"
if choice == 4:
#Call the function
PoundsToKg(input_value)
#Check for the choice "5"
if choice == 5:
#Call the function
InchesToCm(input_value)
#Checck whether the count is "0"
if count == 0:
#Set boolean value as "False"
flag = False
#Call the function
main()
In: Computer Science
C++ program, include comments stating what each part of code does please. I want to be able to understand it so I'll be more knowledgeable in the future. The program is multiple files(fibonacci.h file, fibonacci.cpp file, main.cpp file and loops_simple_data_test.cpp). After the directions I also included any starter code or comments left by my professor within the files to aide us.
Directions:
In folder 04_loops_simple_data write prototype and definition for string value - return function get_fibonacci with an int parameter that returns the fibonacci sequence up to that number. Write the required unit test(s) in folder 04_loops_simple_data_test. Main program flow: Program runs until user opts out. For each loop prompt user for a number, use number as function argument, call get_fibonacci function and display the output.
fibonacci.h
/* | |
Write prototype for string value-return function get_fibonacci with an int | |
parameter that returns the fibonacci sequence up to that number. | |
*/ |
fibonacci.cpp
/* | |
Write prototype for string value - return function get_fibonacci with an int | |
parameter that returns the fibonacci sequence up to that number. | |
DO NOT USE A RECURSIVE FUNCTION | |
*/ |
main.cpp
//Write include statements | |
//Write using statements | |
/* | |
Program runs until user opts out. | |
For each loop prompt user for a number, use number as function argument, | |
call get_fibonacci function and display the output. | |
*/ | |
int main() | |
{ | |
return 0; | |
} |
loops_simple_data_test.cpp
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file | |
#include "catch.hpp" | |
//Write includes | |
/* | |
Write test case for get fibonacci function with values | |
10 result "0, 1, 1, 2, 3, 5, 8" | |
and | |
5 result "0, 1, 1, 2, 3, 5" | |
*/ |
In: Computer Science